mirror of
https://github.com/dergigi/boris.git
synced 2026-01-23 16:54:33 +01:00
feat: add highlights filter button to reading progress filters
- Add 'highlighted' filter type to ReadingProgressFilterType - New filter button with yellow highlighter icon - Filter shows only articles that have highlights - Highlights filter checks both eventReference and urlReference tags - Color-coded: green for completed, yellow for highlighted, blue for others - Applies to reads and links tabs in /me page
This commit is contained in:
@@ -1,16 +1,35 @@
|
||||
import { ReadItem } from '../services/readsService'
|
||||
import { ReadingProgressFilterType } from '../components/ReadingProgressFilters'
|
||||
import { Highlight } from '../types/highlights'
|
||||
|
||||
/**
|
||||
* Filters ReadItems by reading progress
|
||||
*/
|
||||
export function filterByReadingProgress(
|
||||
items: ReadItem[],
|
||||
filter: ReadingProgressFilterType
|
||||
filter: ReadingProgressFilterType,
|
||||
highlights?: Highlight[]
|
||||
): ReadItem[] {
|
||||
// Build a map of article references to highlight count
|
||||
const articleHighlightCount = new Map<string, number>()
|
||||
if (highlights) {
|
||||
highlights.forEach(h => {
|
||||
if (h.eventReference) {
|
||||
const count = articleHighlightCount.get(h.eventReference) || 0
|
||||
articleHighlightCount.set(h.eventReference, count + 1)
|
||||
}
|
||||
if (h.urlReference) {
|
||||
const count = articleHighlightCount.get(h.urlReference) || 0
|
||||
articleHighlightCount.set(h.urlReference, count + 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return items.filter((item) => {
|
||||
const progress = item.readingProgress || 0
|
||||
const isMarked = item.markedAsRead || false
|
||||
const hasHighlights = (articleHighlightCount.get(item.id) || 0) > 0 ||
|
||||
(item.url && (articleHighlightCount.get(item.url) || 0) > 0)
|
||||
|
||||
switch (filter) {
|
||||
case 'unopened':
|
||||
@@ -21,6 +40,8 @@ export function filterByReadingProgress(
|
||||
return progress > 0.10 && progress <= 0.94 && !isMarked
|
||||
case 'completed':
|
||||
return progress >= 0.95 || isMarked
|
||||
case 'highlighted':
|
||||
return hasHighlights
|
||||
case 'all':
|
||||
default:
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user