From 2413f0efee2dcb4cd4c9389f5a496d4b3f71335c Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Tue, 5 Mar 2024 19:38:34 +0000 Subject: fix: Show loading indicators in the bookmark preview page --- .../dashboard/bookmarks/components/LinkCard.tsx | 33 ++++++++-------------- .../dashboard/bookmarks/components/TextCard.tsx | 16 ++++------- 2 files changed, 17 insertions(+), 32 deletions(-) (limited to 'packages/web/app/dashboard/bookmarks/components') diff --git a/packages/web/app/dashboard/bookmarks/components/LinkCard.tsx b/packages/web/app/dashboard/bookmarks/components/LinkCard.tsx index 76d3f1b8..50f30e47 100644 --- a/packages/web/app/dashboard/bookmarks/components/LinkCard.tsx +++ b/packages/web/app/dashboard/bookmarks/components/LinkCard.tsx @@ -14,25 +14,11 @@ import BookmarkOptions from "./BookmarkOptions"; import { api } from "@/lib/trpc"; import { Maximize2, Star } from "lucide-react"; import TagList from "./TagList"; - -function isStillCrawling(bookmark: ZBookmark) { - return ( - bookmark.content.type == "link" && - !bookmark.content.crawledAt && - Date.now().valueOf() - bookmark.createdAt.valueOf() < 30 * 1000 - ); -} - -function isStillTagging(bookmark: ZBookmark) { - return ( - bookmark.taggingStatus == "pending" && - Date.now().valueOf() - bookmark.createdAt.valueOf() < 30 * 1000 - ); -} - -function isStillLoading(bookmark: ZBookmark) { - return isStillTagging(bookmark) || isStillCrawling(bookmark); -} +import { + isBookmarkStillCrawling, + isBookmarkStillLoading, + isBookmarkStillTagging, +} from "@/lib/bookmarkUtils"; export default function LinkCard({ bookmark: initialData, @@ -53,7 +39,7 @@ export default function LinkCard({ return false; } // If the link is not crawled or not tagged - if (isStillLoading(data)) { + if (isBookmarkStillLoading(data)) { return 1000; } return false; @@ -76,7 +62,7 @@ export default function LinkCard({ @@ -88,7 +74,10 @@ export default function LinkCard({ {/* There's a hack here. Every tag has the full hight of the container itself. That why, when we enable flex-wrap, the overflowed don't show up. */} - +
diff --git a/packages/web/app/dashboard/bookmarks/components/TextCard.tsx b/packages/web/app/dashboard/bookmarks/components/TextCard.tsx index 5e0ba3f9..2565e69d 100644 --- a/packages/web/app/dashboard/bookmarks/components/TextCard.tsx +++ b/packages/web/app/dashboard/bookmarks/components/TextCard.tsx @@ -9,15 +9,8 @@ import TagList from "./TagList"; import Markdown from "react-markdown"; import { useState } from "react"; import { BookmarkedTextViewer } from "./BookmarkedTextViewer"; -import { Button } from "@/components/ui/button"; import Link from "next/link"; - -function isStillTagging(bookmark: ZBookmark) { - return ( - bookmark.taggingStatus == "pending" && - Date.now().valueOf() - bookmark.createdAt.valueOf() < 30 * 1000 - ); -} +import { isBookmarkStillTagging } from "@/lib/bookmarkUtils"; export default function TextCard({ bookmark: initialData, @@ -37,7 +30,7 @@ export default function TextCard({ if (!data) { return false; } - if (isStillTagging(data)) { + if (isBookmarkStillTagging(data)) { return 1000; } return false; @@ -69,7 +62,10 @@ export default function TextCard({ {bookmarkedText.text}
- +
-- cgit v1.2.3-70-g09d2