Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,22 @@ export function resolveProjectStatusIndicator(

export function getVisibleThreadsForProject<T extends Pick<Thread, "id">>(input: {
threads: readonly T[];
activeThreadId: T["id"] | undefined;
activeThreadId: string | undefined;
isThreadListExpanded: boolean;
previewLimit: number;
getThreadId?: (thread: T) => string;
}): {
hasHiddenThreads: boolean;
visibleThreads: T[];
hiddenThreads: T[];
} {
const { activeThreadId, isThreadListExpanded, previewLimit, threads } = input;
const {
activeThreadId,
getThreadId = (thread) => thread.id,
isThreadListExpanded,
previewLimit,
threads,
} = input;
const hasHiddenThreads = threads.length > previewLimit;

if (!hasHiddenThreads || isThreadListExpanded) {
Expand All @@ -464,15 +471,15 @@ export function getVisibleThreadsForProject<T extends Pick<Thread, "id">>(input:
}

const previewThreads = threads.slice(0, previewLimit);
if (!activeThreadId || previewThreads.some((thread) => thread.id === activeThreadId)) {
if (!activeThreadId || previewThreads.some((thread) => getThreadId(thread) === activeThreadId)) {
return {
hasHiddenThreads: true,
hiddenThreads: threads.slice(previewLimit),
visibleThreads: previewThreads,
};
}

const activeThread = threads.find((thread) => thread.id === activeThreadId);
const activeThread = threads.find((thread) => getThreadId(thread) === activeThreadId);
if (!activeThread) {
return {
hasHiddenThreads: true,
Expand All @@ -481,12 +488,14 @@ export function getVisibleThreadsForProject<T extends Pick<Thread, "id">>(input:
};
}

const visibleThreadIds = new Set([...previewThreads, activeThread].map((thread) => thread.id));
const visibleThreadIds = new Set(
[...previewThreads, activeThread].map((thread) => getThreadId(thread)),
);

return {
hasHiddenThreads: true,
hiddenThreads: threads.filter((thread) => !visibleThreadIds.has(thread.id)),
visibleThreads: threads.filter((thread) => visibleThreadIds.has(thread.id)),
hiddenThreads: threads.filter((thread) => !visibleThreadIds.has(getThreadId(thread))),
visibleThreads: threads.filter((thread) => visibleThreadIds.has(getThreadId(thread))),
};
}

Expand Down
Loading
Loading