feat: add localStorage persistence to focus store

Wraps the focus store with zustand/middleware persist to maintain
queue state across page refreshes and app restarts.

Persists:
- current: The currently focused item
- queue: Remaining items in the work queue

Not persisted (transient state):
- isLoading: Reset on mount
- error: Reset on mount

Storage key: "mc-focus-store"

This prevents losing your place in the queue when the app restarts
or the page refreshes during development.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
teernisse
2026-02-26 09:55:53 -05:00
parent 7120323295
commit 6c04c2efe7

View File

@@ -6,6 +6,7 @@
*/ */
import { create } from "zustand"; import { create } from "zustand";
import { persist } from "zustand/middleware";
import type { FocusAction, FocusItem } from "@/lib/types"; import type { FocusAction, FocusItem } from "@/lib/types";
export interface FocusState { export interface FocusState {
@@ -34,7 +35,9 @@ export interface FocusState {
setError: (error: string | null) => void; setError: (error: string | null) => void;
} }
export const useFocusStore = create<FocusState>((set, get) => ({ export const useFocusStore = create<FocusState>()(
persist(
(set, get) => ({
current: null, current: null,
queue: [], queue: [],
isLoading: false, isLoading: false,
@@ -102,4 +105,13 @@ export const useFocusStore = create<FocusState>((set, get) => ({
setLoading: (loading) => set({ isLoading: loading }), setLoading: (loading) => set({ isLoading: loading }),
setError: (error) => set({ error }), setError: (error) => set({ error }),
})); }),
{
name: "mc-focus-store",
partialize: (state) => ({
current: state.current,
queue: state.queue,
}),
}
)
);