Skip to content

Commit 362c3cf

Browse files
committed
fix: only save user instruments
1 parent f9b4c06 commit 362c3cf

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

apps/playground/src/store/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ export const useAppStore = create(
2727
}))
2828
),
2929
{
30+
merge: (_persistedState, currentState) => {
31+
const persistedState = _persistedState as
32+
| Partial<Pick<AppStore, 'instruments' | 'selectedInstrument' | 'settings'>>
33+
| undefined;
34+
const instruments = [
35+
...currentState.instruments,
36+
...(persistedState?.instruments ?? []).filter((instrument) => {
37+
return instrument.category === 'Saved';
38+
})
39+
];
40+
const selectedInstrument =
41+
instruments.find(({ id }) => id === persistedState?.selectedInstrument?.id) ??
42+
currentState.selectedInstrument;
43+
const settings = persistedState?.settings ?? currentState.settings;
44+
return { ...currentState, instruments, selectedInstrument, settings };
45+
},
3046
name: 'app',
3147
partialize: (state) => pick(state, ['instruments', 'selectedInstrument', 'settings']),
3248
storage: createJSONStorage(() => localStorage),

0 commit comments

Comments
 (0)