import { AtSign, Braces, FileCode, FileText, X } from "lucide-react"; import { useMemo, useState } from "react"; import { useQueryClient } from "@tanstack/react-query"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; import { File } from "@/lib/type"; import { cn } from "@/lib/utils"; export const Context = ({ files, setFiles, }: { files: File[]; setFiles: (files: File[]) => void; }) => { const queryClient = useQueryClient(); const [open, setOpen] = useState(false); const getFileIcon = (filePath: string, size = "size-3.5") => { if (filePath.endsWith(".css")) { return ; } else if (filePath.endsWith(".js")) { return ; } else if (filePath.endsWith(".json")) { return ; } else { return ; } }; const getFiles = () => queryClient.getQueryData(["files"]) ?? []; return ( Add Context... Select a file to send as context {getFiles().length === 0 ? ( No files available ) : ( <> { setFiles([]); setOpen(false); }} className={`cursor-pointer w-full px-2 py-1.5 text-xs text-left rounded-md hover:bg-accent hover:text-accent-foreground transition-colors ${ files.length === 0 ? "bg-linear-to-r from-indigo-500/20 to-indigo-500/5 text-primary font-medium" : "text-muted-foreground" }`} > All files (default) {getFiles()?.map((page) => ( { if (files.some((f) => f.path === page.path)) setFiles(files.filter((f) => f.path !== page.path)); else setFiles(files ? [...files, page] : [page]); setOpen(false); }} className={`cursor-pointer w-full px-2 py-1.5 text-xs text-left rounded-md hover:bg-accent hover:text-accent-foreground transition-colors flex items-center gap-1.5 ${ files?.some((f) => f.path === page.path) ? "bg-linear-to-r from-indigo-500/20 to-indigo-500/5 text-primary font-medium" : "text-muted-foreground" }`} > {getFileIcon(page.path, "size-3")} {page.path} ))} > )} {files?.map((file) => ( {getFileIcon(file.path, "size-3")} {file.path} { setFiles(files.filter((f) => f.path !== file.path)); }} > ))} ); };
Select a file to send as context