Persist office sound preferences

Co-authored-by: Luke The Dev <iamlukethedev@users.noreply.github.com>
This commit is contained in:
Cursor Agent
2026-04-27 02:37:12 +00:00
co-authored by Luke The Dev
parent 727a7e8a9e
commit 0de07bfa98
3 changed files with 32 additions and 6 deletions
@@ -1387,6 +1387,7 @@ export function OfficeScreen({
setVolume: setOfficeSoundVolume,
} = useStudioOfficeSoundPreference({
gatewayUrl,
storageKey: selectedAdapterType,
settingsCoordinator,
});
const {
+8 -6
View File
@@ -10,11 +10,13 @@ import {
type UseStudioOfficeSoundPreferenceParams = {
gatewayUrl: string;
storageKey?: string;
settingsCoordinator: StudioSettingsCoordinator;
};
export const useStudioOfficeSoundPreference = ({
gatewayUrl,
storageKey,
settingsCoordinator,
}: UseStudioOfficeSoundPreferenceParams) => {
const [preference, setPreference] = useState<StudioOfficeSoundPreference>(
@@ -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 {
+23
View File
@@ -7,6 +7,7 @@ import type {
StudioGatewaySettingsPublic,
StudioGatewaySettingsPatch,
StudioOfficePreferencePatch,
StudioOfficeSoundPreferencePatch,
StudioSettingsPublic,
StudioSettingsPatch,
StudioStandupPreferencePatch,
@@ -31,6 +32,7 @@ type AvatarsPatch = Record<string, Record<string, AgentAvatarProfile | null> | n
type DeskAssignmentsPatch = Record<string, Record<string, string | null> | null>;
type AnalyticsPatch = Record<string, StudioAnalyticsPreferencePatch | null>;
type VoiceRepliesPatch = Record<string, StudioVoiceRepliesPreferencePatch | null>;
type OfficeSoundPatch = Record<string, StudioOfficeSoundPreferencePatch | null>;
type OfficePatch = Record<string, StudioOfficePreferencePatch | null>;
type StandupPatch = Record<string, StudioStandupPreferencePatch | null>;
type TaskBoardPatch = Record<string, StudioTaskBoardPreferencePatch | null>;
@@ -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 } : {}),