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