import React, { useState } from "react"; import { ArrowLeftIcon, Cog6ToothIcon } from "@heroicons/react/16/solid"; import Link from "next/link"; import Card from "./sidepanelcard"; import { sourcesZod } from "@repo/shared-types"; import { toast } from "sonner"; import { MagnifyingGlassIcon } from "@heroicons/react/24/outline"; type card = { title: string; type: string; source: string; content: string; numChunks: string; }; function Sidepanel() { const [content, setContent] = useState([]); return (
Back
{content.map((v, i) => ( ))}
); } function Search({ setContent }: { setContent: (e: any) => void }) { return (
{ const search = FormData.get("search") as string; const sourcesFetch = await fetch("/api/canvasai", { method: "POST", body: JSON.stringify({ query: search }), }); const sources = await sourcesFetch.json(); console.log(sources); const sourcesParsed = sourcesZod.safeParse(sources); if (!sourcesParsed.success) { console.error(sourcesParsed.error); toast.error("Something went wrong while getting the sources"); return; } const filteredSourceUrls = new Set( sourcesParsed.data.metadata.map((source) => source.url), ); const uniqueSources = sourcesParsed.data.metadata.filter((source) => { if (filteredSourceUrls.has(source.url)) { filteredSourceUrls.delete(source.url); return true; } return false; }); setContent( uniqueSources.map((source) => ({ title: source.title ?? "Untitled", type: source.type ?? "page", source: source.url ?? "https://supermemory.ai", content: source.description ?? "No content available", numChunks: sourcesParsed.data.metadata.filter( (f) => f.url === source.url, ).length, })), ); }} >
); } export default Sidepanel;