aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-05-06 18:05:27 +0100
committerMohamedBassem <me@mbassem.com>2024-05-06 18:05:27 +0100
commit32b5a025568dcc5788a8a2afc19bf07264e01a63 (patch)
tree7ad808c667148154c9244cb3def56315da89ef52 /apps
parent02ef4bfc89e66fdf6593dd744aef53adee57b861 (diff)
downloadkarakeep-32b5a025568dcc5788a8a2afc19bf07264e01a63.tar.zst
feature: Dedup links on creation. Fixes #49
Diffstat (limited to 'apps')
-rw-r--r--apps/mobile/app/dashboard/add-link.tsx9
-rw-r--r--apps/mobile/app/sharing.tsx12
-rw-r--r--apps/mobile/lib/upload.ts2
-rw-r--r--apps/web/components/dashboard/bookmarks/EditorCard.tsx20
4 files changed, 38 insertions, 5 deletions
diff --git a/apps/mobile/app/dashboard/add-link.tsx b/apps/mobile/app/dashboard/add-link.tsx
index d913ac01..5096a9e7 100644
--- a/apps/mobile/app/dashboard/add-link.tsx
+++ b/apps/mobile/app/dashboard/add-link.tsx
@@ -3,17 +3,24 @@ import { Text, View } from "react-native";
import { useRouter } from "expo-router";
import { Button } from "@/components/ui/Button";
import { Input } from "@/components/ui/Input";
+import { useToast } from "@/components/ui/Toast";
import { api } from "@/lib/trpc";
export default function AddNote() {
const [text, setText] = useState("");
const [error, setError] = useState<string | undefined>();
+ const { toast } = useToast();
const router = useRouter();
const invalidateAllBookmarks =
api.useUtils().bookmarks.getBookmarks.invalidate;
const { mutate } = api.bookmarks.createBookmark.useMutation({
- onSuccess: () => {
+ onSuccess: (resp) => {
+ if (resp.alreadyExists) {
+ toast({
+ message: "Bookmark already exists",
+ });
+ }
invalidateAllBookmarks();
if (router.canGoBack()) {
router.replace("../");
diff --git a/apps/mobile/app/sharing.tsx b/apps/mobile/app/sharing.tsx
index 7624474a..7339a017 100644
--- a/apps/mobile/app/sharing.tsx
+++ b/apps/mobile/app/sharing.tsx
@@ -12,12 +12,16 @@ import type { ZBookmark } from "@hoarder/shared/types/bookmarks";
type Mode =
| { type: "idle" }
| { type: "success"; bookmarkId: string }
+ | { type: "alreadyExists"; bookmarkId: string }
| { type: "error" };
function SaveBookmark({ setMode }: { setMode: (mode: Mode) => void }) {
- const onSaved = (d: ZBookmark) => {
+ const onSaved = (d: ZBookmark & { alreadyExists: boolean }) => {
invalidateAllBookmarks();
- setMode({ type: "success", bookmarkId: d.id });
+ setMode({
+ type: d.alreadyExists ? "alreadyExists" : "success",
+ bookmarkId: d.id,
+ });
};
const { hasShareIntent, shareIntent, resetShareIntent } =
@@ -86,6 +90,10 @@ export default function Sharing() {
comp = <Text className="text-4xl text-foreground">Hoarded!</Text>;
break;
}
+ case "alreadyExists": {
+ comp = <Text className="text-4xl text-foreground">Already Hoarded!</Text>;
+ break;
+ }
case "error": {
comp = <Text className="text-4xl text-foreground">Error!</Text>;
break;
diff --git a/apps/mobile/lib/upload.ts b/apps/mobile/lib/upload.ts
index 9eb40e01..0b6db549 100644
--- a/apps/mobile/lib/upload.ts
+++ b/apps/mobile/lib/upload.ts
@@ -12,7 +12,7 @@ import { api } from "./trpc";
export function useUploadAsset(
settings: Settings,
options: {
- onSuccess?: (bookmark: ZBookmark) => void;
+ onSuccess?: (bookmark: ZBookmark & { alreadyExists: boolean }) => void;
onError?: (e: string) => void;
},
) {
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: () => {