Skip to content

Open source CapCut alternative.

TypeScript

feat(site): settings panels remember their view for the session

David Le2d00764c598f
diff --git a/site/src/cut/components/ColorPanel.tsx b/site/src/cut/components/ColorPanel.tsx
index 9e2304fc..cbeb3cf7 100644
--- a/site/src/cut/components/ColorPanel.tsx
+++ b/site/src/cut/components/ColorPanel.tsx
@@ -25,6 +25,7 @@ import {
} from "@donkeycut/effects-kit";
import { getPreviewCanvas, sampleClipFrameData } from "@/cut/lib/previewCanvas";
import { useEditor } from "@/cut/lib/store";
+import { usePanelView } from "@/cut/lib/panelViews";
import type { VideoClip } from "@/cut/lib/types";
import { ResetButton, Row, useSliderCheckpoint } from "@/cut/components/panelBits";
import { ColorWheel } from "@/cut/components/ColorWheel";
@@ -48,7 +49,12 @@ import { Switch } from "@/components/ui/switch";
* numbers.
*/
export function ColorPanel({ clip, onBack }: { clip: VideoClip; onBack: () => void }) {
- const [view, setView] = useState<"presets" | "adjust">("presets");
+ // The open level holds for the session per clip, so deselecting and coming
+ // back lands on the same view.
+ const [view, setView] = usePanelView<"presets" | "adjust">(
+ `color-level:${clip.id}`,
+ "presets"
+ );
if (view === "adjust") {
return <AdjustView clip={clip} onBack={() => setView("presets")} />;
}
@@ -367,7 +373,8 @@ function StandInScene({ filter, tint }: { filter: string; tint: string | null })
/* ------------------------------------------------------------------ */
function AdjustView({ clip, onBack }: { clip: VideoClip; onBack: () => void }) {
- const [tool, setTool] = useState<Tool>("basic");
+ // The picked tool holds for the session, the same way the open level does.
+ const [tool, setTool] = usePanelView<Tool>(`color-tool:${clip.id}`, "basic");
const { draft, commit } = useGradeWriter(clip);
const grade = clip.grade;
// Manual adjustments only — reset-all keeps the preset layer.
diff --git a/site/src/cut/components/SubtitlesPanel.tsx b/site/src/cut/components/SubtitlesPanel.tsx
index 01491aa8..6ca692d3 100644
--- a/site/src/cut/components/SubtitlesPanel.tsx
+++ b/site/src/cut/components/SubtitlesPanel.tsx
@@ -28,6 +28,7 @@ import { useElapsed } from "@/cut/hooks/useElapsed";
import { useCutCaps } from "@/cut/lib/backend/hooks";
import { useActiveWork, useGenNotify } from "@/cut/lib/genNotify";
import { TIMELINE_H_MIN, useEditor } from "@/cut/lib/store";
+import { usePanelView } from "@/cut/lib/panelViews";
import { usePreviewSelector } from "@/cut/lib/playhead";
import { PLATE_PAD_X, PLATE_PAD_Y, PLATE_RADIUS, plateFill } from "@/cut/lib/textRender";
import {
@@ -94,7 +95,12 @@ export function SubtitlesPanel() {
const error = useEditor((s) => s.subtitleError);
const activeCues = laneCues(subtitles, lane);
const hasCues = activeCues.length > 0;
- const [tab, setTab] = useState<"content" | "styles" | "options">("content");
+ // The open tab holds for the session, so leaving the panel and coming back
+ // lands on the same one.
+ const [tab, setTab] = usePanelView<"content" | "styles" | "options">(
+ "subtitles-tab",
+ "content"
+ );
const growTimeline = () => {
const cur = useEditor.getState();
diff --git a/site/src/cut/lib/panelViews.ts b/site/src/cut/lib/panelViews.ts
new file mode 100644
index 00000000..a5d04ccc
--- /dev/null
+++ b/site/src/cut/lib/panelViews.ts
@@ -0,0 +1,25 @@
+"use client";
+
+import { create } from "zustand";
+
+/**
+ * Session memory for settings panels: which view each timeline element's
+ * panel was left on, keyed per element. Deselecting a segment to look at
+ * something and selecting it again lands back on its own view; an element
+ * whose panel was never opened starts at the default. In-memory only — a
+ * reload starts fresh.
+ */
+const usePanelViews = create<{
+ views: Record<string, string>;
+ set: (key: string, view: string) => void;
+}>((set) => ({
+ views: {},
+ set: (key, view) => set((s) => ({ views: { ...s.views, [key]: view } })),
+}));
+
+/** A `useState` whose value holds for the session under `key`. */
+export function usePanelView<T extends string>(key: string, initial: T): [T, (v: T) => void] {
+ const value = (usePanelViews((s) => s.views[key]) as T | undefined) ?? initial;
+ const set = usePanelViews((s) => s.set);
+ return [value, (v: T) => set(key, v)];
+}