From 5c82dff8df122a32d10c2fd20d689c77547a225a Mon Sep 17 00:00:00 2001 From: Gigi Date: Sun, 19 Oct 2025 22:13:37 +0200 Subject: [PATCH] feat: only track reading progress for articles above minimum length MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add MIN_CONTENT_LENGTH constant (1000 chars ≈ 150 words) to config/kinds - Create shouldTrackReadingProgress helper to validate content length - Strip HTML tags when calculating character count - Only save reading progress for articles meeting the threshold - Log when content is too short to track This prevents noisy tracking of very short articles or excerpts. --- src/components/ContentPanel.tsx | 10 ++++++++-- src/config/kinds.ts | 6 ++++++ src/utils/helpers.ts | 12 ++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/components/ContentPanel.tsx b/src/components/ContentPanel.tsx index c79bd2f3..62afbc86 100644 --- a/src/components/ContentPanel.tsx +++ b/src/components/ContentPanel.tsx @@ -32,7 +32,7 @@ import { import AuthorCard from './AuthorCard' import { faBooks } from '../icons/customIcons' import { extractYouTubeId, getYouTubeMeta } from '../services/youtubeMetaService' -import { classifyUrl } from '../utils/helpers' +import { classifyUrl, shouldTrackReadingProgress } from '../utils/helpers' import { buildNativeVideoUrl } from '../utils/videoHelpers' import { useReadingPosition } from '../hooks/useReadingPosition' import { ReadingProgressIndicator } from './ReadingProgressIndicator' @@ -163,6 +163,12 @@ const ContentPanel: React.FC = ({ console.log('[progress] ⏭️ ContentPanel: Sync disabled in settings') return } + + // Check if content is long enough to track reading progress + if (!shouldTrackReadingProgress(html, markdown)) { + console.log('[progress] ⏭️ ContentPanel: Content too short to track reading progress') + return + } const scrollTop = window.pageYOffset || document.documentElement.scrollTop console.log('[progress] 💾 ContentPanel: Saving position:', { @@ -190,7 +196,7 @@ const ContentPanel: React.FC = ({ } catch (error) { console.error('[progress] ❌ ContentPanel: Failed to save reading position:', error) } - }, [activeAccount, relayPool, eventStore, articleIdentifier, settings?.syncReadingPosition, selectedUrl]) + }, [activeAccount, relayPool, eventStore, articleIdentifier, settings?.syncReadingPosition, selectedUrl, html, markdown]) const { isReadingComplete, progressPercentage, saveNow } = useReadingPosition({ enabled: isTextContent, diff --git a/src/config/kinds.ts b/src/config/kinds.ts index d8e6e9d8..99c035d4 100644 --- a/src/config/kinds.ts +++ b/src/config/kinds.ts @@ -14,3 +14,9 @@ export const KINDS = { export type KindValue = typeof KINDS[keyof typeof KINDS] +// Reading progress tracking configuration +export const READING_PROGRESS = { + // Minimum character count to track reading progress (roughly 150 words) + MIN_CONTENT_LENGTH: 1000 +} as const + diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index b3fcafa4..29de11d9 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -123,3 +123,15 @@ export function createParallelReqStreams( return { local$, remote$ } } +/** + * Checks if content is long enough to track reading progress + * Minimum 1000 characters (roughly 150 words) + */ +export const shouldTrackReadingProgress = (html: string | undefined, markdown: string | undefined): boolean => { + const { READING_PROGRESS } = require('../config/kinds') + const content = (html || markdown || '').trim() + // Strip HTML tags to get character count + const plainText = content.replace(/<[^>]*>/g, '').trim() + return plainText.length >= READING_PROGRESS.MIN_CONTENT_LENGTH +} +