From 4d381dd00f95e174a6d771dafe71b8ed673f8fab Mon Sep 17 00:00:00 2001 From: codetorso Date: Mon, 1 Jul 2024 06:08:17 +0530 Subject: canvas (3/3) --- apps/web/app/(canvas)/canvas/page.tsx | 3 +- apps/web/app/(canvas)/canvas/search&create.tsx | 22 +- apps/web/app/(canvas)/canvas/thinkPad.tsx | 274 ++++++++++++++++++++-- apps/web/app/(canvas)/canvasStyles.css | 2 +- apps/web/app/(canvas)/layout.tsx | 13 +- apps/web/app/actions/doers.ts | 35 +++ apps/web/app/actions/fetchers.ts | 2 +- apps/web/app/api/canvasai/route.ts | 27 +++ apps/web/components/canvas/draggableComponent.tsx | 28 +-- apps/web/components/canvas/resizableLayout.tsx | 57 +++-- apps/web/components/canvas/savesnap.tsx | 5 +- apps/web/lib/loadSnap.ts | 2 +- 12 files changed, 397 insertions(+), 73 deletions(-) create mode 100644 apps/web/app/api/canvasai/route.ts diff --git a/apps/web/app/(canvas)/canvas/page.tsx b/apps/web/app/(canvas)/canvas/page.tsx index 815d0b93..d0824a20 100644 --- a/apps/web/app/(canvas)/canvas/page.tsx +++ b/apps/web/app/(canvas)/canvas/page.tsx @@ -6,10 +6,9 @@ import ThinkPads from "./thinkPads"; async function page() { const canvas = await getCanvas(); return ( -
+

Your thinkpads

-

{JSON.stringify(canvas)}

{ // @ts-ignore diff --git a/apps/web/app/(canvas)/canvas/search&create.tsx b/apps/web/app/(canvas)/canvas/search&create.tsx index 3998dde7..a52a4cbe 100644 --- a/apps/web/app/(canvas)/canvas/search&create.tsx +++ b/apps/web/app/(canvas)/canvas/search&create.tsx @@ -1,9 +1,10 @@ -"use client" +"use client"; import { useFormStatus } from "react-dom"; import Image from "next/image"; import { SearchIcon } from "@repo/ui/icons"; import { createCanvas } from "@/app/actions/doers"; +import { toast } from "sonner"; export default function SearchandCreate() { return ( @@ -18,18 +19,27 @@ export default function SearchandCreate() {
-
-
); } function Button() { - const {pending} = useFormStatus() + const { pending } = useFormStatus(); return ( ); -} \ No newline at end of file +} diff --git a/apps/web/app/(canvas)/canvas/thinkPad.tsx b/apps/web/app/(canvas)/canvas/thinkPad.tsx index dad2de48..00a83fda 100644 --- a/apps/web/app/(canvas)/canvas/thinkPad.tsx +++ b/apps/web/app/(canvas)/canvas/thinkPad.tsx @@ -1,5 +1,13 @@ -import {motion} from "framer-motion" +import { getCanvasData } from "@/app/actions/fetchers"; +import { AnimatePresence, motion } from "framer-motion"; import Link from "next/link"; +import { + EllipsisHorizontalCircleIcon, + TrashIcon, + PencilSquareIcon, +} from "@heroicons/react/24/outline"; +import { toast } from "sonner"; +import { Label } from "@repo/ui/shadcn/label"; const childVariants = { hidden: { opacity: 0, y: 10, filter: "blur(2px)" }, @@ -10,27 +18,259 @@ export default function ThinkPad({ title, description, image, - id + id, }: { title: string; description: string; image: string; id: string; }) { + const [deleted, setDeleted] = useState(false); + const [info, setInfo] = useState({ title, description }); return ( - - -
- -
-
{title}
-
- {description} -
-
-
+ + {!deleted && ( + + + + Loading... +
+ } + > + + + +
+ + {info.title} + + + {info.description} + +
+ setDeleted(true)} + setInfo={(e) => setInfo(e)} + /> + + )} + ); -} \ No newline at end of file +} + +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@repo/ui/shadcn/popover"; + +function Menu({ + info, + id, + setDeleted, + setInfo, +}: { + info: { title: string; description: string }; + id: string; + setDeleted: () => void; + setInfo: ({ + title, + description, + }: { + title: string; + description: string; + }) => void; +}) { + return ( + + + + + + + + + + ); +} + +function EditToolbar({ + id, + setInfo, + info +}: { + id: string; + setInfo: ({ + title, + description, + }: { + title: string; + description: string; + }) => void; + info: { + title: string; + description: string; + } +}) { + const [open, setOpen] = useState(false); + return ( + + + + + +
{ + const data = { + title: FormData.get("title") as string, + description: FormData.get("description") as string, + }; + const res = await AddCanvasInfo({ id, ...data }); + if (res.success) { + setOpen(false); + setInfo(data); + } else { + setOpen(false); + toast.error("Something went wrong.", { + style: { backgroundColor: "rgb(22 31 42 / 0.3)" }, + }); + } + }} + > + + Edit Canvas + + Add Description to your canvas. Pro tip: Let AI do the job, as you + add your content into canvas, we will autogenerate your + description. + + +
+
+ + +
+
+ +