summaryrefslogtreecommitdiff
path: root/apps/web/src/stores/editor-store.ts
blob: 9923aa87bb2d59de55fcb4d21ac6b5eb7fbb9105 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { CanvasPreset } from "@/types/editor";

export type PlatformLayout = "tiktok";

export const PLATFORM_LAYOUTS: Record<PlatformLayout, string> = {
  tiktok: "TikTok",
};

interface LayoutGuideSettings {
  platform: PlatformLayout | null;
}

interface EditorState {
  // Loading states
  isInitializing: boolean;
  isPanelsReady: boolean;

  // Editor UI settings
  canvasPresets: CanvasPreset[];
  layoutGuide: LayoutGuideSettings;

  // Actions
  setInitializing: (loading: boolean) => void;
  setPanelsReady: (ready: boolean) => void;
  initializeApp: () => Promise<void>;
  setLayoutGuide: (settings: Partial<LayoutGuideSettings>) => void;
  toggleLayoutGuide: (platform: PlatformLayout) => void;
}

const DEFAULT_CANVAS_PRESETS: CanvasPreset[] = [
  { name: "16:9", width: 1920, height: 1080 },
  { name: "9:16", width: 1080, height: 1920 },
  { name: "1:1", width: 1080, height: 1080 },
  { name: "4:3", width: 1440, height: 1080 },
];

export const useEditorStore = create<EditorState>()(
  persist(
    (set) => ({
      // Initial states
      isInitializing: true,
      isPanelsReady: false,
      canvasPresets: DEFAULT_CANVAS_PRESETS,
      layoutGuide: {
        platform: null,
      },

      // Actions
      setInitializing: (loading) => {
        set({ isInitializing: loading });
      },

      setPanelsReady: (ready) => {
        set({ isPanelsReady: ready });
      },

      initializeApp: async () => {
        console.log("Initializing video editor...");
        set({ isInitializing: true, isPanelsReady: false });

        set({ isPanelsReady: true, isInitializing: false });
        console.log("Video editor ready");
      },

      setLayoutGuide: (settings) => {
        set((state) => ({
          layoutGuide: {
            ...state.layoutGuide,
            ...settings,
          },
        }));
      },

      toggleLayoutGuide: (platform) => {
        set((state) => ({
          layoutGuide: {
            platform: state.layoutGuide.platform === platform ? null : platform,
          },
        }));
      },
    }),
    {
      name: "editor-settings",
      partialize: (state) => ({
        layoutGuide: state.layoutGuide,
      }),
    }
  )
);