feat: migrate frontend app to nextjs app router

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-05-29 17:32:44 +02:00
parent 5b5dabc84e
commit 8602645bea
108 changed files with 893 additions and 1188 deletions

View file

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { useRouter } from 'next/router'
import { useSearchParams } from 'next/navigation'
import { useMemo } from 'react'
/**
@ -13,10 +13,9 @@ import { useMemo } from 'react'
* @return An array of values extracted from the router.
*/
export const useArrayStringUrlParameter = (parameter: string): string[] => {
const router = useRouter()
const router = useSearchParams()
return useMemo(() => {
const value = router.query[parameter]
return (typeof value === 'string' ? [value] : value) ?? []
}, [parameter, router.query])
return router?.getAll(parameter) ?? []
}, [parameter, router])
}

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { baseUrlContext } from '../../components/common/base-url/base-url-context-provider'
import { useRouter } from 'next/router'
import { usePathname } from 'next/navigation'
import { useContext, useMemo } from 'react'
export enum ORIGIN {
@ -22,11 +22,11 @@ export const useBaseUrl = (origin = ORIGIN.CURRENT_PAGE): string => {
throw new Error('No base url context received. Did you forget to use the provider component?')
}
const router = useRouter()
const route = usePathname()
return useMemo(() => {
return (router.route === '/render' && origin === ORIGIN.CURRENT_PAGE) || origin === ORIGIN.RENDERER
return (route === '/render' && origin === ORIGIN.CURRENT_PAGE) || origin === ORIGIN.RENDERER
? baseUrls.renderer
: baseUrls.editor
}, [origin, baseUrls.renderer, baseUrls.editor, router.route])
}, [origin, baseUrls.renderer, baseUrls.editor, route])
}

View file

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { useRouter } from 'next/router'
import { useSearchParams } from 'next/navigation'
import { useMemo } from 'react'
/**
@ -14,10 +14,9 @@ import { useMemo } from 'react'
* @return A value extracted from the router.
*/
export const useSingleStringUrlParameter = <T>(parameter: string, fallback: T): string | T => {
const router = useRouter()
const router = useSearchParams()
return useMemo(() => {
const value = router.query[parameter]
return (typeof value === 'string' ? value : value?.[0]) ?? fallback
}, [fallback, parameter, router.query])
return router?.get(parameter) ?? fallback
}, [fallback, parameter, router])
}

View file

@ -1,28 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { useDarkModeState } from './use-dark-mode-state'
import { useEffect } from 'react'
/**
* Applies the dark mode by adding a css class to the body tag.
*/
export const useApplyDarkModeStyle = (): void => {
const darkMode = useDarkModeState()
useEffect(() => {
if (darkMode) {
window.document.body.dataset.bsTheme = 'dark'
} else {
window.document.body.dataset.bsTheme = 'light'
}
}, [darkMode])
useEffect(
() => () => {
window.document.body.dataset.bsTheme = 'light'
},
[]
)
}