diff --git a/src/interface/web/app/search/page.tsx b/src/interface/web/app/search/page.tsx index 3efe589b..06743ac5 100644 --- a/src/interface/web/app/search/page.tsx +++ b/src/interface/web/app/search/page.tsx @@ -73,12 +73,8 @@ import { CommandInput, CommandItem, CommandList, -} from "@/components/ui/command" -import { - Popover, - PopoverContent, - PopoverTrigger, -} from "@/components/ui/popover" +} from "@/components/ui/command"; +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { uploadDataForIndexing } from "../common/chatFunctions"; import { Progress } from "@/components/ui/progress"; @@ -125,11 +121,17 @@ interface FileCardProps { selectedFileFullText: string | null; } -function FileCard({ file, setSelectedFile, setSelectedFileFullText, handleDownload, handleDelete, isDeleting, selectedFileFullText }: FileCardProps) { +function FileCard({ + file, + setSelectedFile, + setSelectedFileFullText, + handleDownload, + handleDelete, + isDeleting, + selectedFileFullText, +}: FileCardProps) { return ( - + { - setSelectedFileFullText( - '', - ); - setSelectedFile( - file.file_name, - ); + setSelectedFileFullText(""); + setSelectedFile(file.file_name); }} > - {file.file_name - .split("/") - .pop()} + {file.file_name.split("/").pop()}
- {file.file_name - .split("/") - .pop()} + {file.file_name.split("/").pop()} @@ -237,7 +218,7 @@ function FileCard({ file, setSelectedFile, setSelectedFileFullText, handleDownlo
- ) + ); } interface NoteResultProps { @@ -397,8 +378,8 @@ const UploadFiles: React.FC<{ Build Your Knowledge Base - Add context for your Khoj knowledge base. - Quickly search and get personalized answers from your documents. + Add context for your Khoj knowledge base. Quickly search and get + personalized answers from your documents.
{ if (props.explicitFile) { @@ -504,17 +485,12 @@ function FileFilterComboBox(props: FileFilterComboBoxProps) { className={`justify-between" ${props.isMobileWidth ? "w-full" : "w-[200px]"}`} > {value - ? ( - props.isMobileWidth ? - "✔️" - : "Selected" - ) - : ( - props.isMobileWidth ? - " " - : "Select file" - ) - } + ? props.isMobileWidth + ? "✔️" + : "Selected" + : props.isMobileWidth + ? " " + : "Select file"} @@ -529,16 +505,16 @@ function FileFilterComboBox(props: FileFilterComboBoxProps) { key={file} value={file} onSelect={(currentValue) => { - setValue(currentValue === value ? "" : currentValue) - setOpen(false) - props.onChooseFile(currentValue) + setValue(currentValue === value ? "" : currentValue); + setOpen(false); + props.onChooseFile(currentValue); }} > {file} @@ -548,7 +524,7 @@ function FileFilterComboBox(props: FileFilterComboBoxProps) { - ) + ); } export default function Search() { @@ -576,18 +552,18 @@ export default function Search() { useEffect(() => { // Load all files once on page load - fetch('/api/content/computer', { - method: 'GET', + fetch("/api/content/computer", { + method: "GET", headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", }, }) - .then(response => response.json()) - .then(data => { + .then((response) => response.json()) + .then((data) => { setAllFiles(data); }) - .catch(error => { - console.error('Error loading files:', error); + .catch((error) => { + console.error("Error loading files:", error); }); }, []); @@ -606,7 +582,6 @@ export default function Search() { } }, [searchQuery]); - function handleSearchInputChange(value: string) { setSearchQuery(value); @@ -673,7 +648,6 @@ export default function Search() { if (Array.isArray(filesList)) { setFiles(filesList.toSorted()); } - } catch (error) { setError("Failed to load files"); console.error("Error fetching files:", error); @@ -778,7 +752,9 @@ export default function Search() { handleSearchInputChange(e.currentTarget.value)} + onChange={(e) => + handleSearchInputChange(e.currentTarget.value) + } onKeyDown={(e) => { if (e.key === "Enter") { search(); @@ -791,7 +767,12 @@ export default function Search() { />
- applySuggestion(file)} isMobileWidth={isMobileWidth} explicitFile={selectedFileFilter} /> + applySuggestion(file)} + isMobileWidth={isMobileWidth} + explicitFile={selectedFileFilter} + />
} - {!searchResults && !fileObjectsLoading && files.length === 0 && ( - - - - - - - Let's get started! - - - -
- To use search, upload docs via the "Add Documents" button. -
- -
- Learn More + {!searchResults && + !fileObjectsLoading && + files.length === 0 && ( + + + + + + + Let's get started! + + + +
+ To use search, upload docs via the + "Add Documents" button.
- -
-
- )} + +
+ Learn More +
+ + + + )}
{files.map((file, index) => ( @@ -906,7 +890,9 @@ export default function Search() { file={file} index={index} setSelectedFile={setSelectedFile} - setSelectedFileFullText={setSelectedFileFullText} + setSelectedFileFullText={ + setSelectedFileFullText + } handleDownload={handleDownload} handleDelete={handleDelete} isDeleting={isDeleting} @@ -920,14 +906,22 @@ export default function Search() { {/* Show prev button if not on first page */} {pageNumber > 0 && ( - setPageNumber(pageNumber - 1)} /> + + setPageNumber(pageNumber - 1) + } + /> )} {/* Show first page if not on first two pages */} {pageNumber > 1 && ( - setPageNumber(0)}>1 + setPageNumber(0)} + > + 1 + )} @@ -941,19 +935,33 @@ export default function Search() { {/* Show previous page if not on first page */} {pageNumber > 0 && ( - setPageNumber(pageNumber - 1)}>{pageNumber} + + setPageNumber(pageNumber - 1) + } + > + {pageNumber} + )} {/* Current page */} - {pageNumber + 1} + + {pageNumber + 1} + {/* Show next page if not on last page */} {pageNumber < numPages - 1 && ( - setPageNumber(pageNumber + 1)}>{pageNumber + 2} + + setPageNumber(pageNumber + 1) + } + > + {pageNumber + 2} + )} @@ -967,22 +975,30 @@ export default function Search() { {/* Show last page if not on last two pages */} {pageNumber < numPages - 2 && ( - setPageNumber(numPages - 1)}>{numPages} + + setPageNumber(numPages - 1) + } + > + {numPages} + )} {/* Show next button if not on last page */} {pageNumber < numPages - 1 && ( - setPageNumber(pageNumber + 1)} /> + + setPageNumber(pageNumber + 1) + } + /> )} -
)} -