refactor: simplify sidebar project sorting
Removes recent-project grouping from the sidebar project list Keeps project ordering based on manual and default sort rules only Reduces memoized session-derived state in the sidebar
This commit is contained in:
@@ -1037,46 +1037,6 @@ export const SessionSidebar: React.FC<SessionSidebarProps> = ({
|
||||
const projectSortOrder = useSessionDisplayStore((state) => state.projectSortOrder);
|
||||
const manualProjectOrder = useProjectsStore((state) => state.manualProjectOrder);
|
||||
|
||||
const recentProjectIdsRef = React.useRef<Set<string>>(new Set());
|
||||
const recentProjectIds = React.useMemo(() => {
|
||||
const recentSessions = deriveRecentSessions(sessions);
|
||||
const ids = new Set<string>();
|
||||
|
||||
if (recentSessions.length > 0) {
|
||||
const pathToId = new Map<string, string>();
|
||||
for (const project of normalizedProjects) {
|
||||
if (project.normalizedPath) {
|
||||
pathToId.set(project.normalizedPath, project.id);
|
||||
}
|
||||
}
|
||||
|
||||
for (const session of recentSessions) {
|
||||
const directory = normalizePath((session as Session & { directory?: string | null }).directory ?? null);
|
||||
if (directory) {
|
||||
const projectId = pathToId.get(directory);
|
||||
if (projectId) ids.add(projectId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sessions update on every SSE event; keep the previous Set reference when
|
||||
// membership is unchanged so sortedProjects (and the sidebar sections built
|
||||
// from it) do not recompute on every streaming event.
|
||||
const previous = recentProjectIdsRef.current;
|
||||
if (previous.size === ids.size) {
|
||||
let unchanged = true;
|
||||
for (const id of ids) {
|
||||
if (!previous.has(id)) {
|
||||
unchanged = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (unchanged) return previous;
|
||||
}
|
||||
recentProjectIdsRef.current = ids;
|
||||
return ids;
|
||||
}, [sessions, normalizedProjects]);
|
||||
|
||||
const sortedProjects = React.useMemo(() => {
|
||||
const list = [...normalizedProjects];
|
||||
|
||||
@@ -1112,14 +1072,8 @@ export const SessionSidebar: React.FC<SessionSidebarProps> = ({
|
||||
}
|
||||
}
|
||||
|
||||
if (projectSortOrder === 'manual') {
|
||||
return list;
|
||||
}
|
||||
|
||||
const recent = list.filter((p) => recentProjectIds.has(p.id));
|
||||
const rest = list.filter((p) => !recentProjectIds.has(p.id));
|
||||
return [...recent, ...rest];
|
||||
}, [normalizedProjects, projectSortOrder, manualProjectOrder, recentProjectIds]);
|
||||
return list;
|
||||
}, [normalizedProjects, projectSortOrder, manualProjectOrder]);
|
||||
|
||||
const {
|
||||
projectSections,
|
||||
|
||||
Reference in New Issue
Block a user