mirror of
https://github.com/dergigi/boris.git
synced 2026-01-30 20:24:27 +01:00
refactor: simplify reads - use readingProgressController directly
Removed the complex readsController wrapper. Now /me/reads simply: 1. Uses readingProgressController (already loaded in App.tsx) 2. Converts progress map to ReadItems 3. Subscribes to progress updates This is much simpler and DRY - no need for a separate controller. Reading progress is already deduped and managed centrally. Same approach as debug page - just use the data source directly.
This commit is contained in:
@@ -30,7 +30,6 @@ import ReadingProgressFilters, { ReadingProgressFilterType } from './ReadingProg
|
||||
import { filterByReadingProgress } from '../utils/readingProgressUtils'
|
||||
import { deriveLinksFromBookmarks } from '../utils/linksFromBookmarks'
|
||||
import { readingProgressController } from '../services/readingProgressController'
|
||||
import { readsController } from '../services/readsController'
|
||||
|
||||
interface MeProps {
|
||||
relayPool: RelayPool
|
||||
@@ -231,7 +230,23 @@ const Me: React.FC<MeProps> = ({
|
||||
try {
|
||||
if (!hasBeenLoaded) setLoading(true)
|
||||
|
||||
// Reads come from centralized loading in App.tsx
|
||||
// Reads come from centralized readingProgressController (already loaded in App.tsx)
|
||||
// It provides deduped reading progress per article
|
||||
const progressMap = readingProgressController.getProgressMap()
|
||||
|
||||
// Convert progress map to ReadItems
|
||||
const readItems: ReadItem[] = Array.from(progressMap.entries()).map(([id, progress]) => ({
|
||||
id,
|
||||
source: 'reading-progress',
|
||||
type: 'article',
|
||||
readingProgress: progress,
|
||||
readingTimestamp: Math.floor(Date.now() / 1000)
|
||||
}))
|
||||
|
||||
const readsMap = new Map(readItems.map(item => [item.id, item]))
|
||||
setReadsMap(readsMap)
|
||||
setReads(readItems)
|
||||
|
||||
setLoadedTabs(prev => new Set(prev).add('reads'))
|
||||
if (!hasBeenLoaded) setLoading(false)
|
||||
|
||||
@@ -241,23 +256,24 @@ const Me: React.FC<MeProps> = ({
|
||||
}
|
||||
}
|
||||
|
||||
// Subscribe to reads controller updates
|
||||
// Subscribe to reading progress updates
|
||||
useEffect(() => {
|
||||
const unsubReads = readsController.onReads((reads) => {
|
||||
const readsMap = new Map(reads.map(item => [item.id, item]))
|
||||
const unsubProgress = readingProgressController.onProgress((progressMap) => {
|
||||
const readItems: ReadItem[] = Array.from(progressMap.entries()).map(([id, progress]) => ({
|
||||
id,
|
||||
source: 'reading-progress',
|
||||
type: 'article',
|
||||
readingProgress: progress,
|
||||
readingTimestamp: Math.floor(Date.now() / 1000)
|
||||
}))
|
||||
|
||||
const readsMap = new Map(readItems.map(item => [item.id, item]))
|
||||
setReadsMap(readsMap)
|
||||
setReads(reads)
|
||||
})
|
||||
|
||||
const unsubLoading = readsController.onLoading((loading) => {
|
||||
if (loading === false) {
|
||||
setLoading(false)
|
||||
}
|
||||
setReads(readItems)
|
||||
})
|
||||
|
||||
return () => {
|
||||
unsubReads()
|
||||
unsubLoading()
|
||||
unsubProgress()
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user