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
|
|
|
|
2023-05-18 08:20:06 +02:00
|
|
|
export function useConfig() {
|
2022-08-02 08:04:47 +02:00
|
|
|
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 || {};
|
|
|
|
}
|
2023-05-18 08:20:06 +02:00
|
|
|
|
|
|
|
export default useConfig;
|