From 75d315dda4232ee3b89abf054f0b6ee10105ffe3 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Fri, 1 Mar 2024 18:00:58 +0000 Subject: feature: Add support for creating and updating lists --- .../lists/[listId]/components/DeleteListButton.tsx | 76 ++++++++++++++++++++++ .../lists/[listId]/components/ListView.tsx | 35 ++++++++++ packages/web/app/dashboard/lists/[listId]/page.tsx | 32 +++++++++ 3 files changed, 143 insertions(+) create mode 100644 packages/web/app/dashboard/lists/[listId]/components/DeleteListButton.tsx create mode 100644 packages/web/app/dashboard/lists/[listId]/components/ListView.tsx create mode 100644 packages/web/app/dashboard/lists/[listId]/page.tsx (limited to 'packages/web/app/dashboard/lists') diff --git a/packages/web/app/dashboard/lists/[listId]/components/DeleteListButton.tsx b/packages/web/app/dashboard/lists/[listId]/components/DeleteListButton.tsx new file mode 100644 index 00000000..8961b2d0 --- /dev/null +++ b/packages/web/app/dashboard/lists/[listId]/components/DeleteListButton.tsx @@ -0,0 +1,76 @@ +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { Trash } from "lucide-react"; +import { useRouter } from "next/navigation"; +import { toast } from "@/components/ui/use-toast"; +import { api } from "@/lib/trpc"; +import { ActionButton } from "@/components/ui/action-button"; +import { useState } from "react"; +import { ZBookmarkList } from "@/lib/types/api/lists"; + +export default function DeleteListButton({ list }: { list: ZBookmarkList }) { + const [isDialogOpen, setDialogOpen] = useState(false); + + const router = useRouter(); + + const listsInvalidationFunction = api.useUtils().lists.list.invalidate; + const { mutate: deleteList, isPending } = api.lists.delete.useMutation({ + onSuccess: () => { + listsInvalidationFunction(); + toast({ + description: `List "${list.icon} ${list.name}" is deleted!`, + }); + router.push("/"); + }, + onError: () => { + toast({ + variant: "destructive", + description: `Something went wrong`, + }); + }, + }); + return ( + + + + + + + + Delete {list.icon} {list.name}? + + + + Are you sure you want to delete {list.icon} {list.name}? + + + + + + deleteList({ listId: list.id })} + > + Delete + + + + + ); +} diff --git a/packages/web/app/dashboard/lists/[listId]/components/ListView.tsx b/packages/web/app/dashboard/lists/[listId]/components/ListView.tsx new file mode 100644 index 00000000..c3d49b6a --- /dev/null +++ b/packages/web/app/dashboard/lists/[listId]/components/ListView.tsx @@ -0,0 +1,35 @@ +"use client"; + +import BookmarksGrid from "@/app/dashboard/bookmarks/components/BookmarksGrid"; +import { ZBookmark } from "@/lib/types/api/bookmarks"; +import { ZBookmarkListWithBookmarks } from "@/lib/types/api/lists"; +import { api } from "@/lib/trpc"; +import DeleteListButton from "./DeleteListButton"; + +export default function ListView({ + bookmarks, + list: initialData, +}: { + list: ZBookmarkListWithBookmarks; + bookmarks: ZBookmark[]; +}) { + const { data } = api.lists.get.useQuery( + { listId: initialData.id }, + { + initialData, + }, + ); + + return ( +
+
+ + {data.icon} {data.name} + + +
+
+ +
+ ); +} diff --git a/packages/web/app/dashboard/lists/[listId]/page.tsx b/packages/web/app/dashboard/lists/[listId]/page.tsx new file mode 100644 index 00000000..b8ca79c3 --- /dev/null +++ b/packages/web/app/dashboard/lists/[listId]/page.tsx @@ -0,0 +1,32 @@ +import { api } from "@/server/api/client"; +import { getServerAuthSession } from "@/server/auth"; +import { TRPCError } from "@trpc/server"; +import { notFound, redirect } from "next/navigation"; +import ListView from "./components/ListView"; + +export default async function ListPage({ + params, +}: { + params: { listId: string }; +}) { + const session = await getServerAuthSession(); + if (!session) { + redirect("/"); + } + + let list; + try { + list = await api.lists.get({ listId: params.listId }); + } catch (e) { + if (e instanceof TRPCError) { + if (e.code == "NOT_FOUND") { + notFound(); + } + } + throw e; + } + + const bookmarks = await api.bookmarks.getBookmarks({ ids: list.bookmarks }); + + return ; +} -- cgit v1.2.3-70-g09d2