Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/client/features/shows/cue-list-view-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
import { createContext, useContext } from "react";
import { proxy } from "valtio";

const PERSISTED_SETTINGS_KEY = "r2t2-cue-list-settings";

interface PersistedSettings {
intercomUrl: string;
isIntercomVisible: boolean;
intercomPanelHeightPx: number;
audioNotificationsEnabled: boolean;
ttsNotificationsEnabled: boolean;
}

function loadPersistedSettings(): Partial<PersistedSettings> {
try {
const raw = localStorage.getItem(PERSISTED_SETTINGS_KEY);
if (!raw) return {};
const parsed: unknown = JSON.parse(raw);
if (typeof parsed !== "object" || parsed === null) return {};
const obj = parsed as Record<string, unknown>;
const result: Partial<PersistedSettings> = {};
if (typeof obj.intercomUrl === "string") result.intercomUrl = obj.intercomUrl;
if (typeof obj.isIntercomVisible === "boolean") result.isIntercomVisible = obj.isIntercomVisible;
if (typeof obj.intercomPanelHeightPx === "number") result.intercomPanelHeightPx = obj.intercomPanelHeightPx;
if (typeof obj.audioNotificationsEnabled === "boolean") result.audioNotificationsEnabled = obj.audioNotificationsEnabled;
if (typeof obj.ttsNotificationsEnabled === "boolean") result.ttsNotificationsEnabled = obj.ttsNotificationsEnabled;
return result;
} catch {
// ignore malformed data
}
return {};
}

export function savePersistedSettings(settings: PersistedSettings): void {
try {
localStorage.setItem(PERSISTED_SETTINGS_KEY, JSON.stringify(settings));
} catch {
// ignore
}
}

export interface CueListViewState {
// Track and value selection for bottom pane filtering
selectedTrackId: string | null;
Expand All @@ -9,13 +47,28 @@ export interface CueListViewState {
// Horizontal splitter position as percentage (0-100)
// 50 = 50/50 split
splitterPositionPercent: number;

// Intercom integration (persisted to localStorage)
intercomUrl: string;
isIntercomVisible: boolean;
intercomPanelHeightPx: number;

// Audio notifications on take (persisted to localStorage)
audioNotificationsEnabled: boolean;
ttsNotificationsEnabled: boolean;
}

export function createCueListViewStore(): CueListViewState {
const persisted = loadPersistedSettings();
return proxy<CueListViewState>({
selectedTrackId: null,
selectedTechnicalIdentifier: null,
splitterPositionPercent: 50,
intercomUrl: persisted.intercomUrl ?? "",
isIntercomVisible: persisted.isIntercomVisible ?? false,
intercomPanelHeightPx: persisted.intercomPanelHeightPx ?? 300,
audioNotificationsEnabled: persisted.audioNotificationsEnabled ?? false,
ttsNotificationsEnabled: persisted.ttsNotificationsEnabled ?? false,
});
}

Expand Down
Loading