obs-portal/frontend/src/config.ts

51 lines
982 B
TypeScript
Raw Normal View History

import React from 'react'
export type MapSoure =
| {
type: 'vector'
url: string
}
| {
type: 'vector'
tiles: string[]
minzoom: number
maxzoom: number
}
2021-11-16 20:59:37 +00:00
export interface Config {
apiUrl: string
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
banner?: {
text: string
style?: 'warning' | 'info'
}
}
async function loadConfig(): Promise<Config> {
const response = await fetch(__webpack_public_path__ + 'config.json')
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