diff --git a/apps/web/app/(dash)/menu.tsx b/apps/web/app/(dash)/menu.tsx index e5501958..396623ff 100644 --- a/apps/web/app/(dash)/menu.tsx +++ b/apps/web/app/(dash)/menu.tsx @@ -1,176 +1,365 @@ -import React from "react"; +"use client"; + +import React, { useEffect, useMemo, useState } from "react"; import Image from "next/image"; import Link from "next/link"; -import { MemoriesIcon, CanvasIcon, AddIcon } from "@repo/ui/icons"; -import { DialogTrigger } from "@repo/ui/shadcn/dialog"; - -import { HomeIcon } from "@heroicons/react/24/solid"; import { - PencilSquareIcon, - PlusIcon, - PresentationChartLineIcon, - RectangleStackIcon, -} from "@heroicons/react/24/solid"; -import DialogTriggerWrapper, { - DialogDesktopTrigger, - DialogMobileTrigger, -} from "./dialogTriggerWrapper"; - -const menuItems = [ - { - icon: MemoriesIcon, - text: "Memories", - url: "/memories", - disabled: false, - }, - { - icon: CanvasIcon, - text: "Canvas", - url: "/canvas", - disabled: true, - }, -]; - -const items = [ - { - icon: , - name: "home", - url: "/home", - disabled: false, - }, - { - icon: , - name: "memories", - url: "/memories", - disabled: false, - }, - // { - // icon: , - // name: 'editor', - // url: '/#', - // disabled: true, - // }, - // { - // icon: , - // name: 'thinkpad', - // url: '/#', - // disabled: true, - // }, -]; + MemoriesIcon, + ExploreIcon, + CanvasIcon, + AddIcon, + HomeIcon as HomeIconWeb, +} from "@repo/ui/icons"; +import { Button } from "@repo/ui/shadcn/button"; +import { MinusIcon, PlusCircleIcon } from "lucide-react"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@repo/ui/shadcn/dialog"; +import { Label } from "@repo/ui/shadcn/label"; +import { Textarea } from "@repo/ui/shadcn/textarea"; +import { toast } from "sonner"; +import { getSpaces } from "../actions/fetchers"; +import { HomeIcon } from "@heroicons/react/24/solid"; +import { createMemory, createSpace } from "../actions/doers"; +import ComboboxWithCreate from "@repo/ui/shadcn/combobox"; +import { StoredSpace } from "@/server/db/schema"; +import useMeasure from "react-use-measure"; function Menu() { + const [spaces, setSpaces] = useState([]); + + useEffect(() => { + (async () => { + let spaces = await getSpaces(); + + if (!spaces.success || !spaces.data) { + toast.warning("Unable to get spaces", { + richColors: true, + }); + setSpaces([]); + return; + } + setSpaces(spaces.data); + })(); + }, []); + + const menuItems = [ + { + icon: HomeIconWeb, + text: "Home", + url: "/home", + disabled: false, + }, + { + icon: MemoriesIcon, + text: "Memories", + url: "/memories", + disabled: false, + }, + ]; + + const [content, setContent] = useState(""); + const [selectedSpaces, setSelectedSpaces] = useState([]); + + 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 [dialogOpen, setDialogOpen] = useState(false); + + const options = useMemo( + () => + spaces.map((x) => ({ + label: x.name, + value: x.id.toString(), + })), + [spaces], + ); + + const handleSubmit = async (content?: string, spaces?: number[]) => { + setDialogOpen(false); + + 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}`); + } + }; + return ( <> {/* Desktop Menu */} -
-
-
- -
- {items.map((v) => ( - + +
+
+
+ + Logo +

+ Add +

+
+
+ {menuItems.map((item) => ( + + {`${item.text} +

+ {item.text} +

+ ))}
-
- {/* Mobile Menu */} -
-
- +
{ + const content = e.get("content")?.toString(); + + await handleSubmit(content, selectedSpaces); + }} + className="flex flex-col gap-4 " > - -

Home

- + + Add memory + + A "Memory" is a bookmark, something you want to remember. + + - - {menuItems.map((item) => ( +
+ +