mirror of
https://github.com/dergigi/boris.git
synced 2026-02-16 12:34:41 +01:00
- Create readingProgressUtils.ts with filterByReadingProgress function - Create readingDataProcessor.ts with shared processing functions: - processReadingPositions - processMarkedAsRead - filterValidItems - sortByReadingActivity - Refactor readsService.ts to use shared utilities - Refactor linksService.ts to use shared utilities - Eliminate 100+ lines of duplicated code - Simplify Me.tsx filter logic to 2 lines Benefits: - Single source of truth for reading progress filtering - Easier to maintain and modify - Less code duplication across services - More testable with isolated utility functions
31 lines
823 B
TypeScript
31 lines
823 B
TypeScript
import { ReadItem } from '../services/readsService'
|
|
import { ReadingProgressFilterType } from '../components/ReadingProgressFilters'
|
|
|
|
/**
|
|
* Filters ReadItems by reading progress
|
|
*/
|
|
export function filterByReadingProgress(
|
|
items: ReadItem[],
|
|
filter: ReadingProgressFilterType
|
|
): ReadItem[] {
|
|
return items.filter((item) => {
|
|
const progress = item.readingProgress || 0
|
|
const isMarked = item.markedAsRead || false
|
|
|
|
switch (filter) {
|
|
case 'unopened':
|
|
return progress === 0 && !isMarked
|
|
case 'started':
|
|
return progress > 0 && progress <= 0.10 && !isMarked
|
|
case 'reading':
|
|
return progress > 0.10 && progress <= 0.94 && !isMarked
|
|
case 'completed':
|
|
return progress >= 0.95 || isMarked
|
|
case 'all':
|
|
default:
|
|
return true
|
|
}
|
|
})
|
|
}
|
|
|