mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat(sidebar): add repo-grouped session navigation with live status (#361)
* feat(sidebar): add repo-grouped session navigation with live status - Add a searchable, collapsible session tree to the desktop sidebar, grouped by repository with pinned and time-bucketed ordering. - Track per-session busy, retry, and compact status in a shared store fed by the SSE event stream and scoped by directory. - Extract shared navigation components reused by the desktop tree and the mobile repo quick-switch sheet. - Show a Git tab and hide Schedules inside a repo on the mobile tab bar; add Repos and Assistant entries to the session More drawer. - Replace the CommitsTab local relative-time formatter with a shared formatShortRelativeTime util. * refactor(sidebar): unify session status tracking and navigation helpers * feat(sidebar): add collapsible sessions and menu sections * fix(sessions): keep specific live status over snapshot busy
This commit is contained in:
1 parent
1389e8e59c
commit
015a44a5f3
45 files changed
+3347
-763
No files matched your search
@@ -25,7 +25,7 @@ import { showToast } from "../lib/toast";
|
||||
import { useSendErrorStore } from "../stores/sendErrorStore";
|
||||
import { useSessionStatus } from "../stores/sessionStatusStore";
|
||||
import { invalidateSessionListCaches, sessionTranscriptQueryKey } from "../lib/queryInvalidation";
|
||||
import { buildSessionKey } from "../lib/sessionKey";
|
||||
import { buildPinnedSessionKeys, buildSessionKey } from "../lib/sessionKey";
|
||||
import { toggleSessionPin } from "../api/sessionPins";
|
||||
import { SESSION_PINS_QUERY_KEY } from "./useSessionPins";
|
||||
import { admitInboxItem, type TranscriptCache } from "../lib/session-projection";
|
||||
@@ -39,6 +39,8 @@ const isSameModelRef = (left: ModelRef, right: ModelRef | undefined) =>
|
||||
|
||||
const SESSION_LIST_PAGE_SIZE = 25
|
||||
|
||||
const EMPTY_SESSIONS: SessionInfo[] = []
|
||||
|
||||
interface UseSessionsAcrossDirectoriesOptions {
|
||||
search?: string
|
||||
limit?: number
|
||||
@@ -110,8 +112,13 @@ export const useSessionsAcrossDirectories = (
|
||||
refetchOnReconnect: true,
|
||||
});
|
||||
|
||||
const data = useMemo(
|
||||
() => query.data?.pages.flatMap((page) => page.items) ?? EMPTY_SESSIONS,
|
||||
[query.data],
|
||||
);
|
||||
|
||||
return {
|
||||
data: query.data?.pages.flatMap((page) => page.items) ?? [],
|
||||
data,
|
||||
isLoading: query.isLoading,
|
||||
isError: query.isError,
|
||||
fetchNextPage: query.fetchNextPage,
|
||||
@@ -122,16 +129,22 @@ export const useSessionsAcrossDirectories = (
|
||||
};
|
||||
};
|
||||
|
||||
const sessionQueryKey = (sessionID: string | undefined, directory?: string) =>
|
||||
["opencode", "session", sessionID, directory] as const;
|
||||
|
||||
export const sessionQueryOptions = (sessionID: string | undefined, directory?: string) => ({
|
||||
queryKey: sessionQueryKey(sessionID, directory),
|
||||
queryFn: () => getSession(sessionID!),
|
||||
enabled: !!sessionID,
|
||||
refetchOnWindowFocus: true,
|
||||
refetchOnReconnect: true,
|
||||
staleTime: 15000,
|
||||
retry: (failureCount: number, error: unknown) =>
|
||||
!(error instanceof FetchError && error.statusCode === 404) && failureCount < 3,
|
||||
});
|
||||
|
||||
export const useSession = (sessionID: string | undefined, directory?: string) => {
|
||||
return useQuery({
|
||||
queryKey: ["opencode", "session", sessionID, directory],
|
||||
queryFn: () => getSession(sessionID!),
|
||||
enabled: !!sessionID,
|
||||
refetchOnWindowFocus: true,
|
||||
refetchOnReconnect: true,
|
||||
staleTime: 15000,
|
||||
retry: (failureCount, error) => !(error instanceof FetchError && error.statusCode === 404) && failureCount < 3,
|
||||
});
|
||||
return useQuery(sessionQueryOptions(sessionID, directory));
|
||||
};
|
||||
|
||||
export const useCreateSession = (
|
||||
@@ -232,7 +245,7 @@ const cleanupSessionPins = (
|
||||
) => {
|
||||
const pins = queryClient.getQueryData<SessionPin[]>(SESSION_PINS_QUERY_KEY) ?? [];
|
||||
if (pins.length === 0) return;
|
||||
const pinnedKeys = new Set(pins.map((p) => buildSessionKey(p.directory, p.sessionId)));
|
||||
const pinnedKeys = buildPinnedSessionKeys(pins);
|
||||
const targets = (Array.isArray(variables) ? variables : [variables])
|
||||
.map((target) => ({
|
||||
sessionId: getDeleteSessionTargetId(target),
|
||||
@@ -256,15 +269,12 @@ export const useUpdateSession = (directory?: string) => {
|
||||
},
|
||||
onSuccess: (_, variables) => {
|
||||
const { sessionID } = variables;
|
||||
queryClient.invalidateQueries({ queryKey: ["opencode", "session", sessionID, directory] });
|
||||
queryClient.invalidateQueries({ queryKey: sessionQueryKey(sessionID, directory) });
|
||||
invalidateSessionListCaches(queryClient);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const sessionQueryKey = (sessionID: string, directory?: string) =>
|
||||
["opencode", "session", sessionID, directory] as const;
|
||||
|
||||
const patchCachedSessionSelection = (
|
||||
queryClient: ReturnType<typeof useQueryClient>,
|
||||
sessionID: string,
|
||||
@@ -459,7 +469,7 @@ export const useSendShell = (directory?: string) => {
|
||||
const { sessionID } = variables;
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["opencode", "session", sessionID, directory],
|
||||
queryKey: sessionQueryKey(sessionID, directory),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user