From 657f0e428ab08cbdeaa9e8713a0b6c433863b0ea Mon Sep 17 00:00:00 2001 From: kashaf-ansari-dev Date: Wed, 3 Jun 2026 01:46:56 +0500 Subject: [PATCH 1/4] mobile: display monograph view count Signed-off-by: kashaf-ansari-dev --- .../app/components/sheets/publish-note/index.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/mobile/app/components/sheets/publish-note/index.tsx b/apps/mobile/app/components/sheets/publish-note/index.tsx index 22f2dbfae..106d3b1a1 100644 --- a/apps/mobile/app/components/sheets/publish-note/index.tsx +++ b/apps/mobile/app/components/sheets/publish-note/index.tsx @@ -168,6 +168,14 @@ const PublishNoteSheet = ({ setPublishLoading(false); }; + const analytics = useAsync(async () => { + if (!isFeatureAvailable?.isAllowed || !monograph) { + return { totalViews: 0 }; + } + + return await db.monographs.analytics(monograph.id); + }, [monograph?.id, isFeatureAvailable?.isAllowed]); + return ( {strings.views()} + + + {analytics.result?.totalViews} + From 4256003e1cff7c6fb21fd0732cc6bf3e0181f331 Mon Sep 17 00:00:00 2001 From: kashaf-ansari-dev Date: Thu, 4 Jun 2026 07:17:03 +0500 Subject: [PATCH 2/4] mobile: refresh monograph analytics on app foreground Signed-off-by: kashaf-ansari-dev --- .../app/components/sheets/publish-note/index.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/mobile/app/components/sheets/publish-note/index.tsx b/apps/mobile/app/components/sheets/publish-note/index.tsx index 106d3b1a1..c4435e1d6 100644 --- a/apps/mobile/app/components/sheets/publish-note/index.tsx +++ b/apps/mobile/app/components/sheets/publish-note/index.tsx @@ -54,6 +54,7 @@ import FormInput, { createFormRef, validators } from "../../ui/input/form-input"; +import { useAppState } from "../../../../app/hooks/use-app-state"; async function fetchMonographData(noteId: string) { const monographId = db.monographs.monograph(noteId); @@ -87,6 +88,8 @@ const PublishNoteSheet = ({ const monograph = monographData.result?.monograph; const publishUrl = monograph && `${hosts.MONOGRAPH_HOST}/${monograph?.id}`; const isPublished = db.monographs.monograph(note?.id); + const appState = useAppState(); + const previousAppState = useRef(appState); const formRef = useRef( createFormRef({ @@ -176,6 +179,15 @@ const PublishNoteSheet = ({ return await db.monographs.analytics(monograph.id); }, [monograph?.id, isFeatureAvailable?.isAllowed]); + useEffect(() => { + const prevState = previousAppState.current; + previousAppState.current = appState; + + if (appState === "active" && prevState !== "active" && monograph?.id) { + analytics.execute(); + } + }, [appState, monograph?.id]); + return ( Date: Fri, 5 Jun 2026 12:25:54 +0500 Subject: [PATCH 3/4] mobile: fix monograpghs analytics fetch and display conditions Signed-off-by: kashaf-ansari-dev --- .../components/sheets/publish-note/index.tsx | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/apps/mobile/app/components/sheets/publish-note/index.tsx b/apps/mobile/app/components/sheets/publish-note/index.tsx index c4435e1d6..d8ca896fd 100644 --- a/apps/mobile/app/components/sheets/publish-note/index.tsx +++ b/apps/mobile/app/components/sheets/publish-note/index.tsx @@ -172,21 +172,25 @@ const PublishNoteSheet = ({ }; const analytics = useAsync(async () => { - if (!isFeatureAvailable?.isAllowed || !monograph) { - return { totalViews: 0 }; - } - + if (!isFeatureAvailable?.isAllowed || !monograph?.id || selfDestruct) + return null; return await db.monographs.analytics(monograph.id); - }, [monograph?.id, isFeatureAvailable?.isAllowed]); + }, [monograph?.id, isFeatureAvailable?.isAllowed, selfDestruct]); useEffect(() => { const prevState = previousAppState.current; previousAppState.current = appState; - if (appState === "active" && prevState !== "active" && monograph?.id) { + if ( + appState === "active" && + prevState !== "active" && + isFeatureAvailable?.isAllowed && + monograph?.id && + !selfDestruct + ) { analytics.execute(); } - }, [appState, monograph?.id]); + }, [appState, monograph?.id, selfDestruct, isFeatureAvailable?.isAllowed]); return ( - {isFeatureAvailable?.isAllowed ? ( + {isFeatureAvailable?.isAllowed && + !selfDestruct && + analytics?.result && + analytics?.result?.totalViews > 0 ? ( Date: Tue, 9 Jun 2026 20:09:09 +0500 Subject: [PATCH 4/4] mobile: prevent UI jerk on analytics refresh after app resume Signed-off-by: kashaf-ansari-dev --- .../app/components/sheets/publish-note/index.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/mobile/app/components/sheets/publish-note/index.tsx b/apps/mobile/app/components/sheets/publish-note/index.tsx index d8ca896fd..59559c047 100644 --- a/apps/mobile/app/components/sheets/publish-note/index.tsx +++ b/apps/mobile/app/components/sheets/publish-note/index.tsx @@ -171,12 +171,20 @@ const PublishNoteSheet = ({ setPublishLoading(false); }; + const lastAnalyticsResult = useRef + > | null>(null); + const analytics = useAsync(async () => { if (!isFeatureAvailable?.isAllowed || !monograph?.id || selfDestruct) return null; - return await db.monographs.analytics(monograph.id); + const result = await db.monographs.analytics(monograph.id); + if (result) lastAnalyticsResult.current = result; + return result; }, [monograph?.id, isFeatureAvailable?.isAllowed, selfDestruct]); + const analyticsData = analytics.result ?? lastAnalyticsResult.current; + useEffect(() => { const prevState = previousAppState.current; previousAppState.current = appState; @@ -398,8 +406,8 @@ const PublishNoteSheet = ({ {isFeatureAvailable?.isAllowed && !selfDestruct && - analytics?.result && - analytics?.result?.totalViews > 0 ? ( + analyticsData && + analyticsData?.totalViews > 0 ? ( {strings.views()} - {analytics.result?.totalViews} + {analyticsData?.totalViews}