Extract windows location code into hook (#808)

Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
Tilman Vatteroth 2020-11-30 10:09:04 +01:00 committed by GitHub
parent a24ef18dd4
commit bc7ff07256
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View file

@ -5,18 +5,17 @@ SPDX-License-Identifier: AGPL-3.0-only
*/ */
import React, { Suspense, useCallback, useEffect, useState } from 'react' 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 './application-loader.scss'
import { createSetUpTaskList, InitTask } from './initializers' import { createSetUpTaskList, InitTask } from './initializers'
import { LoadingScreen } from './loading-screen' import { LoadingScreen } from './loading-screen'
export const ApplicationLoader: React.FC = ({ children }) => { export const ApplicationLoader: React.FC = ({ children }) => {
const { pathname } = useLocation() const frontendUrl = useFrontendBaseUrl()
const setUpTasks = useCallback(() => { const setUpTasks = useCallback(() => {
const baseUrl: string = window.location.pathname.replace(pathname, '') return createSetUpTaskList(frontendUrl)
return createSetUpTaskList(baseUrl) }, [frontendUrl])
}, [pathname])
const [failedTitle, setFailedTitle] = useState<string>('') const [failedTitle, setFailedTitle] = useState<string>('')
const [doneTasks, setDoneTasks] = useState<number>(0) const [doneTasks, setDoneTasks] = useState<number>(0)

View 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, '')
}