From 82ca8e3a55f26a8709251f161224e92b93fc5828 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 9 Mar 2025 15:34:24 +0000 Subject: fix: Add error boundary around bookmark cards --- .../dashboard/bookmarks/BookmarkCard.tsx | 3 ++ .../dashboard/bookmarks/BookmarksGrid.tsx | 10 +++++-- .../components/dashboard/bookmarks/UnknownCard.tsx | 34 ++++++++++++++++++++++ apps/web/package.json | 1 + pnpm-lock.yaml | 14 +++++++++ 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 apps/web/components/dashboard/bookmarks/UnknownCard.tsx diff --git a/apps/web/components/dashboard/bookmarks/BookmarkCard.tsx b/apps/web/components/dashboard/bookmarks/BookmarkCard.tsx index ec0d4069..5f8e4e0a 100644 --- a/apps/web/components/dashboard/bookmarks/BookmarkCard.tsx +++ b/apps/web/components/dashboard/bookmarks/BookmarkCard.tsx @@ -6,6 +6,7 @@ import { BookmarkTypes, ZBookmark } from "@hoarder/shared/types/bookmarks"; import AssetCard from "./AssetCard"; import LinkCard from "./LinkCard"; import TextCard from "./TextCard"; +import UnknownCard from "./UnknownCard"; export default function BookmarkCard({ bookmark: initialData, @@ -55,5 +56,7 @@ export default function BookmarkCard({ bookmark={{ ...bookmark, content: bookmark.content }} /> ); + case BookmarkTypes.UNKNOWN: + return ; } } diff --git a/apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx b/apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx index bb3222a7..b8e8d1e6 100644 --- a/apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx +++ b/apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx @@ -7,6 +7,7 @@ import { } from "@/lib/userLocalSettings/bookmarksLayout"; import tailwindConfig from "@/tailwind.config"; import { Slot } from "@radix-ui/react-slot"; +import { ErrorBoundary } from "react-error-boundary"; import { useInView } from "react-intersection-observer"; import Masonry from "react-masonry-css"; import resolveConfig from "tailwindcss/resolveConfig"; @@ -15,6 +16,7 @@ import type { ZBookmark } from "@hoarder/shared/types/bookmarks"; import BookmarkCard from "./BookmarkCard"; import EditorCard from "./EditorCard"; +import UnknownCard from "./UnknownCard"; function StyledBookmarkCard({ children }: { children: React.ReactNode }) { return ( @@ -78,9 +80,11 @@ export default function BookmarksGrid({ ), ...bookmarks.map((b) => ( - - - + }> + + + + )), ]; return ( diff --git a/apps/web/components/dashboard/bookmarks/UnknownCard.tsx b/apps/web/components/dashboard/bookmarks/UnknownCard.tsx new file mode 100644 index 00000000..970b5e30 --- /dev/null +++ b/apps/web/components/dashboard/bookmarks/UnknownCard.tsx @@ -0,0 +1,34 @@ +"use client"; + +import { useTranslation } from "@/lib/i18n/client"; +import { AlertCircle } from "lucide-react"; + +import type { ZBookmark } from "@hoarder/shared/types/bookmarks"; + +import { BookmarkLayoutAdaptingCard } from "./BookmarkLayoutAdaptingCard"; + +export default function UnknownCard({ + bookmark, + className, +}: { + bookmark: ZBookmark; + className?: string; +}) { + const { t } = useTranslation(); + return ( + ( +
+ +

+ {t("common.something_went_wrong")} +

+
+ )} + /> + ); +} diff --git a/apps/web/package.json b/apps/web/package.json index cb7f6d85..f1c84285 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -74,6 +74,7 @@ "react-dom": "^18.3.1", "react-draggable": "^4.4.6", "react-dropzone": "^14.2.3", + "react-error-boundary": "^5.0.0", "react-hook-form": "^7.50.1", "react-i18next": "^15.1.1", "react-intersection-observer": "^9.13.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ace59c05..a3f10631 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -628,6 +628,9 @@ importers: react-dropzone: specifier: ^14.2.3 version: 14.2.3(react@18.3.1) + react-error-boundary: + specifier: ^5.0.0 + version: 5.0.0(react@18.3.1) react-hook-form: specifier: ^7.50.1 version: 7.50.1(react@18.3.1) @@ -12872,6 +12875,11 @@ packages: peerDependencies: react: '>=16.13.1' + react-error-boundary@5.0.0: + resolution: {integrity: sha512-tnjAxG+IkpLephNcePNA7v6F/QpWLH8He65+DmedchDwg162JZqx4NmbXj0mlAYVVEd81OW7aFhmbsScYfiAFQ==} + peerDependencies: + react: '>=16.13.1' + react-error-overlay@6.0.11: resolution: {integrity: sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg==} @@ -33783,6 +33791,12 @@ snapshots: react: 18.3.1 dev: false + react-error-boundary@5.0.0(react@18.3.1): + dependencies: + '@babel/runtime': 7.26.0 + react: 18.3.1 + dev: false + react-error-overlay@6.0.11: dev: false -- cgit v1.2.3-70-g09d2