The best way to control Claude Code, Codex and more from any computer or phone

main
ts 37 lines 1.17 KB
Raw
1 import type { ReviewRenderableFile } from "../review/reviewModel";
2
3 export function fileDirectory(path: string) {
4 const separator = path.lastIndexOf("/");
5 return separator < 0 ? "" : path.slice(0, separator);
6 }
7
8 type SheetItem =
9 | {
10 readonly kind: "directory";
11 readonly key: string;
12 readonly directory: string;
13 readonly collapsed: boolean;
14 }
15 | { readonly kind: "file"; readonly key: string; readonly file: ReviewRenderableFile };
16
17 export function groupByDirectory(
18 files: ReadonlyArray<ReviewRenderableFile>,
19 collapsed: ReadonlySet<string>,
20 ) {
21 // Keep the shared review order: a directory gets a new header each time it resumes after a subdirectory.
22 const items: SheetItem[] = [];
23 files.forEach((file, index) => {
24 const directory = fileDirectory(file.path);
25 const previous = files[index - 1];
26 if (!previous || directory !== fileDirectory(previous.path)) {
27 items.push({
28 kind: "directory",
29 key: `directory:${directory}:${index}`,
30 directory,
31 collapsed: collapsed.has(directory),
32 });
33 }
34 if (!collapsed.has(directory)) items.push({ kind: "file", key: file.id, file });
35 });
36 return items;
37 }