Files
Sable/src/app/state/callPreferences.ts
T
7w1 1717ca872f migrate to oxlint and oxfmt
ran formatter
fixed lint issues, primarily getting rid of "any"s and swapping to .toSorted()
2026-04-16 22:15:13 -05:00

40 lines
924 B
TypeScript

import type { WritableAtom } from 'jotai';
import {
atomWithLocalStorage,
getLocalStorageItem,
setLocalStorageItem,
} from './utils/atomWithLocalStorage';
export type CallPreferences = {
microphone: boolean;
video: boolean;
sound: boolean;
};
const CALL_PREFERENCES = 'callPreferences';
const DEFAULT_PREFERENCES: CallPreferences = {
microphone: true,
video: false,
sound: true,
};
export type CallPreferencesAtom = WritableAtom<CallPreferences, [CallPreferences], undefined>;
export const makeCallPreferencesAtom = (userId: string): CallPreferencesAtom => {
const storeKey = `${CALL_PREFERENCES}${userId}`;
const callPreferencesAtom = atomWithLocalStorage<CallPreferences>(
storeKey,
(key) => {
const v = getLocalStorageItem(key, DEFAULT_PREFERENCES);
return v;
},
(key, value) => {
setLocalStorageItem(key, value);
}
);
return callPreferencesAtom;
};