docs UI working
This commit is contained in:
parent
8e4c56ebea
commit
93eddae58a
7 changed files with 101 additions and 30 deletions
|
|
@ -376,24 +376,15 @@ export default class DocsService {
|
|||
progress: 0,
|
||||
});
|
||||
|
||||
// NOTE - during "indexing" phase, check if aborted before each status update
|
||||
|
||||
const articles: Article[] = [];
|
||||
let processedPages = 0;
|
||||
let estimatedProgress = 0; // progress heuristic = sum series 1/(3*2^n) from n=0 to pages. Alternative e.g. sum 1/(2^n)
|
||||
let estimatedProgress = 0; // progress heuristic = sum series 1/(2^n) from n=1 to pages + 1. Alternative e.g. sum 1/(2^n)
|
||||
|
||||
// Crawl pages and retrieve info as articles
|
||||
for await (const page of this.docsCrawler.crawl(new URL(startUrl))) {
|
||||
estimatedProgress += 1 / (3 * 2 ** processedPages);
|
||||
|
||||
const article = pageToArticle(page);
|
||||
|
||||
if (!article) {
|
||||
continue;
|
||||
}
|
||||
|
||||
articles.push(article);
|
||||
estimatedProgress += 1 / 2 ** (processedPages + 1);
|
||||
|
||||
// NOTE - during "indexing" phase, check if aborted before each status update
|
||||
if (this.isAborted(startUrl)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -404,6 +395,12 @@ export default class DocsService {
|
|||
progress: 0.4 * estimatedProgress, // 0% -> 40%, a heuristic approach for progress calculation
|
||||
});
|
||||
|
||||
const article = pageToArticle(page);
|
||||
if (!article) {
|
||||
continue;
|
||||
}
|
||||
articles.push(article);
|
||||
|
||||
processedPages++;
|
||||
await new Promise((resolve) => setTimeout(resolve, 50)); // Locks down GUI if no sleeping
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline";
|
||||
import {
|
||||
CheckCircleIcon,
|
||||
ChevronDownIcon,
|
||||
ChevronUpIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { SiteIndexingConfig } from "core";
|
||||
import { usePostHog } from "posthog-js/react";
|
||||
import { useContext, useLayoutEffect, useRef, useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { Button, HelperText, Input, lightGray } from "..";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { setShowDialog } from "../../redux/slices/uiStateSlice";
|
||||
import { RootState } from "../../redux/store";
|
||||
import IndexingStatusViewer from "../indexing/IndexingStatus";
|
||||
|
||||
function AddDocsDialog() {
|
||||
const posthog = usePostHog();
|
||||
|
|
@ -18,7 +24,12 @@ function AddDocsDialog() {
|
|||
const [faviconUrl, setFaviconUrl] = useState("");
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const [submittedConfig, setSubmittedConfig] = useState<SiteIndexingConfig>();
|
||||
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const indexingStatuses = useSelector(
|
||||
(store: RootState) => store.state.indexingStatuses,
|
||||
);
|
||||
|
||||
const isFormValid = startUrl && title;
|
||||
|
||||
|
|
@ -41,15 +52,67 @@ function AddDocsDialog() {
|
|||
|
||||
ideMessenger.post("context/addDocs", siteIndexingConfig);
|
||||
|
||||
setSubmittedConfig(siteIndexingConfig);
|
||||
setTitle("");
|
||||
setStartUrl("");
|
||||
setFaviconUrl("");
|
||||
|
||||
dispatch(setShowDialog(false));
|
||||
// dispatch(setShowDialog(false));
|
||||
|
||||
posthog.capture("add_docs_gui", { url: startUrl });
|
||||
}
|
||||
|
||||
if (submittedConfig) {
|
||||
const status = indexingStatuses[submittedConfig.startUrl];
|
||||
return (
|
||||
<div className="flex flex-col p-4">
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
<CheckCircleIcon className="h-8 w-8" />
|
||||
<h1>{`Docs added`}</h1>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 text-stone-500">
|
||||
<p className="m-0 p-0">Title: {submittedConfig.title}</p>
|
||||
<p className="m-0 p-0">Start URL: {submittedConfig.startUrl}</p>
|
||||
{submittedConfig.rootUrl && (
|
||||
<p className="m-0 p-0">Root URL: {submittedConfig.rootUrl}</p>
|
||||
)}
|
||||
{submittedConfig.maxDepth && (
|
||||
<p className="m-0 p-0">Max depth: {submittedConfig.maxDepth}</p>
|
||||
)}
|
||||
{submittedConfig.faviconUrl && (
|
||||
<p className="m-0 p-0">Favicon URL: {submittedConfig.faviconUrl}</p>
|
||||
)}
|
||||
</div>
|
||||
{!!status && (
|
||||
<div className="mt-4 flex flex-col divide-x-0 divide-y-2 divide-solid divide-zinc-700">
|
||||
<p className="m-0 mb-5 p-0 leading-snug">{`Type "@docs" and select ${submittedConfig.title} to reference these docs once indexing is complete. Check indexing status from the "More" page.`}</p>
|
||||
<div className="pt-1">
|
||||
<IndexingStatusViewer status={status} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-4 flex flex-row items-center gap-4">
|
||||
<Button
|
||||
className="flex-1"
|
||||
onClick={() => {
|
||||
setSubmittedConfig(undefined);
|
||||
}}
|
||||
>
|
||||
Add another
|
||||
</Button>
|
||||
<Button
|
||||
className="flex-1"
|
||||
onClick={() => {
|
||||
dispatch(setShowDialog(false));
|
||||
}}
|
||||
>
|
||||
Close
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-4">
|
||||
<div className="mb-8">
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ const DialogContainer = styled.div`
|
|||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: 75%;
|
||||
`;
|
||||
|
||||
const Dialog = styled.div`
|
||||
|
|
@ -72,6 +71,7 @@ const TextDialog = (props: TextDialogProps) => {
|
|||
return (
|
||||
<ScreenCover onClick={props.onClose} hidden={!props.showDialog}>
|
||||
<DialogContainer
|
||||
className="xs:w-[85%] w-[92%] sm:w-[75%]"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ interface IndexingStatusViewerProps {
|
|||
status: IndexingStatus;
|
||||
}
|
||||
|
||||
function FooterIndexingPeek({ status }: IndexingStatusViewerProps) {
|
||||
function ChatIndexingPeek({ status }: IndexingStatusViewerProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const navigate = useNavigate();
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ function FooterIndexingPeek({ status }: IndexingStatusViewerProps) {
|
|||
|
||||
return (
|
||||
<div
|
||||
className="flex cursor-pointer flex-row items-center gap-2 hover:opacity-60"
|
||||
className="flex cursor-pointer flex-row items-center gap-2 hover:opacity-80"
|
||||
onClick={() => {
|
||||
navigate("/more");
|
||||
}}
|
||||
|
|
@ -87,12 +87,12 @@ function ChatIndexingPeeks() {
|
|||
if (!currentlyIndexingDocs.length) return null;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1 px-2 py-1">
|
||||
<p className="m-0 p-0">Indexing in progress</p>
|
||||
<div className="flex flex-col gap-1 px-3 pb-1">
|
||||
{/* <p className="m-0 p-0 text-xs text-stone-500">Indexing in progress</p> */}
|
||||
{hidden
|
||||
? null
|
||||
: currentlyIndexingDocs.map((status) => {
|
||||
return <FooterIndexingPeek status={status} />;
|
||||
return <ChatIndexingPeek status={status} />;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -129,11 +129,11 @@ function IndexingStatusViewer({ status }: IndexingStatusViewerProps) {
|
|||
}
|
||||
</span>
|
||||
|
||||
{status.status === "indexing" && (
|
||||
<span className="lines lines-1 text-right text-xs text-stone-500">
|
||||
{status.description}
|
||||
</span>
|
||||
)}
|
||||
{/* {status.status === "indexing" && ( */}
|
||||
<span className="lines lines-1 text-right text-xs text-stone-500">
|
||||
{status.description}
|
||||
</span>
|
||||
{/* )} */}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {
|
|||
setShowDialog,
|
||||
} from "../../redux/slices/uiStateSlice";
|
||||
import AddDocsDialog from "../dialogs/AddDocsDialog";
|
||||
import { ChevronUpIcon } from "@heroicons/react/24/outline";
|
||||
|
||||
function IndexingStatuses() {
|
||||
const indexingStatuses = useSelector(
|
||||
|
|
@ -17,17 +18,22 @@ function IndexingStatuses() {
|
|||
const docs = Object.values(indexingStatuses).filter(
|
||||
(status) => status.type === "docs" && status.status !== "deleted",
|
||||
);
|
||||
|
||||
return docs;
|
||||
}, [indexingStatuses]);
|
||||
const dispatch = useDispatch();
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
<h3 className="mb-1 mt-0 text-xl">@docs indexes</h3>
|
||||
<div className="flex flex-row items-center justify-between">
|
||||
<h3 className="mb-1 mt-0 text-xl">@docs indexes</h3>
|
||||
{/* <div className="border-1 rounded-full border">
|
||||
<ChevronUpIcon className="h-8 w-8" />
|
||||
</div> */}
|
||||
</div>
|
||||
<span className="text-xs text-stone-500">
|
||||
Manage your documentation sources
|
||||
</span>
|
||||
{/* <div className="flex max-h-[170px] flex-col gap-1 overflow-x-hidden overflow-y-scroll pr-2"> */}
|
||||
{docsStatuses.length ? (
|
||||
docsStatuses.map((status) => {
|
||||
return <IndexingStatusViewer key={status.id} status={status} />;
|
||||
|
|
@ -43,6 +49,7 @@ function IndexingStatuses() {
|
|||
</Button>
|
||||
)}
|
||||
</div>
|
||||
// </div>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ export function Chat() {
|
|||
{widget}
|
||||
<StepsDiv
|
||||
ref={stepsDivRef}
|
||||
className={`overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${state.history.length > 0 ? "h-full" : ""}`}
|
||||
className={`overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${state.history.length > 0 ? "flex-1" : ""}`}
|
||||
onScroll={handleScroll}
|
||||
>
|
||||
{highlights}
|
||||
|
|
@ -506,7 +506,11 @@ export function Chat() {
|
|||
)}
|
||||
</div>
|
||||
</div>
|
||||
<ChatIndexingPeeks />
|
||||
<div
|
||||
className={`${state.history.length === 0 ? "h-full" : ""} flex flex-col justify-end`}
|
||||
>
|
||||
<ChatIndexingPeeks />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue