From fe13408831dce4bdae4911098d6079a097cae9e8 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Tue, 9 Apr 2024 15:49:24 +0100
Subject: feature(web): Allow uploading directly into lists/tags. Fixes #69

---
 apps/web/components/dashboard/UploadDropzone.tsx | 25 ++++++++++--------------
 1 file changed, 10 insertions(+), 15 deletions(-)

(limited to 'apps/web/components/dashboard/UploadDropzone.tsx')

diff --git a/apps/web/components/dashboard/UploadDropzone.tsx b/apps/web/components/dashboard/UploadDropzone.tsx
index 70e6483a..bd08d2cf 100644
--- a/apps/web/components/dashboard/UploadDropzone.tsx
+++ b/apps/web/components/dashboard/UploadDropzone.tsx
@@ -1,12 +1,12 @@
 "use client";
 
 import React, { useState } from "react";
-import { api } from "@/lib/trpc";
 import { cn } from "@/lib/utils";
 import { useMutation } from "@tanstack/react-query";
 import { TRPCClientError } from "@trpc/client";
 import DropZone from "react-dropzone";
 
+import { useCreateBookmarkWithPostHook } from "@hoarder/shared-react/hooks/bookmarks";
 import {
   zUploadErrorSchema,
   zUploadResponseSchema,
@@ -16,20 +16,15 @@ import LoadingSpinner from "../ui/spinner";
 import { toast } from "../ui/use-toast";
 
 function useUploadAsset({ onComplete }: { onComplete: () => void }) {
-  const invalidateAllBookmarks =
-    api.useUtils().bookmarks.getBookmarks.invalidate;
-
-  const { mutateAsync: createBookmark } =
-    api.bookmarks.createBookmark.useMutation({
-      onSuccess: () => {
-        toast({ description: "Bookmark uploaded" });
-        invalidateAllBookmarks();
-        onComplete();
-      },
-      onError: () => {
-        toast({ description: "Something went wrong", variant: "destructive" });
-      },
-    });
+  const { mutateAsync: createBookmark } = useCreateBookmarkWithPostHook({
+    onSuccess: () => {
+      toast({ description: "Bookmark uploaded" });
+      onComplete();
+    },
+    onError: () => {
+      toast({ description: "Something went wrong", variant: "destructive" });
+    },
+  });
 
   const { mutateAsync: runUpload } = useMutation({
     mutationFn: async (file: File) => {
-- 
cgit v1.2.3-70-g09d2

