Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: refresh monograph analytics on app foreground

kashaf-ansari-dev4256003e1cff
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 (
<View
style={{