mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-23 02:06:29 -05:00
Extract windows location code into hook (#808)
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
parent
a24ef18dd4
commit
bc7ff07256
2 changed files with 17 additions and 5 deletions
|
@ -5,18 +5,17 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
*/
|
||||
|
||||
import React, { Suspense, useCallback, useEffect, useState } from 'react'
|
||||
import { useLocation } from 'react-router'
|
||||
import { useFrontendBaseUrl } from '../../hooks/common/use-frontend-base-url'
|
||||
import './application-loader.scss'
|
||||
import { createSetUpTaskList, InitTask } from './initializers'
|
||||
import { LoadingScreen } from './loading-screen'
|
||||
|
||||
export const ApplicationLoader: React.FC = ({ children }) => {
|
||||
const { pathname } = useLocation()
|
||||
const frontendUrl = useFrontendBaseUrl()
|
||||
|
||||
const setUpTasks = useCallback(() => {
|
||||
const baseUrl: string = window.location.pathname.replace(pathname, '')
|
||||
return createSetUpTaskList(baseUrl)
|
||||
}, [pathname])
|
||||
return createSetUpTaskList(frontendUrl)
|
||||
}, [frontendUrl])
|
||||
|
||||
const [failedTitle, setFailedTitle] = useState<string>('')
|
||||
const [doneTasks, setDoneTasks] = useState<number>(0)
|
||||
|
|
13
src/hooks/common/use-frontend-base-url.ts
Normal file
13
src/hooks/common/use-frontend-base-url.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { useLocation } from 'react-router'
|
||||
|
||||
export const useFrontendBaseUrl = (): string => {
|
||||
const { pathname } = useLocation()
|
||||
|
||||
return window.location.pathname.replace(pathname, '')
|
||||
}
|
Loading…
Reference in a new issue