diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-06-19 15:46:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-19 15:46:53 +0100 |
| commit | 80d28ea2dac4adc696b481f5f52e1f3947d7b959 (patch) | |
| tree | d5686a010e9fb355d27a57e533161822176e3c74 /ui/src/state/store.ts | |
| parent | fix(gui): add support for checking if the cli is installed on windows (#2162) (diff) | |
| download | atuin-80d28ea2dac4adc696b481f5f52e1f3947d7b959.zip | |
feat(gui): cache zustand store in localstorage (#2168)
* fix(gui): use the store to cache week start
* feat(gui): cache zustand store in localStorage
This means that before we've loaded any data, we can still display
something up-to-date. Avoid flashing!
I'll probably want to switch this to the tauri sqlite plugin later
Diffstat (limited to 'ui/src/state/store.ts')
| -rw-r--r-- | ui/src/state/store.ts | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/ui/src/state/store.ts b/ui/src/state/store.ts index 822abc26..21fbdf14 100644 --- a/ui/src/state/store.ts +++ b/ui/src/state/store.ts @@ -1,4 +1,6 @@ import { create } from "zustand"; +import { persist, createJSONStorage } from "zustand/middleware"; + import { parseISO } from "date-fns"; import { fetch } from "@tauri-apps/plugin-http"; @@ -26,6 +28,7 @@ interface AtuinState { vars: Var[]; shellHistory: ShellHistory[]; calendar: any[]; + weekStart: number; refreshHomeInfo: () => void; refreshCalendar: () => void; @@ -36,13 +39,14 @@ interface AtuinState { historyNextPage: (query?: string) => void; } -export const useStore = create<AtuinState>()((set, get) => ({ +let state = (set, get): AtuinState => ({ user: DefaultUser, homeInfo: DefaultHomeInfo, aliases: [], vars: [], shellHistory: [], calendar: [], + weekStart: new Intl.Locale(navigator.language).getWeekInfo().firstDay, refreshAliases: () => { invoke("aliases").then((aliases: any) => { @@ -135,4 +139,8 @@ export const useStore = create<AtuinState>()((set, get) => ({ }); } }, -})); +}); + +export const useStore = create<AtuinState>()( + persist(state, { name: "atuin-storage" }), +); |
