mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 23:24:46 -04:00
parent
557386f78f
commit
e2155e735d
65 changed files with 834 additions and 467 deletions
|
@ -1,16 +1,16 @@
|
|||
import React, { Fragment, useEffect, useState } from 'react'
|
||||
import { useLocation } from 'react-router'
|
||||
import { setUp } from '../../initializers'
|
||||
import './application-loader.scss'
|
||||
import { LoadingScreen } from './loading-screen'
|
||||
|
||||
interface ApplicationLoaderProps {
|
||||
initTasks: Promise<void>[]
|
||||
}
|
||||
|
||||
export const ApplicationLoader: React.FC<ApplicationLoaderProps> = ({ children, initTasks }) => {
|
||||
export const ApplicationLoader: React.FC = ({ children }) => {
|
||||
const [failed, setFailed] = useState<boolean>(false)
|
||||
const [doneTasks, setDoneTasks] = useState<number>(0)
|
||||
const [initTasks, setInitTasks] = useState<Promise<void>[]>([])
|
||||
const { pathname } = useLocation()
|
||||
|
||||
const runTask:((task: Promise<void>) => (Promise<void>)) = async (task) => {
|
||||
const runTask = async (task: Promise<void>): Promise<void> => {
|
||||
await task
|
||||
setDoneTasks(prevDoneTasks => {
|
||||
return prevDoneTasks + 1
|
||||
|
@ -18,7 +18,12 @@ export const ApplicationLoader: React.FC<ApplicationLoaderProps> = ({ children,
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
setDoneTasks(0)
|
||||
const baseUrl:string = window.location.pathname.replace(pathname, '') + '/'
|
||||
console.debug('Base URL is', baseUrl)
|
||||
setInitTasks(setUp(baseUrl))
|
||||
}, [pathname])
|
||||
|
||||
useEffect(() => {
|
||||
for (const task of initTasks) {
|
||||
runTask(task).catch(reason => {
|
||||
setFailed(true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue