2021-09-14 20:02:57 +00:00
|
|
|
import React from 'react'
|
|
|
|
|
2021-11-16 20:59:37 +00:00
|
|
|
export type MapSoure = {
|
|
|
|
type: 'vector'
|
|
|
|
url: string,
|
|
|
|
} | {
|
|
|
|
type: 'vector',
|
|
|
|
tiles: string[],
|
|
|
|
minzoom: number,
|
|
|
|
maxzoom: number,
|
|
|
|
}
|
|
|
|
|
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-11-16 20:59:37 +00:00
|
|
|
obsMapSource?: MapSoure
|
2021-11-04 17:13:24 +00:00
|
|
|
imprintUrl?: string
|
|
|
|
privacyPolicyUrl?: string
|
2021-12-03 16:31:43 +00:00
|
|
|
banner?: {
|
|
|
|
text: string
|
|
|
|
style?: "warning" | "info"
|
|
|
|
}
|
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
|