2021-09-14 20:02:57 +00:00
|
|
|
import React from 'react'
|
|
|
|
|
2021-10-27 15:32:07 +00:00
|
|
|
export interface Config {
|
2021-09-14 20:02:57 +00:00
|
|
|
apiUrl: string
|
2021-10-10 10:32:28 +00:00
|
|
|
mapHome: {
|
|
|
|
latitude: number
|
|
|
|
longitude: number
|
|
|
|
zoom: number
|
|
|
|
}
|
2021-10-27 15:32:07 +00:00
|
|
|
obsMapSource?: string
|
2021-11-04 17:13:24 +00:00
|
|
|
imprintUrl?: string
|
|
|
|
privacyPolicyUrl?: string
|
|
|
|
mapTileset?: {
|
|
|
|
url?: string
|
|
|
|
minZoom?: number
|
|
|
|
maxZoom?: number
|
|
|
|
}
|
2021-09-14 20:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function loadConfig(): Promise<Config> {
|
2021-10-10 09:01:18 +00:00
|
|
|
const response = await fetch(__webpack_public_path__ + 'config.json')
|
2021-09-14 20:02:57 +00:00
|
|
|
const config = await response.json()
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
let _configPromise: Promise<Config> = loadConfig()
|
|
|
|
let _configCache: null | Config = null
|
|
|
|
|
|
|
|
export function useConfig() {
|
|
|
|
const [config, setConfig] = React.useState<Config>(_configCache)
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (!_configCache) {
|
|
|
|
_configPromise.then(setConfig)
|
|
|
|
}
|
|
|
|
}, [])
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
export default _configPromise
|