Files
openchamber/packages/ui/src/stores/useMobileSessionExpansionStore.ts
T
Bohdan Triapitsyn 61765ca32c feat: show subsessions under parent sessions in mobile sheet
Nest child sessions (by parentID) under their parent in the mobile sessions
list, with a chevron in the row's left gutter to expand/collapse them
recursively. Top-level pagination counts only parent sessions; children whose
parent isn't in the same bucket stay top-level so nothing is hidden.

Expansion state lives in an in-memory store that survives closing and
reopening the sheet but resets on a full page reload.
2026-06-02 17:04:23 +03:00

24 lines
809 B
TypeScript

import { create } from 'zustand';
/**
* In-memory expand state for parent sessions (with subsessions) in the mobile
* sessions sheet. Deliberately NOT persisted: it survives closing and
* reopening the sheet (the sheet unmounts on close, but this module-level store
* does not), and resets on a full page reload.
*/
type MobileSessionExpansionStore = {
expandedParents: Record<string, boolean>;
toggleParent: (sessionId: string) => void;
};
export const useMobileSessionExpansionStore = create<MobileSessionExpansionStore>((set) => ({
expandedParents: {},
toggleParent: (sessionId) =>
set((state) => {
const next = { ...state.expandedParents };
if (next[sessionId]) delete next[sessionId];
else next[sessionId] = true;
return { expandedParents: next };
}),
}));