hedgedoc/frontend/src/components/application-loader/initializers/index.ts
Erik Michelson d67e44f540
refactor: remove history page
This needs to be done since the backend does not include code
for the history page anymore. This will be replaced with the
explore page in the near future anyway.

Co-authored-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-05-17 23:27:15 +02:00

82 lines
2 KiB
TypeScript

/*
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Logger } from '../../../utils/logger'
import { isDevMode, isTestMode } from '../../../utils/test-modes'
import { loadDarkMode } from './load-dark-mode'
import { setUpI18n } from './setupI18n'
import { loadFromLocalStorage } from '../../../redux/editor-config/methods'
import { fetchAndSetUser } from '../../login-page/utils/fetch-and-set-user'
const logger = new Logger('Application Loader')
/**
* Create a custom delay in the loading of the application.
*/
const customDelay: () => Promise<void> = async () => {
if ((isDevMode || isTestMode) && (window.location.search.startsWith('?customDelay=') || isCustomDelayActive())) {
return new Promise((resolve) => setTimeout(resolve, 500000000))
} else {
return Promise.resolve()
}
}
const isCustomDelayActive = (): boolean => {
try {
return (
typeof window !== 'undefined' &&
typeof window.localStorage !== 'undefined' &&
window.localStorage.getItem('customDelay') !== null
)
} catch {
return false
}
}
export interface InitTask {
name: string
task: () => Promise<void>
}
const fetchUserInformation = async (): Promise<void> => {
try {
await fetchAndSetUser()
} catch {
logger.error("Couldn't load user. Probably not logged in.")
}
}
/**
* Create a list of tasks, that need to be fulfilled on startup.
*/
export const createSetUpTaskList = (): InitTask[] => {
return [
{
name: 'Load dark mode',
task: loadDarkMode
},
{
name: 'Load Translations',
task: setUpI18n
},
{
name: 'Fetch user information',
task: fetchUserInformation
},
{
name: 'Load preferences',
task: loadFromLocalStorageAsync
},
{
name: 'Add Delay',
task: customDelay
}
]
}
const loadFromLocalStorageAsync = (): Promise<void> => {
loadFromLocalStorage()
return Promise.resolve()
}