2022-05-19 14:06:18 +02:00
|
|
|
import { basePath } from 'utils/formatPath';
|
2022-02-23 15:08:44 +01:00
|
|
|
import { createPersistentGlobalStateHook } from './usePersistentGlobalState';
|
2022-02-08 13:36:32 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
export interface ILocationSettings {
|
|
|
|
locale: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IUseLocationSettingsOutput {
|
|
|
|
locationSettings: ILocationSettings;
|
|
|
|
setLocationSettings: React.Dispatch<
|
|
|
|
React.SetStateAction<ILocationSettings>
|
|
|
|
>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useLocationSettings = (): IUseLocationSettingsOutput => {
|
|
|
|
const [locationSettings, setLocationSettings] = useGlobalState();
|
|
|
|
|
|
|
|
return { locationSettings, setLocationSettings };
|
|
|
|
};
|
|
|
|
|
|
|
|
const createInitialValue = (): ILocationSettings => {
|
|
|
|
return { locale: navigator.language };
|
|
|
|
};
|
|
|
|
|
2022-02-23 15:08:44 +01:00
|
|
|
const useGlobalState = createPersistentGlobalStateHook<ILocationSettings>(
|
2022-05-19 14:06:18 +02:00
|
|
|
`${basePath}:useLocationSettings:v1`,
|
2022-02-08 13:36:32 +01:00
|
|
|
createInitialValue()
|
|
|
|
);
|