Skip to content

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

mobile: fix monograpghs analytics fetch and display conditions

kashaf-ansari-devcdef17eb8d15
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 (
<View
@@ -392,7 +396,10 @@ const PublishNoteSheet = ({
</View>
</TouchableOpacity>
- {isFeatureAvailable?.isAllowed ? (
+ {isFeatureAvailable?.isAllowed &&
+ !selfDestruct &&
+ analytics?.result &&
+ analytics?.result?.totalViews > 0 ? (
<View
style={{
flexDirection: "row",