diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-03-27 00:55:15 +0100 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-03-29 15:56:48 +0200 |
| commit | 4d127a038bf768eded68aae3cfa5c1b12241bdac (patch) | |
| tree | 16bbb801caf6770546cff4fdb37b6408ec9ead98 /apps/web/src/stores/preview-store.ts | |
| parent | 82817cb50cb0487350573d6129130aec705f924b (diff) | |
| download | opencut-4d127a038bf768eded68aae3cfa5c1b12241bdac.tar.gz | |
chore: normalize line endings
Diffstat (limited to 'apps/web/src/stores/preview-store.ts')
| -rw-r--r-- | apps/web/src/stores/preview-store.ts | 224 |
1 files changed, 112 insertions, 112 deletions
diff --git a/apps/web/src/stores/preview-store.ts b/apps/web/src/stores/preview-store.ts index cd6488b3..d0489e3b 100644 --- a/apps/web/src/stores/preview-store.ts +++ b/apps/web/src/stores/preview-store.ts @@ -1,112 +1,112 @@ -import { create } from "zustand"; -import { persist } from "zustand/middleware"; -import { isGuideId, type GuideId } from "@/lib/guides"; -import { DEFAULT_GRID_CONFIG } from "@/constants/guide-constants"; -import type { GridConfig } from "@/lib/guides/types"; - -interface PreviewOverlaysState { - bookmarks: boolean; -} - -interface PersistedPreviewState { - activeGuide?: string | null; - layoutGuide?: { - platform?: string | null; - }; - overlays?: PreviewOverlaysState; - gridConfig?: GridConfig; -} - -interface PreviewState { - activeGuide: GuideId | null; - overlays: PreviewOverlaysState; - gridConfig: GridConfig; - toggleGuide: (guideId: GuideId) => void; - setGridConfig: (config: Partial<GridConfig>) => void; - setOverlayVisibility: ({ - overlay, - isVisible, - }: { - overlay: keyof PreviewOverlaysState; - isVisible: boolean; - }) => void; - toggleOverlayVisibility: ({ - overlay, - }: { - overlay: keyof PreviewOverlaysState; - }) => void; -} - -const DEFAULT_PREVIEW_OVERLAYS: PreviewOverlaysState = { - bookmarks: true, -}; - -function getPersistedActiveGuide( - state: PersistedPreviewState | undefined, -): GuideId | null { - const persistedGuide = - state?.activeGuide ?? state?.layoutGuide?.platform ?? null; - - if (typeof persistedGuide !== "string") { - return null; - } - - return isGuideId(persistedGuide) ? persistedGuide : null; -} - -export const usePreviewStore = create<PreviewState>()( - persist( - (set) => ({ - activeGuide: null, - overlays: DEFAULT_PREVIEW_OVERLAYS, - gridConfig: DEFAULT_GRID_CONFIG, - toggleGuide: (guideId) => { - set((state) => ({ - activeGuide: state.activeGuide === guideId ? null : guideId, - })); - }, - setGridConfig: (config) => { - set((state) => ({ - gridConfig: { ...state.gridConfig, ...config }, - })); - }, - setOverlayVisibility: ({ overlay, isVisible }) => { - set((state) => ({ - overlays: { - ...state.overlays, - [overlay]: isVisible, - }, - })); - }, - toggleOverlayVisibility: ({ overlay }) => { - set((state) => ({ - overlays: { - ...state.overlays, - [overlay]: !state.overlays[overlay], - }, - })); - }, - }), - { - name: "preview-settings", - version: 4, - migrate: (persistedState) => { - const state = persistedState as PersistedPreviewState | undefined; - - return { - activeGuide: getPersistedActiveGuide(state), - overlays: state?.overlays ?? DEFAULT_PREVIEW_OVERLAYS, - gridConfig: { - rows: state?.gridConfig?.rows ?? DEFAULT_GRID_CONFIG.rows, - cols: state?.gridConfig?.cols ?? DEFAULT_GRID_CONFIG.cols, - }, - }; - }, - partialize: (state) => ({ - activeGuide: state.activeGuide, - overlays: state.overlays, - gridConfig: state.gridConfig, - }), - }, - ), -); +import { create } from "zustand";
+import { persist } from "zustand/middleware";
+import { isGuideId, type GuideId } from "@/lib/guides";
+import { DEFAULT_GRID_CONFIG } from "@/constants/guide-constants";
+import type { GridConfig } from "@/lib/guides/types";
+
+interface PreviewOverlaysState {
+ bookmarks: boolean;
+}
+
+interface PersistedPreviewState {
+ activeGuide?: string | null;
+ layoutGuide?: {
+ platform?: string | null;
+ };
+ overlays?: PreviewOverlaysState;
+ gridConfig?: GridConfig;
+}
+
+interface PreviewState {
+ activeGuide: GuideId | null;
+ overlays: PreviewOverlaysState;
+ gridConfig: GridConfig;
+ toggleGuide: (guideId: GuideId) => void;
+ setGridConfig: (config: Partial<GridConfig>) => void;
+ setOverlayVisibility: ({
+ overlay,
+ isVisible,
+ }: {
+ overlay: keyof PreviewOverlaysState;
+ isVisible: boolean;
+ }) => void;
+ toggleOverlayVisibility: ({
+ overlay,
+ }: {
+ overlay: keyof PreviewOverlaysState;
+ }) => void;
+}
+
+const DEFAULT_PREVIEW_OVERLAYS: PreviewOverlaysState = {
+ bookmarks: true,
+};
+
+function getPersistedActiveGuide(
+ state: PersistedPreviewState | undefined,
+): GuideId | null {
+ const persistedGuide =
+ state?.activeGuide ?? state?.layoutGuide?.platform ?? null;
+
+ if (typeof persistedGuide !== "string") {
+ return null;
+ }
+
+ return isGuideId(persistedGuide) ? persistedGuide : null;
+}
+
+export const usePreviewStore = create<PreviewState>()(
+ persist(
+ (set) => ({
+ activeGuide: null,
+ overlays: DEFAULT_PREVIEW_OVERLAYS,
+ gridConfig: DEFAULT_GRID_CONFIG,
+ toggleGuide: (guideId) => {
+ set((state) => ({
+ activeGuide: state.activeGuide === guideId ? null : guideId,
+ }));
+ },
+ setGridConfig: (config) => {
+ set((state) => ({
+ gridConfig: { ...state.gridConfig, ...config },
+ }));
+ },
+ setOverlayVisibility: ({ overlay, isVisible }) => {
+ set((state) => ({
+ overlays: {
+ ...state.overlays,
+ [overlay]: isVisible,
+ },
+ }));
+ },
+ toggleOverlayVisibility: ({ overlay }) => {
+ set((state) => ({
+ overlays: {
+ ...state.overlays,
+ [overlay]: !state.overlays[overlay],
+ },
+ }));
+ },
+ }),
+ {
+ name: "preview-settings",
+ version: 4,
+ migrate: (persistedState) => {
+ const state = persistedState as PersistedPreviewState | undefined;
+
+ return {
+ activeGuide: getPersistedActiveGuide(state),
+ overlays: state?.overlays ?? DEFAULT_PREVIEW_OVERLAYS,
+ gridConfig: {
+ rows: state?.gridConfig?.rows ?? DEFAULT_GRID_CONFIG.rows,
+ cols: state?.gridConfig?.cols ?? DEFAULT_GRID_CONFIG.cols,
+ },
+ };
+ },
+ partialize: (state) => ({
+ activeGuide: state.activeGuide,
+ overlays: state.overlays,
+ gridConfig: state.gridConfig,
+ }),
+ },
+ ),
+);
|
