mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Ensure that persisted state is kept in sync (#12596)
This commit is contained in:
parent
1bd3285679
commit
5c15659a34
@ -38,12 +38,22 @@ export function usePersistedOverlayState<S extends string>(
|
||||
(value: S | undefined, replace?: boolean) => void,
|
||||
() => void,
|
||||
] {
|
||||
const [persistedValue, setPersistedValue, , deletePersistedValue] =
|
||||
usePersistence<S>(key, defaultValue);
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const currentLocationState = useMemo(() => location.state, [location]);
|
||||
|
||||
// currently selected value
|
||||
|
||||
const overlayStateValue = useMemo<S | undefined>(
|
||||
() => location.state && location.state[key],
|
||||
[location, key],
|
||||
);
|
||||
|
||||
// saved value from previous session
|
||||
|
||||
const [persistedValue, setPersistedValue, , deletePersistedValue] =
|
||||
usePersistence<S>(key, overlayStateValue);
|
||||
|
||||
const setOverlayStateValue = useCallback(
|
||||
(value: S | undefined, replace: boolean = false) => {
|
||||
setPersistedValue(value);
|
||||
@ -56,11 +66,6 @@ export function usePersistedOverlayState<S extends string>(
|
||||
[key, currentLocationState, navigate],
|
||||
);
|
||||
|
||||
const overlayStateValue = useMemo<S | undefined>(
|
||||
() => location.state && location.state[key],
|
||||
[location, key],
|
||||
);
|
||||
|
||||
return [
|
||||
overlayStateValue ?? persistedValue ?? defaultValue,
|
||||
setOverlayStateValue,
|
||||
|
@ -34,7 +34,6 @@ export function usePersistence<S>(
|
||||
|
||||
useEffect(() => {
|
||||
setLoaded(false);
|
||||
setInternalValue(defaultValue);
|
||||
|
||||
async function load() {
|
||||
const value = await getData(key);
|
||||
|
Loading…
Reference in New Issue
Block a user