From 0de07bfa9814efbc4d551fdc45ce3c39e4f18fc3 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 27 Apr 2026 02:37:12 +0000 Subject: [PATCH] Persist office sound preferences Co-authored-by: Luke The Dev --- src/features/office/screens/OfficeScreen.tsx | 1 + src/hooks/useStudioOfficeSoundPreference.ts | 14 +++++++----- src/lib/studio/coordinator.ts | 23 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/features/office/screens/OfficeScreen.tsx b/src/features/office/screens/OfficeScreen.tsx index 22961ce..e576ec5 100644 --- a/src/features/office/screens/OfficeScreen.tsx +++ b/src/features/office/screens/OfficeScreen.tsx @@ -1387,6 +1387,7 @@ export function OfficeScreen({ setVolume: setOfficeSoundVolume, } = useStudioOfficeSoundPreference({ gatewayUrl, + storageKey: selectedAdapterType, settingsCoordinator, }); const { diff --git a/src/hooks/useStudioOfficeSoundPreference.ts b/src/hooks/useStudioOfficeSoundPreference.ts index cc9e60b..db97cd1 100644 --- a/src/hooks/useStudioOfficeSoundPreference.ts +++ b/src/hooks/useStudioOfficeSoundPreference.ts @@ -10,11 +10,13 @@ import { type UseStudioOfficeSoundPreferenceParams = { gatewayUrl: string; + storageKey?: string; settingsCoordinator: StudioSettingsCoordinator; }; export const useStudioOfficeSoundPreference = ({ gatewayUrl, + storageKey, settingsCoordinator, }: UseStudioOfficeSoundPreferenceParams) => { const [preference, setPreference] = useState( @@ -24,7 +26,7 @@ export const useStudioOfficeSoundPreference = ({ useEffect(() => { let cancelled = false; - const gatewayKey = gatewayUrl.trim(); + const gatewayKey = gatewayUrl.trim() || storageKey?.trim() || ""; if (!gatewayKey) { setPreference(defaultStudioOfficeSoundPreference()); setLoaded(true); @@ -53,11 +55,11 @@ export const useStudioOfficeSoundPreference = ({ return () => { cancelled = true; }; - }, [gatewayUrl, settingsCoordinator]); + }, [gatewayUrl, settingsCoordinator, storageKey]); const setEnabled = useCallback( (enabled: boolean) => { - const gatewayKey = gatewayUrl.trim(); + const gatewayKey = gatewayUrl.trim() || storageKey?.trim() || ""; setPreference((current) => ({ ...current, enabled })); if (!gatewayKey) return; settingsCoordinator.schedulePatch( @@ -65,12 +67,12 @@ export const useStudioOfficeSoundPreference = ({ 0, ); }, - [gatewayUrl, settingsCoordinator], + [gatewayUrl, settingsCoordinator, storageKey], ); const setVolume = useCallback( (volume: number) => { - const gatewayKey = gatewayUrl.trim(); + const gatewayKey = gatewayUrl.trim() || storageKey?.trim() || ""; setPreference((current) => ({ ...current, volume })); if (!gatewayKey) return; settingsCoordinator.schedulePatch( @@ -78,7 +80,7 @@ export const useStudioOfficeSoundPreference = ({ 0, ); }, - [gatewayUrl, settingsCoordinator], + [gatewayUrl, settingsCoordinator, storageKey], ); return { diff --git a/src/lib/studio/coordinator.ts b/src/lib/studio/coordinator.ts index 2c3aa24..5865ede 100644 --- a/src/lib/studio/coordinator.ts +++ b/src/lib/studio/coordinator.ts @@ -7,6 +7,7 @@ import type { StudioGatewaySettingsPublic, StudioGatewaySettingsPatch, StudioOfficePreferencePatch, + StudioOfficeSoundPreferencePatch, StudioSettingsPublic, StudioSettingsPatch, StudioStandupPreferencePatch, @@ -31,6 +32,7 @@ type AvatarsPatch = Record | n type DeskAssignmentsPatch = Record | null>; type AnalyticsPatch = Record; type VoiceRepliesPatch = Record; +type OfficeSoundPatch = Record; type OfficePatch = Record; type StandupPatch = Record; type TaskBoardPatch = Record; @@ -152,6 +154,24 @@ const mergeVoiceRepliesPatch = ( return merged; }; +const mergeOfficeSoundPatch = ( + current: OfficeSoundPatch | undefined, + next: OfficeSoundPatch | undefined +): OfficeSoundPatch | undefined => { + if (!current && !next) return undefined; + const merged: OfficeSoundPatch = { ...(current ?? {}) }; + for (const [gatewayKey, value] of Object.entries(next ?? {})) { + if (value === null) { + merged[gatewayKey] = null; + continue; + } + const existing = merged[gatewayKey]; + merged[gatewayKey] = + existing && existing !== null ? { ...existing, ...value } : { ...value }; + } + return merged; +}; + const mergeOfficePatch = ( current: OfficePatch | undefined, next: OfficePatch | undefined @@ -351,6 +371,7 @@ const mergeStudioPatch = ( ...(next.deskAssignments ? { deskAssignments: { ...next.deskAssignments } } : {}), ...(next.analytics ? { analytics: { ...next.analytics } } : {}), ...(next.voiceReplies ? { voiceReplies: { ...next.voiceReplies } } : {}), + ...(next.officeSound ? { officeSound: { ...next.officeSound } } : {}), ...(next.office ? { office: { ...next.office } } : {}), ...(next.standup ? { standup: { ...next.standup } } : {}), ...(next.officeFloors ? { officeFloors: { ...next.officeFloors } } : {}), @@ -364,6 +385,7 @@ const mergeStudioPatch = ( ); const analytics = mergeAnalyticsPatch(current.analytics, next.analytics); const voiceReplies = mergeVoiceRepliesPatch(current.voiceReplies, next.voiceReplies); + const officeSound = mergeOfficeSoundPatch(current.officeSound, next.officeSound); const office = mergeOfficePatch(current.office, next.office); const standup = mergeStandupPatch(current.standup, next.standup); const taskBoard = mergeTaskBoardPatch(current.taskBoard, next.taskBoard); @@ -385,6 +407,7 @@ const mergeStudioPatch = ( ...(deskAssignments ? { deskAssignments } : {}), ...(analytics ? { analytics } : {}), ...(voiceReplies ? { voiceReplies } : {}), + ...(officeSound ? { officeSound } : {}), ...(office ? { office } : {}), ...(standup ? { standup } : {}), ...(taskBoard ? { taskBoard } : {}),