diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-07-06 22:02:07 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-07-06 22:02:28 +0000 |
| commit | 362be3008aa8b036c4c448a86e459044af8784c2 (patch) | |
| tree | 27a9f2195558770820cab3da0859a4569d1db08e /apps/mobile/app | |
| parent | 959da9a8980b235370f3d1ae7eecf93df5508e2c (diff) | |
| download | karakeep-362be3008aa8b036c4c448a86e459044af8784c2.tar.zst | |
fix(mobile): Fix crash when bookmark doesn't have archive or screenshot. Fixes #1584
Diffstat (limited to 'apps/mobile/app')
| -rw-r--r-- | apps/mobile/app/dashboard/bookmarks/[slug]/index.tsx | 81 |
1 files changed, 58 insertions, 23 deletions
diff --git a/apps/mobile/app/dashboard/bookmarks/[slug]/index.tsx b/apps/mobile/app/dashboard/bookmarks/[slug]/index.tsx index 1cf2ad3d..00954dd8 100644 --- a/apps/mobile/app/dashboard/bookmarks/[slug]/index.tsx +++ b/apps/mobile/app/dashboard/bookmarks/[slug]/index.tsx @@ -47,41 +47,75 @@ import { BookmarkTypes, ZBookmark } from "@karakeep/shared/types/bookmarks"; type BookmarkLinkType = "browser" | "reader" | "screenshot" | "archive"; +function getAvailableViewTypes(bookmark: ZBookmark): BookmarkLinkType[] { + if (bookmark.content.type !== BookmarkTypes.LINK) { + return []; + } + + const availableTypes: BookmarkLinkType[] = ["browser", "reader"]; + + if (bookmark.assets.some((asset) => asset.assetType === "screenshot")) { + availableTypes.push("screenshot"); + } + + if ( + bookmark.assets.some( + (asset) => + asset.assetType === "precrawledArchive" || + asset.assetType === "fullPageArchive", + ) + ) { + availableTypes.push("archive"); + } + + return availableTypes; +} + function BookmarkLinkTypeSelector({ type, onChange, + bookmark, }: { type: BookmarkLinkType; onChange: (type: BookmarkLinkType) => void; + bookmark: ZBookmark; }) { + const availableTypes = getAvailableViewTypes(bookmark); + + const allActions = [ + { + id: "reader" as const, + title: "Reader View", + state: type === "reader" ? ("on" as const) : undefined, + }, + { + id: "browser" as const, + title: "Browser", + state: type === "browser" ? ("on" as const) : undefined, + }, + { + id: "screenshot" as const, + title: "Screenshot", + state: type === "screenshot" ? ("on" as const) : undefined, + }, + { + id: "archive" as const, + title: "Archived Page", + state: type === "archive" ? ("on" as const) : undefined, + }, + ]; + + const availableActions = allActions.filter((action) => + availableTypes.includes(action.id), + ); + return ( <MenuView onPressAction={({ nativeEvent }) => { Haptics.selectionAsync(); onChange(nativeEvent.event as BookmarkLinkType); }} - actions={[ - { - id: "reader", - title: "Reader", - state: type === "reader" ? "on" : undefined, - }, - { - id: "browser", - title: "Browser", - state: type === "browser" ? "on" : undefined, - }, - { - id: "screenshot", - title: "Screenshot", - state: type === "screenshot" ? "on" : undefined, - }, - { - id: "archive", - title: "Archive", - state: type === "archive" ? "on" : undefined, - }, - ]} + actions={availableActions} shouldOpenOnLongPress={false} > <ChevronDown onPress={() => Haptics.selectionAsync()} color="gray" /> @@ -346,7 +380,7 @@ export default function ListView() { const isDark = colorScheme === "dark"; const [bookmarkLinkType, setBookmarkLinkType] = - useState<BookmarkLinkType>("reader"); + useState<BookmarkLinkType>("browser"); if (typeof slug !== "string") { throw new Error("Unexpected param type"); @@ -407,6 +441,7 @@ export default function ListView() { <BookmarkLinkTypeSelector type={bookmarkLinkType} onChange={(type) => setBookmarkLinkType(type)} + bookmark={bookmark} /> ) : undefined, }} |
