2022-08-02 08:04:47 +02:00
|
|
|
import { useEffect } from 'react';
|
|
|
|
import useStore, { setConfig } from 'store/app';
|
|
|
|
import useApi from 'hooks/useApi';
|
|
|
|
|
2022-10-31 19:02:37 +01:00
|
|
|
let loading = false;
|
2022-08-02 08:04:47 +02:00
|
|
|
|
|
|
|
export default function useConfig() {
|
|
|
|
const { config } = useStore();
|
|
|
|
const { get } = useApi();
|
|
|
|
|
|
|
|
async function loadConfig() {
|
2023-01-11 17:33:43 +01:00
|
|
|
const data = await get('/config');
|
2022-10-31 19:02:37 +01:00
|
|
|
loading = false;
|
2022-08-02 08:04:47 +02:00
|
|
|
setConfig(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-10-31 19:02:37 +01:00
|
|
|
if (!config && !loading) {
|
|
|
|
loading = true;
|
2022-08-02 08:04:47 +02:00
|
|
|
loadConfig();
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return config || {};
|
|
|
|
}
|