feat: persist mobile sessions tree state and fix root sessions layout
Persist project/worktree expand state across restarts and decouple it from the active directory — projects default expanded, worktree groups collapsed, and the user's explicit toggles are remembered. Selecting a session now switches the active project (not just the draft), following the session's directory. Replace all-or-nothing session pagination with incremental +7 loading that resets when a group or project is toggled, matching the desktop sidebar. Always render root (project-level) sessions as a flat list above worktree groups, and vertically center the session row status dot.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
|
||||
/**
|
||||
* Expand/collapse state for the mobile sessions sheet tree.
|
||||
*
|
||||
* Stores only explicit user overrides, keyed by project id (projects) and
|
||||
* `${projectId}::${bucketKey}` (worktree groups). A missing key means "use the
|
||||
* default": projects start expanded, worktree groups start collapsed. The
|
||||
* user's choice is remembered across app restarts and is intentionally
|
||||
* decoupled from the active directory/session — selecting a session no longer
|
||||
* forces a project open or closed.
|
||||
*/
|
||||
type MobileSessionTreeStore = {
|
||||
projectExpanded: Record<string, boolean>;
|
||||
worktreeExpanded: Record<string, boolean>;
|
||||
setProjectExpanded: (projectId: string, expanded: boolean) => void;
|
||||
setWorktreeExpanded: (key: string, expanded: boolean) => void;
|
||||
};
|
||||
|
||||
export const useMobileSessionTreeStore = create<MobileSessionTreeStore>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
projectExpanded: {},
|
||||
worktreeExpanded: {},
|
||||
setProjectExpanded: (projectId, expanded) =>
|
||||
set((state) => ({ projectExpanded: { ...state.projectExpanded, [projectId]: expanded } })),
|
||||
setWorktreeExpanded: (key, expanded) =>
|
||||
set((state) => ({ worktreeExpanded: { ...state.worktreeExpanded, [key]: expanded } })),
|
||||
}),
|
||||
{
|
||||
name: 'mobile-session-tree',
|
||||
},
|
||||
),
|
||||
);
|
||||
Reference in New Issue
Block a user