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
This commit is contained in:
Gigi
2025-10-16 09:36:17 +02:00
parent ed17a68986
commit 5f6a414953
4 changed files with 16 additions and 38 deletions

View File

@@ -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<MeProps> = ({ relayPool, activeTab: propActiveTab, pubkey: propPubkey }) => {
const activeAccount = Hooks.useActiveAccount()
const navigate = useNavigate()
@@ -53,9 +56,9 @@ const Me: React.FC<MeProps> = ({ relayPool, activeTab: propActiveTab, pubkey: pr
const [highlights, setHighlights] = useState<Highlight[]>([])
const [bookmarks, setBookmarks] = useState<Bookmark[]>([])
const [reads, setReads] = useState<ReadItem[]>([])
const [readsMap, setReadsMap] = useState<Map<string, ReadItem>>(new Map())
const [, setReadsMap] = useState<Map<string, ReadItem>>(new Map())
const [links, setLinks] = useState<ReadItem[]>([])
const [linksMap, setLinksMap] = useState<Map<string, ReadItem>>(new Map())
const [, setLinksMap] = useState<Map<string, ReadItem>>(new Map())
const [writings, setWritings] = useState<BlogPostPreview[]>([])
const [loading, setLoading] = useState(true)
const [loadedTabs, setLoadedTabs] = useState<Set<TabType>>(new Set())
@@ -64,8 +67,7 @@ const Me: React.FC<MeProps> = ({ relayPool, activeTab: propActiveTab, pubkey: pr
const [bookmarkFilter, setBookmarkFilter] = useState<BookmarkFilterType>('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<ReadingProgressFilterType>(initialFilter)
@@ -79,7 +81,7 @@ const Me: React.FC<MeProps> = ({ 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)

View File

@@ -22,7 +22,6 @@ export const ReadingProgressIndicator: React.FC<ReadingProgressIndicatorProps> =
// 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 = ''

View File

@@ -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
}

View File

@@ -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
}