mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-07 18:04:56 -04:00
Switch the base framework from Create React App to Next.JS
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
a979b6ffdd
commit
77a60c6c48
361 changed files with 5130 additions and 9605 deletions
|
@ -4,52 +4,42 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import React, { Suspense, useCallback, useEffect, useState } from 'react'
|
||||
import React, { Suspense, useEffect } from 'react'
|
||||
import { useBackendBaseUrl } from '../../hooks/common/use-backend-base-url'
|
||||
import './application-loader.scss'
|
||||
import type { InitTask } from './initializers'
|
||||
import { createSetUpTaskList } from './initializers'
|
||||
import { LoadingScreen } from './loading-screen'
|
||||
import { useCustomizeAssetsUrl } from '../../hooks/common/use-customize-assets-url'
|
||||
import { useFrontendAssetsUrl } from '../../hooks/common/use-frontend-assets-url'
|
||||
import { Logger } from '../../utils/logger'
|
||||
import { useAsync } from 'react-use'
|
||||
import { ApplicationLoaderError } from './application-loader-error'
|
||||
import { isTestMode } from '../../utils/test-modes'
|
||||
|
||||
const log = new Logger('ApplicationLoader')
|
||||
|
||||
export const ApplicationLoader: React.FC = ({ children }) => {
|
||||
const frontendAssetsUrl = useFrontendAssetsUrl()
|
||||
const backendBaseUrl = useBackendBaseUrl()
|
||||
const customizeAssetsUrl = useCustomizeAssetsUrl()
|
||||
|
||||
const setUpTasks = useCallback(
|
||||
() => createSetUpTaskList(frontendAssetsUrl, customizeAssetsUrl, backendBaseUrl),
|
||||
[backendBaseUrl, customizeAssetsUrl, frontendAssetsUrl]
|
||||
)
|
||||
|
||||
const [failedTitle, setFailedTitle] = useState<string>('')
|
||||
const [doneTasks, setDoneTasks] = useState<number>(0)
|
||||
const [initTasks] = useState<InitTask[]>(setUpTasks)
|
||||
|
||||
const runTask = useCallback(async (task: Promise<void>): Promise<void> => {
|
||||
await task
|
||||
setDoneTasks((prevDoneTasks) => {
|
||||
return prevDoneTasks + 1
|
||||
})
|
||||
const { error, loading } = useAsync(async () => {
|
||||
const initTasks = createSetUpTaskList(customizeAssetsUrl, backendBaseUrl)
|
||||
for (const task of initTasks) {
|
||||
try {
|
||||
await task.task
|
||||
} catch (reason: unknown) {
|
||||
log.error('Error while initialising application', reason)
|
||||
throw new ApplicationLoaderError(task.name)
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
for (const task of initTasks) {
|
||||
runTask(task.task).catch((reason: Error) => {
|
||||
log.error('Error while initialising application', reason)
|
||||
setFailedTitle(task.name)
|
||||
})
|
||||
if (isTestMode()) {
|
||||
log.warn('This build runs in test mode. This means:\n - no sandboxed iframe')
|
||||
}
|
||||
}, [initTasks, runTask])
|
||||
}, [])
|
||||
|
||||
const tasksAreRunning = doneTasks < initTasks.length || initTasks.length === 0
|
||||
|
||||
if (tasksAreRunning) {
|
||||
return <LoadingScreen failedTitle={failedTitle} />
|
||||
if (loading) {
|
||||
return <LoadingScreen failedTaskName={error?.message} />
|
||||
} else {
|
||||
return <Suspense fallback={<LoadingScreen />}>{children}</Suspense>
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue