Elffuss BraidHub

kikocis/continue public

736b2a5165fa · 2.5 KiBRawPermalink
1import { parseConfigYaml } from "@continuedev/config-yaml";
2import { IndexingStatus } from "core";
3import { useMemo } from "react";
4import { useAuth } from "../../../../../context/Auth";
5import { useAppSelector } from "../../../../../redux/hooks";
6import { ExploreBlocksButton } from "../ExploreBlocksButton";
7import DocsIndexingStatus from "./DocsIndexingStatus";
8
9function DocsIndexingStatuses() {
10 const config = useAppSelector((store) => store.config.config);
11 const indexingStatuses = useAppSelector(
12 (store) => store.indexing.indexing.statuses,
13 );
14 const { selectedProfile } = useAuth();
15 const mergedDocs = useMemo(() => {
16 const parsed = selectedProfile?.rawYaml
17 ? parseConfigYaml(selectedProfile?.rawYaml ?? "")
18 : undefined;
19 return (config.docs ?? []).map((doc, index) => ({
20 doc,
21 docFromYaml: parsed?.docs?.[index],
22 }));
23 }, [config.docs, selectedProfile?.rawYaml]);
24
25 const sortedConfigDocs = useMemo(() => {
26 const sorter = (status: IndexingStatus["status"]) => {
27 if (status === "complete") return 0;
28 if (status === "indexing" || status === "paused") return 1;
29 if (status === "failed") return 2;
30 if (status === "aborted" || status === "pending") return 3;
31 return 4;
32 };
33
34 const docs = [...mergedDocs];
35 docs.sort((a, b) => {
36 const statusA = indexingStatuses[a.doc.startUrl]?.status ?? "pending";
37 const statusB = indexingStatuses[b.doc.startUrl]?.status ?? "pending";
38
39 // First, compare by status
40 const statusCompare = sorter(statusA) - sorter(statusB);
41 if (statusCompare !== 0) return statusCompare;
42
43 // If status is the same, sort by presence of icon
44 const hasIconA = !!a.doc.faviconUrl;
45 const hasIconB = !!b.doc.faviconUrl;
46 return hasIconB === hasIconA ? 0 : hasIconB ? 1 : -1;
47 });
48 return docs;
49 }, [mergedDocs, indexingStatuses]);
50
51 return (
52 <div className="flex flex-col gap-1">
53 <div className="flex flex-col overflow-y-auto overflow-x-hidden pr-2">
54 {sortedConfigDocs.map((docConfig) => {
55 return (
56 <div
57 key={docConfig.doc.startUrl}
58 className="flex items-center gap-2"
59 >
60 <div className="flex-grow">
61 <DocsIndexingStatus
62 docFromYaml={docConfig.docFromYaml}
63 docConfig={docConfig.doc}
64 />
65 </div>
66 </div>
67 );
68 })}
69 </div>
70 <ExploreBlocksButton blockType="docs" />
71 </div>
72 );
73}
74
75export default DocsIndexingStatuses;