From 7956e9fa6772ab57a0794fb7cba7e9d9c0bd7878 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sat, 28 Dec 2024 12:30:24 +0000 Subject: feat: Implement the all highlights page. Fixes #620 --- .../dashboard/preview/BookmarkHtmlHighlighter.tsx | 6 +- .../dashboard/preview/BookmarkPreview.tsx | 15 +---- .../components/dashboard/preview/HighlightsBox.tsx | 64 +--------------------- 3 files changed, 9 insertions(+), 76 deletions(-) (limited to 'apps/web/components/dashboard/preview') diff --git a/apps/web/components/dashboard/preview/BookmarkHtmlHighlighter.tsx b/apps/web/components/dashboard/preview/BookmarkHtmlHighlighter.tsx index b99a1a56..89472184 100644 --- a/apps/web/components/dashboard/preview/BookmarkHtmlHighlighter.tsx +++ b/apps/web/components/dashboard/preview/BookmarkHtmlHighlighter.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useRef, useState } from "react"; +import { ActionButton } from "@/components/ui/action-button"; import { Button } from "@/components/ui/button"; import { Popover, PopoverContent } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; @@ -61,14 +62,15 @@ const ColorPickerMenu: React.FC = ({ ))} {selectedHighlight && ( - + )} diff --git a/apps/web/components/dashboard/preview/BookmarkPreview.tsx b/apps/web/components/dashboard/preview/BookmarkPreview.tsx index b854146c..c257d902 100644 --- a/apps/web/components/dashboard/preview/BookmarkPreview.tsx +++ b/apps/web/components/dashboard/preview/BookmarkPreview.tsx @@ -1,6 +1,5 @@ "use client"; -import { useEffect, useState } from "react"; import Link from "next/link"; import { BookmarkTagsEditor } from "@/components/dashboard/bookmarks/BookmarkTagsEditor"; import { FullPageSpinner } from "@/components/ui/full-page-spinner"; @@ -12,10 +11,9 @@ import { TooltipPortal, TooltipTrigger, } from "@/components/ui/tooltip"; +import useRelativeTime from "@/lib/hooks/relative-time"; import { useTranslation } from "@/lib/i18n/client"; import { api } from "@/lib/trpc"; -import dayjs from "dayjs"; -import relativeTime from "dayjs/plugin/relativeTime"; import { CalendarDays, ExternalLink } from "lucide-react"; import { @@ -35,8 +33,6 @@ import LinkContentSection from "./LinkContentSection"; import { NoteEditor } from "./NoteEditor"; import { TextContentSection } from "./TextContentSection"; -dayjs.extend(relativeTime); - function ContentLoading() { return (
@@ -48,14 +44,7 @@ function ContentLoading() { } function CreationTime({ createdAt }: { createdAt: Date }) { - const [fromNow, setFromNow] = useState(""); - const [localCreatedAt, setLocalCreatedAt] = useState(""); - - // This is to avoid hydration errors when server and clients are in different timezones - useEffect(() => { - setFromNow(dayjs(createdAt).fromNow()); - setLocalCreatedAt(createdAt.toLocaleString()); - }, [createdAt]); + const { fromNow, localCreatedAt } = useRelativeTime(createdAt); return ( diff --git a/apps/web/components/dashboard/preview/HighlightsBox.tsx b/apps/web/components/dashboard/preview/HighlightsBox.tsx index 3c873f3d..af065a9d 100644 --- a/apps/web/components/dashboard/preview/HighlightsBox.tsx +++ b/apps/web/components/dashboard/preview/HighlightsBox.tsx @@ -1,72 +1,14 @@ -import { ActionButton } from "@/components/ui/action-button"; import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@/components/ui/collapsible"; -import { toast } from "@/components/ui/use-toast"; import { useTranslation } from "@/lib/i18n/client"; import { api } from "@/lib/trpc"; -import { cn } from "@/lib/utils"; import { Separator } from "@radix-ui/react-dropdown-menu"; -import { ChevronsDownUp, Trash2 } from "lucide-react"; +import { ChevronsDownUp } from "lucide-react"; -import { useDeleteHighlight } from "@hoarder/shared-react/hooks/highlights"; -import { ZHighlight } from "@hoarder/shared/types/highlights"; - -import { HIGHLIGHT_COLOR_MAP } from "./highlights"; - -function HighlightCard({ highlight }: { highlight: ZHighlight }) { - const { mutate: deleteHighlight, isPending: isDeleting } = useDeleteHighlight( - { - onSuccess: () => { - toast({ - description: "Highlight has been deleted!", - }); - }, - onError: () => { - toast({ - description: "Something went wrong", - variant: "destructive", - }); - }, - }, - ); - - const onBookmarkClick = () => { - document - .querySelector(`[data-highlight-id="${highlight.id}"]`) - ?.scrollIntoView({ - behavior: "smooth", - block: "center", - }); - }; - return ( -
-
- -
-
- deleteHighlight({ highlightId: highlight.id })} - > - - -
-
- ); -} +import HighlightCard from "../highlights/HighlightCard"; export default function HighlightsBox({ bookmarkId }: { bookmarkId: string }) { const { t } = useTranslation(); @@ -87,7 +29,7 @@ export default function HighlightsBox({ bookmarkId }: { bookmarkId: string }) { {highlights.highlights.map((highlight) => ( <> - + ))} -- cgit v1.2.3-70-g09d2