From 9ab9579b5ef5c041af6c8ee67bf578d1e779cbde Mon Sep 17 00:00:00 2001 From: codetorso Date: Fri, 19 Jul 2024 07:07:52 +0530 Subject: [PATCH] a server rendered navbar --- .../web/app/(dash)/dialogContentContainer.tsx | 224 ++++++++++++++++++ apps/web/app/(dash)/dialogTriggerWrapper.tsx | 46 ++++ 2 files changed, 270 insertions(+) create mode 100644 apps/web/app/(dash)/dialogContentContainer.tsx create mode 100644 apps/web/app/(dash)/dialogTriggerWrapper.tsx diff --git a/apps/web/app/(dash)/dialogContentContainer.tsx b/apps/web/app/(dash)/dialogContentContainer.tsx new file mode 100644 index 00000000..7ad68f17 --- /dev/null +++ b/apps/web/app/(dash)/dialogContentContainer.tsx @@ -0,0 +1,224 @@ +import { StoredSpace } from "@/server/db/schema"; +import { useEffect, useMemo, useState } from "react"; +import { createMemory, createSpace } from "../actions/doers"; +import ComboboxWithCreate from "@repo/ui/shadcn/combobox"; +import { toast } from "sonner"; +import { getSpaces } from "../actions/fetchers"; +import { MinusIcon, PlusCircleIcon } from "lucide-react"; +import { DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@repo/ui/shadcn/dialog"; +import { Label } from "@repo/ui/shadcn/label"; +import { Textarea } from "@repo/ui/shadcn/textarea"; +import { Button } from "@repo/ui/shadcn/button"; + +export function DialogContentContainer({DialogClose}: {DialogClose: ()=> void}) { + const [spaces, setSpaces] = useState([]); +const [content, setContent] = useState(""); +const [selectedSpaces, setSelectedSpaces] = useState([]); + +const options = useMemo( + () => + spaces.map((x) => ({ + label: x.name, + value: x.id.toString(), + })), + [spaces], +); + +const autoDetectedType = useMemo(() => { + if (content.length === 0) { + return "none"; + } + + if ( + content.match(/https?:\/\/(x\.com|twitter\.com)\/[\w]+\/[\w]+\/[\d]+/) + ) { + return "tweet"; + } else if (content.match(/https?:\/\/[\w\.]+/)) { + return "page"; + } else if (content.match(/https?:\/\/www\.[\w\.]+/)) { + return "page"; + } else { + return "note"; + } +}, [content]); + +const handleSubmit = async (content?: string, spaces?: number[]) => { + DialogClose(); + + toast.info("Creating memory...", { + icon: , + duration: 7500, + }); + + if (!content || content.length === 0) { + toast.error("Content is required"); + return; + } + + console.log(spaces); + + const cont = await createMemory({ + content: content, + spaces: spaces ?? undefined, + }); + + setContent(""); + setSelectedSpaces([]); + + if (cont.success) { + toast.success("Memory created", { + richColors: true, + }); + } else { + toast.error(`Memory creation failed: ${cont.error}`); + } +}; + +useEffect(() => { + (async () => { + let spaces = await getSpaces(); + + if (!spaces.success || !spaces.data) { + toast.warning("Unable to get spaces", { + richColors: true, + }); + setSpaces([]); + return; + } + setSpaces(spaces.data); + })(); +}, []); + +return ( + +
{ + const content = e.get("content")?.toString(); + + await handleSubmit(content, selectedSpaces); + }} + className="flex flex-col gap-4 " + > + + Add memory + + A "Memory" is a bookmark, something you want to remember. + + + +
+ +