From d6dd76021226802adf5295b3243d6f2ae4fa5cc2 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 10 Mar 2024 17:59:58 +0000 Subject: refactor: Move all components to the top level directory --- packages/web/app/dashboard/archive/page.tsx | 2 +- .../dashboard/bookmarks/components/AddBookmark.tsx | 100 ---------- .../bookmarks/components/AddToListModal.tsx | 168 ----------------- .../bookmarks/components/BookmarkCardSkeleton.tsx | 30 --- .../bookmarks/components/BookmarkOptions.tsx | 185 ------------------ .../bookmarks/components/BookmarkedTextEditor.tsx | 109 ----------- .../bookmarks/components/BookmarkedTextViewer.tsx | 20 -- .../dashboard/bookmarks/components/Bookmarks.tsx | 32 ---- .../bookmarks/components/BookmarksGrid.tsx | 64 ------- .../dashboard/bookmarks/components/LinkCard.tsx | 114 ------------ .../app/dashboard/bookmarks/components/TagList.tsx | 39 ---- .../dashboard/bookmarks/components/TagModal.tsx | 207 --------------------- .../dashboard/bookmarks/components/TextCard.tsx | 94 ---------- packages/web/app/dashboard/bookmarks/layout.tsx | 2 +- packages/web/app/dashboard/bookmarks/page.tsx | 2 +- packages/web/app/dashboard/components/AllLists.tsx | 60 ------ .../web/app/dashboard/components/ModileSidebar.tsx | 24 --- .../app/dashboard/components/ModileSidebarItem.tsx | 27 --- .../web/app/dashboard/components/NewListModal.tsx | 170 ----------------- packages/web/app/dashboard/components/Sidebar.tsx | 66 ------- .../web/app/dashboard/components/SidebarItem.tsx | 33 ---- .../dashboard/components/SidebarProfileOptions.tsx | 35 ---- packages/web/app/dashboard/favourites/page.tsx | 2 +- packages/web/app/dashboard/layout.tsx | 4 +- .../lists/[listId]/components/DeleteListButton.tsx | 77 -------- .../lists/[listId]/components/ListView.tsx | 25 --- packages/web/app/dashboard/lists/[listId]/page.tsx | 4 +- .../dashboard/lists/components/AllListsView.tsx | 66 ------- packages/web/app/dashboard/lists/page.tsx | 2 +- .../[bookmarkId]/components/BookmarkPreview.tsx | 101 ---------- .../app/dashboard/preview/[bookmarkId]/page.tsx | 2 +- packages/web/app/dashboard/search/page.tsx | 2 +- .../dashboard/settings/components/AddApiKey.tsx | 167 ----------------- .../settings/components/ApiKeySettings.tsx | 49 ----- .../dashboard/settings/components/DeleteApiKey.tsx | 74 -------- packages/web/app/dashboard/settings/page.tsx | 2 +- packages/web/app/dashboard/tags/[tagName]/page.tsx | 2 +- 37 files changed, 13 insertions(+), 2149 deletions(-) delete mode 100644 packages/web/app/dashboard/bookmarks/components/AddBookmark.tsx delete mode 100644 packages/web/app/dashboard/bookmarks/components/AddToListModal.tsx delete mode 100644 packages/web/app/dashboard/bookmarks/components/BookmarkCardSkeleton.tsx delete mode 100644 packages/web/app/dashboard/bookmarks/components/BookmarkOptions.tsx delete mode 100644 packages/web/app/dashboard/bookmarks/components/BookmarkedTextEditor.tsx delete mode 100644 packages/web/app/dashboard/bookmarks/components/BookmarkedTextViewer.tsx delete mode 100644 packages/web/app/dashboard/bookmarks/components/Bookmarks.tsx delete mode 100644 packages/web/app/dashboard/bookmarks/components/BookmarksGrid.tsx delete mode 100644 packages/web/app/dashboard/bookmarks/components/LinkCard.tsx delete mode 100644 packages/web/app/dashboard/bookmarks/components/TagList.tsx delete mode 100644 packages/web/app/dashboard/bookmarks/components/TagModal.tsx delete mode 100644 packages/web/app/dashboard/bookmarks/components/TextCard.tsx delete mode 100644 packages/web/app/dashboard/components/AllLists.tsx delete mode 100644 packages/web/app/dashboard/components/ModileSidebar.tsx delete mode 100644 packages/web/app/dashboard/components/ModileSidebarItem.tsx delete mode 100644 packages/web/app/dashboard/components/NewListModal.tsx delete mode 100644 packages/web/app/dashboard/components/Sidebar.tsx delete mode 100644 packages/web/app/dashboard/components/SidebarItem.tsx delete mode 100644 packages/web/app/dashboard/components/SidebarProfileOptions.tsx delete mode 100644 packages/web/app/dashboard/lists/[listId]/components/DeleteListButton.tsx delete mode 100644 packages/web/app/dashboard/lists/[listId]/components/ListView.tsx delete mode 100644 packages/web/app/dashboard/lists/components/AllListsView.tsx delete mode 100644 packages/web/app/dashboard/preview/[bookmarkId]/components/BookmarkPreview.tsx delete mode 100644 packages/web/app/dashboard/settings/components/AddApiKey.tsx delete mode 100644 packages/web/app/dashboard/settings/components/ApiKeySettings.tsx delete mode 100644 packages/web/app/dashboard/settings/components/DeleteApiKey.tsx (limited to 'packages/web/app/dashboard') diff --git a/packages/web/app/dashboard/archive/page.tsx b/packages/web/app/dashboard/archive/page.tsx index 81eea57c..69559185 100644 --- a/packages/web/app/dashboard/archive/page.tsx +++ b/packages/web/app/dashboard/archive/page.tsx @@ -1,4 +1,4 @@ -import Bookmarks from "../bookmarks/components/Bookmarks"; +import Bookmarks from "@/components/dashboard/bookmarks/Bookmarks"; export default async function ArchivedBookmarkPage() { return ( diff --git a/packages/web/app/dashboard/bookmarks/components/AddBookmark.tsx b/packages/web/app/dashboard/bookmarks/components/AddBookmark.tsx deleted file mode 100644 index d12fc663..00000000 --- a/packages/web/app/dashboard/bookmarks/components/AddBookmark.tsx +++ /dev/null @@ -1,100 +0,0 @@ -"use client"; - -import { Form, FormControl, FormField, FormItem } from "@/components/ui/form"; -import { Input } from "@/components/ui/input"; -import { Pencil, Plus } from "lucide-react"; -import { useForm, SubmitErrorHandler } from "react-hook-form"; -import { z } from "zod"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { toast } from "@/components/ui/use-toast"; -import { api } from "@/lib/trpc"; -import { ActionButton } from "@/components/ui/action-button"; -import { Button } from "@/components/ui/button"; -import { BookmarkedTextEditor } from "./BookmarkedTextEditor"; -import { useState } from "react"; - -function AddText() { - const [isEditorOpen, setEditorOpen] = useState(false); - - return ( -
- - -
- ); -} - -function AddLink() { - const formSchema = z.object({ - url: z.string().url({ message: "The link must be a valid URL" }), - }); - const form = useForm>({ - resolver: zodResolver(formSchema), - defaultValues: { - url: "", - }, - }); - - const invalidateBookmarksCache = api.useUtils().bookmarks.invalidate; - const createBookmarkMutator = api.bookmarks.createBookmark.useMutation({ - onSuccess: () => { - invalidateBookmarksCache(); - form.reset(); - }, - onError: () => { - toast({ description: "Something went wrong", variant: "destructive" }); - }, - }); - - const onError: SubmitErrorHandler> = (errors) => { - toast({ - description: Object.values(errors) - .map((v) => v.message) - .join("\n"), - variant: "destructive", - }); - }; - - return ( -
- - createBookmarkMutator.mutate({ url: value.url, type: "link" }), - onError, - )} - > -
- { - return ( - - - - - - ); - }} - /> - - - -
-
- - ); -} - -export default function AddBookmark() { - return ( -
- - -
- ); -} diff --git a/packages/web/app/dashboard/bookmarks/components/AddToListModal.tsx b/packages/web/app/dashboard/bookmarks/components/AddToListModal.tsx deleted file mode 100644 index c9fd5da0..00000000 --- a/packages/web/app/dashboard/bookmarks/components/AddToListModal.tsx +++ /dev/null @@ -1,168 +0,0 @@ -import { ActionButton } from "@/components/ui/action-button"; -import { Button } from "@/components/ui/button"; -import { - Dialog, - DialogClose, - DialogContent, - DialogFooter, - DialogHeader, - DialogTitle, -} from "@/components/ui/dialog"; -import { - Form, - FormControl, - FormField, - FormItem, - FormMessage, -} from "@/components/ui/form"; - -import { toast } from "@/components/ui/use-toast"; -import { api } from "@/lib/trpc"; -import { useState } from "react"; - -import { - Select, - SelectContent, - SelectGroup, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select"; -import LoadingSpinner from "@/components/ui/spinner"; -import { z } from "zod"; -import { useForm } from "react-hook-form"; -import { zodResolver } from "@hookform/resolvers/zod"; - -export default function AddToListModal({ - bookmarkId, - open, - setOpen, -}: { - bookmarkId: string; - open: boolean; - setOpen: (open: boolean) => void; -}) { - const formSchema = z.object({ - listId: z.string({ - required_error: "Please select a list", - }), - }); - const form = useForm>({ - resolver: zodResolver(formSchema), - }); - - const { data: lists, isPending: isFetchingListsPending } = - api.lists.list.useQuery(); - - const listInvalidationFunction = api.useUtils().lists.get.invalidate; - const bookmarksInvalidationFunction = - api.useUtils().bookmarks.getBookmarks.invalidate; - - const { mutate: addToList, isPending: isAddingToListPending } = - api.lists.addToList.useMutation({ - onSuccess: (_resp, req) => { - toast({ - description: "List has been updated!", - }); - listInvalidationFunction({ listId: req.listId }); - bookmarksInvalidationFunction(); - }, - onError: (e) => { - if (e.data?.code == "BAD_REQUEST") { - toast({ - variant: "destructive", - description: e.message, - }); - } else { - toast({ - variant: "destructive", - title: "Something went wrong", - }); - } - }, - }); - - const isPending = isFetchingListsPending || isAddingToListPending; - - return ( - - -
- { - addToList({ - bookmarkId: bookmarkId, - listId: value.listId, - }); - })} - > - - Add to List - - -
- {lists ? ( - { - return ( - - - - - - - ); - }} - /> - ) : ( - - )} -
- - - - - - Add - - -
- -
-
- ); -} - -export function useAddToListModal(bookmarkId: string) { - const [open, setOpen] = useState(false); - - return { - open, - setOpen, - content: ( - - ), - }; -} diff --git a/packages/web/app/dashboard/bookmarks/components/BookmarkCardSkeleton.tsx b/packages/web/app/dashboard/bookmarks/components/BookmarkCardSkeleton.tsx deleted file mode 100644 index 1f5fa433..00000000 --- a/packages/web/app/dashboard/bookmarks/components/BookmarkCardSkeleton.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { - ImageCard, - ImageCardBody, - ImageCardContent, - ImageCardFooter, - ImageCardTitle, - ImageCardBanner, -} from "@/components/ui/imageCard"; -import { Skeleton } from "@/components/ui/skeleton"; - -export default function BookmarkCardSkeleton() { - return ( - - - - - - - - - - - - - ); -} diff --git a/packages/web/app/dashboard/bookmarks/components/BookmarkOptions.tsx b/packages/web/app/dashboard/bookmarks/components/BookmarkOptions.tsx deleted file mode 100644 index 4f08ebee..00000000 --- a/packages/web/app/dashboard/bookmarks/components/BookmarkOptions.tsx +++ /dev/null @@ -1,185 +0,0 @@ -"use client"; - -import { useToast } from "@/components/ui/use-toast"; -import { api } from "@/lib/trpc"; -import { ZBookmark, ZBookmarkedLink } from "@hoarder/trpc/types/bookmarks"; -import { Button } from "@/components/ui/button"; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, -} from "@/components/ui/dropdown-menu"; -import { - Archive, - Link, - List, - MoreHorizontal, - Pencil, - RotateCw, - Star, - Tags, - Trash2, -} from "lucide-react"; -import { useTagModel } from "./TagModal"; -import { useState } from "react"; -import { BookmarkedTextEditor } from "./BookmarkedTextEditor"; -import { useAddToListModal } from "./AddToListModal"; - -export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) { - const { toast } = useToast(); - const linkId = bookmark.id; - - const { setOpen: setTagModalIsOpen, content: tagModal } = - useTagModel(bookmark); - const { setOpen: setAddToListModalOpen, content: addToListModal } = - useAddToListModal(bookmark.id); - - const [isTextEditorOpen, setTextEditorOpen] = useState(false); - - const invalidateAllBookmarksCache = - api.useUtils().bookmarks.getBookmarks.invalidate; - - const invalidateBookmarkCache = - api.useUtils().bookmarks.getBookmark.invalidate; - - const onError = () => { - toast({ - variant: "destructive", - title: "Something went wrong", - description: "There was a problem with your request.", - }); - }; - const deleteBookmarkMutator = api.bookmarks.deleteBookmark.useMutation({ - onSuccess: () => { - toast({ - description: "The bookmark has been deleted!", - }); - }, - onError, - onSettled: () => { - invalidateAllBookmarksCache(); - }, - }); - - const updateBookmarkMutator = api.bookmarks.updateBookmark.useMutation({ - onSuccess: () => { - toast({ - description: "The bookmark has been updated!", - }); - }, - onError, - onSettled: () => { - invalidateBookmarkCache({ bookmarkId: bookmark.id }); - invalidateAllBookmarksCache(); - }, - }); - - const crawlBookmarkMutator = api.bookmarks.recrawlBookmark.useMutation({ - onSuccess: () => { - toast({ - description: "Re-fetch has been enqueued!", - }); - }, - onError, - onSettled: () => { - invalidateBookmarkCache({ bookmarkId: bookmark.id }); - }, - }); - - return ( - <> - {tagModal} - {addToListModal} - - - - - - - {bookmark.content.type === "text" && ( - setTextEditorOpen(true)}> - - Edit - - )} - - updateBookmarkMutator.mutate({ - bookmarkId: linkId, - favourited: !bookmark.favourited, - }) - } - > - - {bookmark.favourited ? "Un-favourite" : "Favourite"} - - - updateBookmarkMutator.mutate({ - bookmarkId: linkId, - archived: !bookmark.archived, - }) - } - > - - {bookmark.archived ? "Un-archive" : "Archive"} - - {bookmark.content.type === "link" && ( - { - navigator.clipboard.writeText( - (bookmark.content as ZBookmarkedLink).url, - ); - toast({ - description: "Link was added to your clipboard!", - }); - }} - > - - Copy Link - - )} - setTagModalIsOpen(true)}> - - Edit Tags - - - setAddToListModalOpen(true)}> - - Add to List - - - {bookmark.content.type === "link" && ( - - crawlBookmarkMutator.mutate({ bookmarkId: bookmark.id }) - } - > - - Refresh - - )} - - deleteBookmarkMutator.mutate({ bookmarkId: bookmark.id }) - } - > - - Delete - - - - - ); -} diff --git a/packages/web/app/dashboard/bookmarks/components/BookmarkedTextEditor.tsx b/packages/web/app/dashboard/bookmarks/components/BookmarkedTextEditor.tsx deleted file mode 100644 index a5b58f1a..00000000 --- a/packages/web/app/dashboard/bookmarks/components/BookmarkedTextEditor.tsx +++ /dev/null @@ -1,109 +0,0 @@ -import { ZBookmark } from "@hoarder/trpc/types/bookmarks"; -import { - Dialog, - DialogClose, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, -} from "@/components/ui/dialog"; -import { ActionButton } from "@/components/ui/action-button"; -import { Button } from "@/components/ui/button"; -import { Textarea } from "@/components/ui/textarea"; -import { api } from "@/lib/trpc"; -import { useState } from "react"; -import { toast } from "@/components/ui/use-toast"; - -export function BookmarkedTextEditor({ - bookmark, - open, - setOpen, -}: { - bookmark?: ZBookmark; - open: boolean; - setOpen: (open: boolean) => void; -}) { - const isNewBookmark = bookmark === undefined; - const [noteText, setNoteText] = useState( - bookmark && bookmark.content.type == "text" ? bookmark.content.text : "", - ); - - const invalidateAllBookmarksCache = - api.useUtils().bookmarks.getBookmarks.invalidate; - const invalidateOneBookmarksCache = - api.useUtils().bookmarks.getBookmark.invalidate; - - const { mutate: createBookmarkMutator, isPending: isCreationPending } = - api.bookmarks.createBookmark.useMutation({ - onSuccess: () => { - invalidateAllBookmarksCache(); - toast({ - description: "Note created!", - }); - setOpen(false); - setNoteText(""); - }, - onError: () => { - toast({ description: "Something went wrong", variant: "destructive" }); - }, - }); - const { mutate: updateBookmarkMutator, isPending: isUpdatePending } = - api.bookmarks.updateBookmarkText.useMutation({ - onSuccess: () => { - invalidateOneBookmarksCache({ - bookmarkId: bookmark!.id, - }); - toast({ - description: "Note updated!", - }); - setOpen(false); - }, - onError: () => { - toast({ description: "Something went wrong", variant: "destructive" }); - }, - }); - const isPending = isCreationPending || isUpdatePending; - - const onSave = () => { - if (isNewBookmark) { - createBookmarkMutator({ - type: "text", - text: noteText, - }); - } else { - updateBookmarkMutator({ - bookmarkId: bookmark.id, - text: noteText, - }); - } - }; - - return ( - - - - {isNewBookmark ? "New Note" : "Edit Note"} - - Write your note with markdown support - - -