From 32b5a025568dcc5788a8a2afc19bf07264e01a63 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Mon, 6 May 2024 18:05:27 +0100
Subject: feature: Dedup links on creation. Fixes #49

---
 .../components/dashboard/bookmarks/EditorCard.tsx    | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

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

diff --git a/apps/web/components/dashboard/bookmarks/EditorCard.tsx b/apps/web/components/dashboard/bookmarks/EditorCard.tsx
index f6ea0c9a..7c036c04 100644
--- a/apps/web/components/dashboard/bookmarks/EditorCard.tsx
+++ b/apps/web/components/dashboard/bookmarks/EditorCard.tsx
@@ -1,5 +1,6 @@
 import type { SubmitErrorHandler, SubmitHandler } from "react-hook-form";
 import { useEffect, useImperativeHandle, useRef } from "react";
+import Link from "next/link";
 import { ActionButton } from "@/components/ui/action-button";
 import { Form, FormControl, FormItem } from "@/components/ui/form";
 import InfoTooltip from "@/components/ui/info-tooltip";
@@ -10,6 +11,7 @@ import { useClientConfig } from "@/lib/clientConfig";
 import { useBookmarkLayoutSwitch } from "@/lib/userLocalSettings/bookmarksLayout";
 import { cn } from "@/lib/utils";
 import { zodResolver } from "@hookform/resolvers/zod";
+import { ExternalLink } from "lucide-react";
 import { useForm } from "react-hook-form";
 import { z } from "zod";
 
@@ -50,7 +52,23 @@ export default function EditorCard({ className }: { className?: string }) {
   useFocusOnKeyPress(inputRef);
 
   const { mutate, isPending } = useCreateBookmarkWithPostHook({
-    onSuccess: () => {
+    onSuccess: (resp) => {
+      if (resp.alreadyExists) {
+        toast({
+          description: (
+            <div className="flex items-center gap-1">
+              Bookmark already exists.
+              <Link
+                className="flex underline-offset-4 hover:underline"
+                href={`/dashboard/preview/${resp.id}`}
+              >
+                Open <ExternalLink className="ml-1 size-4" />
+              </Link>
+            </div>
+          ),
+          variant: "default",
+        });
+      }
       form.reset();
     },
     onError: () => {
-- 
cgit v1.2.3-70-g09d2

