♻️ (synced-prefs) remove no longer necessary migration (#3718)

* ♻️ (synced-prefs) remove no longer necessary migration

Closes #3551

* Release notes
This commit is contained in:
Matiss Janis Aboltins
2024-10-23 19:57:02 +01:00
committed by GitHub
parent 1b883aa0ab
commit 34f3ccacf6
2 changed files with 10 additions and 23 deletions

View File

@@ -1,5 +1,3 @@
import { useEffect } from 'react';
import { useLocalStorage } from 'usehooks-ts';
import { type LocalPrefs } from 'loot-core/src/types/prefs';
@@ -18,25 +16,8 @@ export function useLocalPref<K extends keyof LocalPrefs>(
): [LocalPrefs[K], SetLocalPrefAction<K>] {
const [budgetId] = useMetadataPref('id');
const [value, setValue] = useLocalStorage<LocalPrefs[K]>(
`${budgetId}-${prefName}`,
undefined,
{
deserializer: JSON.parse,
serializer: JSON.stringify,
},
);
// Migrate from old pref storage location (metadata.json) to local storage
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [metadataPref] = useMetadataPref(prefName as any);
useEffect(() => {
if (value !== undefined || metadataPref === undefined) {
return;
}
setValue(metadataPref);
}, [value, metadataPref, setValue]);
return [value, setValue];
return useLocalStorage<LocalPrefs[K]>(`${budgetId}-${prefName}`, undefined, {
deserializer: JSON.parse,
serializer: JSON.stringify,
});
}

View File

@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MatissJanis]
---
SyncedPrefs: remove no longer necessary migration.