From 5f6a414953c7d8d7e53e8284a69cfb4a8d7aa889 Mon Sep 17 00:00:00 2001 From: Gigi Date: Thu, 16 Oct 2025 09:36:17 +0200 Subject: [PATCH] fix: resolve all linter errors and type issues - Remove unused state variables (readsMap, linksMap) by using only setters - Move VALID_FILTERS constant outside component to fix exhaustive-deps warning - Remove unused isReading variable in ReadingProgressIndicator - Remove unused extractUrlFromBookmark function and IndividualBookmark import - Fix type errors in linksFromBookmarks by extracting metadata from tags instead of non-existent properties --- src/components/Me.tsx | 12 +++++----- src/components/ReadingProgressIndicator.tsx | 1 - src/services/readsService.ts | 25 +-------------------- src/utils/linksFromBookmarks.ts | 16 ++++++------- 4 files changed, 16 insertions(+), 38 deletions(-) diff --git a/src/components/Me.tsx b/src/components/Me.tsx index 6d49ebea..d35d2a96 100644 --- a/src/components/Me.tsx +++ b/src/components/Me.tsx @@ -41,6 +41,9 @@ interface MeProps { type TabType = 'highlights' | 'reading-list' | 'reads' | 'links' | 'writings' +// Valid reading progress filters +const VALID_FILTERS: ReadingProgressFilterType[] = ['all', 'unopened', 'started', 'reading', 'completed'] + const Me: React.FC = ({ relayPool, activeTab: propActiveTab, pubkey: propPubkey }) => { const activeAccount = Hooks.useActiveAccount() const navigate = useNavigate() @@ -53,9 +56,9 @@ const Me: React.FC = ({ relayPool, activeTab: propActiveTab, pubkey: pr const [highlights, setHighlights] = useState([]) const [bookmarks, setBookmarks] = useState([]) const [reads, setReads] = useState([]) - const [readsMap, setReadsMap] = useState>(new Map()) + const [, setReadsMap] = useState>(new Map()) const [links, setLinks] = useState([]) - const [linksMap, setLinksMap] = useState>(new Map()) + const [, setLinksMap] = useState>(new Map()) const [writings, setWritings] = useState([]) const [loading, setLoading] = useState(true) const [loadedTabs, setLoadedTabs] = useState>(new Set()) @@ -64,8 +67,7 @@ const Me: React.FC = ({ relayPool, activeTab: propActiveTab, pubkey: pr const [bookmarkFilter, setBookmarkFilter] = useState('all') // Initialize reading progress filter from URL param - const validFilters: ReadingProgressFilterType[] = ['all', 'unopened', 'started', 'reading', 'completed'] - const initialFilter = urlFilter && validFilters.includes(urlFilter as ReadingProgressFilterType) + const initialFilter = urlFilter && VALID_FILTERS.includes(urlFilter as ReadingProgressFilterType) ? (urlFilter as ReadingProgressFilterType) : 'all' const [readingProgressFilter, setReadingProgressFilter] = useState(initialFilter) @@ -79,7 +81,7 @@ const Me: React.FC = ({ relayPool, activeTab: propActiveTab, pubkey: pr // Sync filter state with URL changes useEffect(() => { - const filterFromUrl = urlFilter && validFilters.includes(urlFilter as ReadingProgressFilterType) + const filterFromUrl = urlFilter && VALID_FILTERS.includes(urlFilter as ReadingProgressFilterType) ? (urlFilter as ReadingProgressFilterType) : 'all' setReadingProgressFilter(filterFromUrl) diff --git a/src/components/ReadingProgressIndicator.tsx b/src/components/ReadingProgressIndicator.tsx index e9a11534..9aee1ce4 100644 --- a/src/components/ReadingProgressIndicator.tsx +++ b/src/components/ReadingProgressIndicator.tsx @@ -22,7 +22,6 @@ export const ReadingProgressIndicator: React.FC = // Determine reading state based on progress (matching readingProgressUtils.ts logic) const progressDecimal = clampedProgress / 100 const isStarted = progressDecimal > 0 && progressDecimal <= 0.10 - const isReading = progressDecimal > 0.10 && progressDecimal <= 0.94 // Determine bar color based on state let barColorClass = '' diff --git a/src/services/readsService.ts b/src/services/readsService.ts index 1000d70c..f54adc9b 100644 --- a/src/services/readsService.ts +++ b/src/services/readsService.ts @@ -1,7 +1,7 @@ import { RelayPool } from 'applesauce-relay' import { NostrEvent } from 'nostr-tools' import { Helpers } from 'applesauce-core' -import { Bookmark, IndividualBookmark } from '../types/bookmarks' +import { Bookmark } from '../types/bookmarks' import { fetchReadArticles } from './libraryService' import { queryEvents } from './dataFetch' import { RELAYS } from '../config/relays' @@ -195,26 +195,3 @@ export async function fetchAllReads( return [] } } - -// Helper to extract URL from bookmark content -function extractUrlFromBookmark(bookmark: IndividualBookmark): string[] { - const urls: string[] = [] - - // Check for web bookmark (kind 39701) with 'd' tag - if (bookmark.kind === 39701) { - const dTag = bookmark.tags.find(t => t[0] === 'd')?.[1] - if (dTag) { - urls.push(dTag.startsWith('http') ? dTag : `https://${dTag}`) - } - } - - // Extract URLs from content - const urlRegex = /(https?:\/\/[^\s]+)/g - const matches = bookmark.content.match(urlRegex) - if (matches) { - urls.push(...matches) - } - - return urls -} - diff --git a/src/utils/linksFromBookmarks.ts b/src/utils/linksFromBookmarks.ts index 156f5794..bd3912a7 100644 --- a/src/utils/linksFromBookmarks.ts +++ b/src/utils/linksFromBookmarks.ts @@ -25,11 +25,6 @@ export function deriveLinksFromBookmarks(bookmarks: Bookmark[]): ReadItem[] { } } - // Extract URLs from urlReferences (pre-extracted by bookmarkService) - if (bookmark.urlReferences && bookmark.urlReferences.length > 0) { - urls.push(...bookmark.urlReferences) - } - // Extract URLs from content if not already captured if (bookmark.content) { const urlRegex = /(https?:\/\/[^\s]+)/g @@ -39,6 +34,11 @@ export function deriveLinksFromBookmarks(bookmarks: Bookmark[]): ReadItem[] { } } + // Extract metadata from tags (for web bookmarks and other types) + const title = bookmark.tags.find(t => t[0] === 'title')?.[1] + const summary = bookmark.tags.find(t => t[0] === 'summary')?.[1] + const image = bookmark.tags.find(t => t[0] === 'image')?.[1] + // Create ReadItem for each unique URL for (const url of [...new Set(urls)]) { if (!linksMap.has(url)) { @@ -47,9 +47,9 @@ export function deriveLinksFromBookmarks(bookmarks: Bookmark[]): ReadItem[] { source: 'bookmark', type: 'external', url, - title: bookmark.title || fallbackTitleFromUrl(url), - summary: bookmark.summary, - image: bookmark.image, + title: title || fallbackTitleFromUrl(url), + summary, + image, readingProgress: 0, readingTimestamp: bookmark.added_at || bookmark.created_at }