Files
llink/js/mobile/src/stores/playback-pause-store.ts
T
Arjun PatelandGitHub a8a0b7db1b infra: add linting and formatting for js projects (#230)
* wip

* wip

* wip

* format

* wip(mobile): lint and format

* cleanup

* nits

* nits

* idiomatic react

* nit

* format all root files
2026-06-02 07:44:24 -07:00

34 lines
1.1 KiB
TypeScript

import { create } from 'zustand';
/**
* Single source of truth for "is stream playback paused." Each component that
* wants to pause playback registers a unique id via `useSuspendPlayback`; the
* label is for devtools only. Playback is paused while any id is registered.
*/
interface PlaybackPauseState {
activeIds: Record<string, string>;
composing: boolean;
add: (id: string, label: string) => void;
remove: (id: string) => void;
setComposing: (composing: boolean) => void;
}
export const usePlaybackPauseStore = create<PlaybackPauseState>((set) => ({
activeIds: {},
composing: false,
add: (id, label) =>
set((s) => ({ activeIds: { ...s.activeIds, [id]: label } })),
remove: (id) =>
set((s) => {
if (!(id in s.activeIds)) return s;
const { [id]: _, ...rest } = s.activeIds;
return { activeIds: rest };
}),
setComposing: (composing) => set({ composing }),
}));
export const selectIsPaused = (s: PlaybackPauseState) =>
Object.keys(s.activeIds).length > 0 || s.composing;
export const selectIsComposing = (s: PlaybackPauseState) => s.composing;