import { Editor } from "novel"; import { DialogClose, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "../ui/dialog"; import { Input } from "../ui/input"; import { Label } from "../ui/label"; import { Markdown } from "tiptap-markdown"; import { useEffect, useRef, useState } from "react"; import { FilterMemories, FilterSpaces } from "./FilterCombobox"; import { useMemory } from "@/contexts/MemoryContext"; import { Loader, Plus, X } from "lucide-react"; import { StoredContent } from "@/server/db/schema"; import { cleanUrl } from "@/lib/utils"; import { motion } from "framer-motion"; import { getMetaData } from "@/server/helpers"; export function AddMemoryPage({ closeDialog }: { closeDialog: () => void }) { const { addMemory } = useMemory(); const [loading, setLoading] = useState(false); const [url, setUrl] = useState(""); const [selectedSpacesId, setSelectedSpacesId] = useState([]); return (
Add a web page to memory This will take you the web page you are trying to add to memory, where the extension will save the page to memory setUrl(e.target.value)} disabled={loading} /> Cancel
); } export function NoteAddPage({ closeDialog }: { closeDialog: () => void }) { const { addMemory } = useMemory(); const [selectedSpacesId, setSelectedSpacesId] = useState([]); const inputRef = useRef(null); const [name, setName] = useState(""); const [content, setContent] = useState(""); const [loading, setLoading] = useState(false); function check(): boolean { const data = { name: name.trim(), content, }; if (!data.name || data.name.length < 1) { if (!inputRef.current) { alert("Please enter a name for the note"); return false; } inputRef.current.value = ""; inputRef.current.placeholder = "Please enter a title for the note"; inputRef.current.dataset["error"] = "true"; setTimeout(() => { inputRef.current!.placeholder = "Title of the note"; inputRef.current!.dataset["error"] = "false"; }, 500); inputRef.current.focus(); return false; } return true; } return (
setName(e.target.value)} /> { if (!editor) return; setContent(editor.storage.markdown.getMarkdown()); }} extensions={[Markdown]} className="novel-editor bg-rgray-4 border-rgray-7 dark mt-5 max-h-[60vh] min-h-[40vh] w-[50vw] overflow-y-auto rounded-lg border [&>div>div]:p-5" /> Cancel
); } export function SpaceAddPage({ closeDialog }: { closeDialog: () => void }) { const { addSpace } = useMemory(); const inputRef = useRef(null); const [name, setName] = useState(""); const [loading, setLoading] = useState(false); const [selected, setSelected] = useState([]); function check(): boolean { const data = { name: name.trim(), }; if (!data.name || data.name.length < 1) { if (!inputRef.current) { alert("Please enter a name for the note"); return false; } inputRef.current.value = ""; inputRef.current.placeholder = "Please enter a title for the space"; inputRef.current.dataset["error"] = "true"; setTimeout(() => { inputRef.current!.placeholder = "Enter the name of the space"; inputRef.current!.dataset["error"] = "false"; }, 500); inputRef.current.focus(); return false; } return true; } return (
Add a space setName(e.target.value)} className="bg-rgray-4 mt-2 w-full placeholder:transition placeholder:duration-500 data-[error=true]:placeholder:text-red-400 focus-visible:data-[error=true]:ring-red-500/10" /> {selected.length > 0 && ( <>
{selected.map((i) => ( setSelected((prev) => prev.filter((p) => p.id !== i.id)) } {...i} /> ))}
)} Memory Cancel
); } export function MemorySelectedItem({ id, title, url, type, image, onRemove, }: StoredContent & { onRemove: () => void }) { return (
{title} {type === "note" ? "Note" : cleanUrl(url)}
); }