From d07f2c90065f53d36a3fc0e7db54c32d54a2a332 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Thu, 25 Apr 2024 20:15:15 +0100 Subject: feature(web): Add ability to rename, merge and fast delete tags. Fixes #105 (#125) * feature(web): Allow deleting tags from the all tags page * feature(web): Add ability to rename, merge and fast delete tags. Fixes #105 --- .../components/dashboard/preview/EditableTitle.tsx | 155 ++++----------------- 1 file changed, 25 insertions(+), 130 deletions(-) (limited to 'apps/web/components/dashboard/preview') diff --git a/apps/web/components/dashboard/preview/EditableTitle.tsx b/apps/web/components/dashboard/preview/EditableTitle.tsx index 071b3ca3..8067e23d 100644 --- a/apps/web/components/dashboard/preview/EditableTitle.tsx +++ b/apps/web/components/dashboard/preview/EditableTitle.tsx @@ -1,27 +1,11 @@ -import { useEffect, useRef, useState } from "react"; -import { ActionButtonWithTooltip } from "@/components/ui/action-button"; -import { ButtonWithTooltip } from "@/components/ui/button"; -import { - Tooltip, - TooltipContent, - TooltipPortal, - TooltipTrigger, -} from "@/components/ui/tooltip"; import { toast } from "@/components/ui/use-toast"; -import { Check, Pencil, X } from "lucide-react"; import { useUpdateBookmark } from "@hoarder/shared-react/hooks/bookmarks"; import { ZBookmark } from "@hoarder/shared/types/bookmarks"; -interface Props { - bookmarkId: string; - originalTitle: string | null; - setEditable: (editable: boolean) => void; -} - -function EditMode({ bookmarkId, originalTitle, setEditable }: Props) { - const ref = useRef(null); +import { EditableText } from "../EditableText"; +export function EditableTitle({ bookmark }: { bookmark: ZBookmark }) { const { mutate: updateBookmark, isPending } = useUpdateBookmark({ onSuccess: () => { toast({ @@ -30,107 +14,6 @@ function EditMode({ bookmarkId, originalTitle, setEditable }: Props) { }, }); - useEffect(() => { - if (ref.current) { - ref.current.focus(); - ref.current.textContent = originalTitle; - } - }, [ref]); - - const onSave = () => { - let toSave: string | null = ref.current?.textContent ?? null; - if (originalTitle == toSave) { - // Nothing to do here - return; - } - if (toSave == "") { - toSave = null; - } - updateBookmark({ - bookmarkId, - title: toSave, - }); - setEditable(false); - }; - - return ( -
-
{ - if (e.key === "Enter") { - e.preventDefault(); - } - }} - /> - onSave()} - > - - - { - setEditable(false); - }} - > - - -
- ); -} - -function ViewMode({ originalTitle, setEditable }: Props) { - return ( - -
- - {originalTitle ? ( -

{originalTitle}

- ) : ( -

Untitled

- )} -
- { - setEditable(true); - }} - > - - -
- - {originalTitle && ( - - {originalTitle} - - )} - -
- ); -} - -export function EditableTitle({ bookmark }: { bookmark: ZBookmark }) { - const [editable, setEditable] = useState(false); - let title: string | null = null; switch (bookmark.content.type) { case "link": @@ -149,17 +32,29 @@ export function EditableTitle({ bookmark }: { bookmark: ZBookmark }) { title = null; } - return editable ? ( - - ) : ( - { + updateBookmark( + { + bookmarkId: bookmark.id, + title: newTitle, + }, + { + onError: () => { + toast({ + description: "Something went wrong", + variant: "destructive", + }); + }, + }, + ); + }} + isSaving={isPending} /> ); } -- cgit v1.2.3-70-g09d2