From f14ecc5acb240c6f050e0e3423431a975bc1aa08 Mon Sep 17 00:00:00 2001 From: Gigi Date: Wed, 15 Oct 2025 14:14:54 +0200 Subject: [PATCH] refactor(bookmarks): simplify filtering to only exclude empty content --- src/components/BookmarkList.tsx | 31 ++----------------------------- src/components/Me.tsx | 24 +++--------------------- src/utils/bookmarkUtils.tsx | 5 +++++ 3 files changed, 10 insertions(+), 50 deletions(-) diff --git a/src/components/BookmarkList.tsx b/src/components/BookmarkList.tsx index 5363df63..978deaa7 100644 --- a/src/components/BookmarkList.tsx +++ b/src/components/BookmarkList.tsx @@ -8,11 +8,10 @@ import { BookmarkItem } from './BookmarkItem' import SidebarHeader from './SidebarHeader' import IconButton from './IconButton' import { ViewMode } from './Bookmarks' -import { extractUrlsFromContent } from '../services/bookmarkHelpers' import { usePullToRefresh } from 'use-pull-to-refresh' import RefreshIndicator from './RefreshIndicator' import { BookmarkSkeleton } from './Skeletons' -import { groupIndividualBookmarks } from '../utils/bookmarkUtils' +import { groupIndividualBookmarks, hasContent } from '../utils/bookmarkUtils' interface BookmarkListProps { bookmarks: Bookmark[] @@ -63,35 +62,9 @@ export const BookmarkList: React.FC = ({ isDisabled: !onRefresh }) - // Helper to check if a bookmark has either content or a URL - const hasContentOrUrl = (ib: IndividualBookmark) => { - // Check if has content (text) - const hasContent = ib.content && ib.content.trim().length > 0 - - // Check if has URL - let hasUrl = false - - // For web bookmarks (kind:39701), URL is in the 'd' tag - if (ib.kind === 39701) { - const dTag = ib.tags?.find((t: string[]) => t[0] === 'd')?.[1] - hasUrl = !!dTag && dTag.trim().length > 0 - } else { - // For other bookmarks, extract URLs from content - const urls = extractUrlsFromContent(ib.content || '') - hasUrl = urls.length > 0 - } - - // Always show articles (kind:30023) as they have special handling - if (ib.kind === 30023) return true - - // Otherwise, must have either content or URL - return hasContent || hasUrl - } - // Merge and flatten all individual bookmarks from all lists - // Re-sort after flattening to ensure newest first across all lists const allIndividualBookmarks = bookmarks.flatMap(b => b.individualBookmarks || []) - .filter(hasContentOrUrl) + .filter(hasContent) const groups = groupIndividualBookmarks(allIndividualBookmarks) const sections: Array<{ key: string; title: string; items: IndividualBookmark[] }> = [ { key: 'private', title: `Private bookmarks (${groups.privateItems.length})`, items: groups.privateItems }, diff --git a/src/components/Me.tsx b/src/components/Me.tsx index e1cf6de0..5c7b3501 100644 --- a/src/components/Me.tsx +++ b/src/components/Me.tsx @@ -19,12 +19,11 @@ import BlogPostCard from './BlogPostCard' import { BookmarkItem } from './BookmarkItem' import IconButton from './IconButton' import { ViewMode } from './Bookmarks' -import { extractUrlsFromContent } from '../services/bookmarkHelpers' import { getCachedMeData, setCachedMeData, updateCachedHighlights } from '../services/meCache' import { faBooks } from '../icons/customIcons' import { usePullToRefresh } from 'use-pull-to-refresh' import RefreshIndicator from './RefreshIndicator' -import { groupIndividualBookmarks } from '../utils/bookmarkUtils' +import { groupIndividualBookmarks, hasContent } from '../utils/bookmarkUtils' interface MeProps { relayPool: RelayPool @@ -151,23 +150,6 @@ const Me: React.FC = ({ relayPool, activeTab: propActiveTab, pubkey: pr return `/a/${naddr}` } - // Helper to check if a bookmark has either content or a URL (same logic as BookmarkList) - const hasContentOrUrl = (ib: IndividualBookmark) => { - const hasContent = ib.content && ib.content.trim().length > 0 - - let hasUrl = false - if (ib.kind === 39701) { - const dTag = ib.tags?.find((t: string[]) => t[0] === 'd')?.[1] - hasUrl = !!dTag && dTag.trim().length > 0 - } else { - const urls = extractUrlsFromContent(ib.content || '') - hasUrl = urls.length > 0 - } - - if (ib.kind === 30023) return true - return hasContent || hasUrl - } - const handleSelectUrl = (url: string, bookmark?: { id: string; kind: number; tags: string[][]; pubkey: string }) => { if (bookmark && bookmark.kind === 30023) { // For kind:30023 articles, navigate to the article route @@ -187,9 +169,9 @@ const Me: React.FC = ({ relayPool, activeTab: propActiveTab, pubkey: pr } } - // Merge and flatten all individual bookmarks (same logic as BookmarkList) + // Merge and flatten all individual bookmarks const allIndividualBookmarks = bookmarks.flatMap(b => b.individualBookmarks || []) - .filter(hasContentOrUrl) + .filter(hasContent) const groups = groupIndividualBookmarks(allIndividualBookmarks) const sections: Array<{ key: string; title: string; items: IndividualBookmark[] }> = [ { key: 'private', title: `Private bookmarks (${groups.privateItems.length})`, items: groups.privateItems }, diff --git a/src/utils/bookmarkUtils.tsx b/src/utils/bookmarkUtils.tsx index 501ed2f4..6c5b7775 100644 --- a/src/utils/bookmarkUtils.tsx +++ b/src/utils/bookmarkUtils.tsx @@ -99,3 +99,8 @@ export function groupIndividualBookmarks(items: IndividualBookmark[]) { const publicItems = sorted.filter(i => !i.isPrivate && !isIn(amethyst, i) && !isIn(web, i)) return { privateItems, publicItems, web, amethyst } } + +// Simple filter: only exclude bookmarks with empty/whitespace-only content +export function hasContent(bookmark: IndividualBookmark): boolean { + return !!(bookmark.content && bookmark.content.trim().length > 0) +}