Skip to content

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

mobile: improve sync status UX

ammarahm-ede34114a3c4bc
diff --git a/apps/mobile/app/app.js b/apps/mobile/app/app.js
index 69264a0f7..00ac551f7 100644
--- a/apps/mobile/app/app.js
+++ b/apps/mobile/app/app.js
@@ -31,6 +31,15 @@ import { TipManager } from "./services/tip-manager";
import { useUserStore } from "./stores/use-user-store";
import { View } from "react-native";
import { useState } from "react";
+import NetInfo from "@react-native-community/netinfo";
+
+NetInfo.configure({
+ reachabilityUrl: "https://notesnook.com",
+ reachabilityTest: (response) => {
+ if (!response) return false;
+ return response?.status >= 200 && response?.status < 300;
+ }
+});
SettingsService.init();
SettingsService.checkOrientation();
diff --git a/apps/mobile/app/components/side-menu/user-status.js b/apps/mobile/app/components/side-menu/user-status.js
index 2536caf5b..97bec7f69 100644
--- a/apps/mobile/app/components/side-menu/user-status.js
+++ b/apps/mobile/app/components/side-menu/user-status.js
@@ -25,7 +25,7 @@ import useSyncProgress from "../../hooks/use-sync-progress";
import { eSendEvent } from "../../services/event-manager";
import Sync from "../../services/sync";
import { useThemeStore } from "../../stores/use-theme-store";
-import { useUserStore } from "../../stores/use-user-store";
+import { SyncStatus, useUserStore } from "../../stores/use-user-store";
import { eOpenLoginDialog } from "../../utils/events";
import { tabBarRef } from "../../utils/global-refs";
import { SIZE } from "../../utils/size";
@@ -33,12 +33,16 @@ import { PressableButton } from "../ui/pressable";
import { TimeSince } from "../ui/time-since";
import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph";
+import { useNetInfo } from "@react-native-community/netinfo";
export const UserStatus = () => {
const colors = useThemeStore((state) => state.colors);
const user = useUserStore((state) => state.user);
const syncing = useUserStore((state) => state.syncing);
+ const lastSyncStatus = useUserStore((state) => state.lastSyncStatus);
const lastSynced = useUserStore((state) => state.lastSynced);
const insets = useGlobalSafeAreaInsets();
+ const { isInternetReachable } = useNetInfo();
+ const isOffline = !isInternetReachable;
const { progress } = useSyncProgress();
return (
<View
@@ -90,27 +94,29 @@ export const UserStatus = () => {
>
{!user ? (
"You are not logged in"
- ) : !syncing ? (
- lastSynced && lastSynced !== "Never" ? (
- <>
- Last synced{" "}
- <TimeSince
- style={{ fontSize: SIZE.xs, color: colors.icon }}
- time={lastSynced}
- />
- </>
- ) : (
- "never"
- )
+ ) : lastSynced && lastSynced !== "Never" ? (
+ <>
+ Synced{" "}
+ <TimeSince
+ style={{ fontSize: SIZE.xs, color: colors.icon }}
+ time={lastSynced}
+ bold={true}
+ />
+ {isOffline ? " (offline)" : ""}
+ </>
) : (
- `Syncing your notes${
- progress ? ` (${progress.current}/${progress.total})` : ""
- }`
+ "never"
)}{" "}
<Icon
name="checkbox-blank-circle"
- size={9}
- color={!user ? colors.red : colors.green}
+ size={11}
+ color={
+ !user || lastSyncStatus === SyncStatus.Failed
+ ? colors.red
+ : isOffline
+ ? colors.orange
+ : colors.green
+ }
/>
</Heading>
@@ -122,15 +128,21 @@ export const UserStatus = () => {
>
{!user
? "Login to sync your notes."
+ : lastSyncStatus === SyncStatus.Failed
+ ? "Last sync failed, tap to try again"
+ : syncing
+ ? `Syncing your notes${
+ progress ? ` (${progress.current}/${progress.total})` : ""
+ }`
: "Tap here to sync your notes."}
</Paragraph>
</View>
{user ? (
syncing ? (
- <>
- <ActivityIndicator color={colors.accent} size={SIZE.xl} />
- </>
+ <ActivityIndicator color={colors.accent} size={SIZE.xl} />
+ ) : lastSyncStatus === SyncStatus.Failed ? (
+ <Icon color={colors.red} name="sync-alert" size={SIZE.lg} />
) : (
<Icon color={colors.accent} name="sync" size={SIZE.lg} />
)
diff --git a/apps/mobile/app/components/ui/time-since/index.tsx b/apps/mobile/app/components/ui/time-since/index.tsx
index 44604fd21..470fe9d32 100644
--- a/apps/mobile/app/components/ui/time-since/index.tsx
+++ b/apps/mobile/app/components/ui/time-since/index.tsx
@@ -20,16 +20,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import React, { useEffect, useRef, useState } from "react";
import { TextProps } from "react-native";
import { timeSince } from "../../../utils/time";
+import Heading from "../typography/heading";
import Paragraph from "../typography/paragraph";
interface TimeSinceProps extends TextProps {
updateFrequency: number;
time: number;
+ bold?: boolean
}
export const TimeSince = ({
time,
style,
- updateFrequency = 30000
+ updateFrequency = 30000,
+ bold
}: TimeSinceProps) => {
const [timeAgo, setTimeAgo] = useState<string | null>(null);
const interval = useRef<NodeJS.Timer>();
@@ -46,5 +49,9 @@ export const TimeSince = ({
};
}, [time, updateFrequency]);
- return <Paragraph style={style}>{timeAgo}</Paragraph>;
+ return bold ? (
+ <Heading style={style}>{timeAgo}</Heading>
+ ) : (
+ <Paragraph style={style}>{timeAgo}</Paragraph>
+ );
};
diff --git a/apps/mobile/app/hooks/use-app-events.js b/apps/mobile/app/hooks/use-app-events.js
index b4ffe2eea..dfdfe62eb 100644
--- a/apps/mobile/app/hooks/use-app-events.js
+++ b/apps/mobile/app/hooks/use-app-events.js
@@ -51,7 +51,7 @@ import {
} from "../utils/events";
import Sync from "../services/sync";
import { initAfterSync } from "../stores";
-import { useUserStore } from "../stores/use-user-store";
+import { SyncStatus, useUserStore } from "../stores/use-user-store";
import { useMessageStore } from "../stores/use-message-store";
import { useSettingStore } from "../stores/use-setting-store";
import { useAttachmentStore } from "../stores/use-attachment-store";
@@ -142,6 +142,11 @@ export const useAppEvents = () => {
}
}, []);
+ const onSyncAborted = useCallback((error) => {
+ useUserStore.getState().setSyncing(false, SyncStatus.Failed);
+ if (error) ToastEvent.error(new Error(error));
+ }, []);
+
useEffect(() => {
let subs = [
Appearance.addChangeListener(SettingsService.setTheme),
@@ -153,7 +158,7 @@ export const useAppEvents = () => {
];
EV.subscribe(EVENTS.syncCheckStatus, onSyncStatusCheck);
-
+ EV.subscribe(EVENTS.syncAborted, onSyncAborted);
EV.subscribe(EVENTS.appRefreshRequested, onSyncComplete);
EV.subscribe(EVENTS.userLoggedOut, onLogout);
EV.subscribe(EVENTS.userEmailConfirmed, onEmailVerified);
@@ -167,7 +172,7 @@ export const useAppEvents = () => {
eUnSubscribeEvent("userLoggedIn", onUserUpdated);
EV.unsubscribe(EVENTS.syncCheckStatus, onSyncStatusCheck);
-
+ EV.unsubscribe(EVENTS.syncAborted, onSyncAborted);
EV.unsubscribe(EVENTS.appRefreshRequested, onSyncComplete);
EV.unsubscribe(EVENTS.userSessionExpired, onSessionExpired);
EV.unsubscribe(EVENTS.userLoggedOut, onLogout);
@@ -184,7 +189,8 @@ export const useAppEvents = () => {
onSyncComplete,
onSyncStatusCheck,
onUrlRecieved,
- onUserUpdated
+ onUserUpdated,
+ onSyncAborted
]);
const onSessionExpired = async () => {
@@ -513,6 +519,9 @@ export const useAppEvents = () => {
let user = await db.user.getUser();
if (user && state.isConnected && state.isInternetReachable) {
await db.connectSSE();
+ } else {
+ useUserStore.getState().setSyncing(false);
+ await db.syncer.stop();
}
refValues.current.isReconnecting = false;
} catch (e) {
diff --git a/apps/mobile/app/services/sync.js b/apps/mobile/app/services/sync.js
index 4ac0f7c73..fd4a317e6 100644
--- a/apps/mobile/app/services/sync.js
+++ b/apps/mobile/app/services/sync.js
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import NetInfo from "@react-native-community/netinfo";
import { EVENTS } from "@notesnook/core/common";
import { initAfterSync } from "../stores/index";
-import { useUserStore } from "../stores/use-user-store";
+import { SyncStatus, useUserStore } from "../stores/use-user-store";
import { doInBackground } from "../utils";
import { db } from "../common/database";
import { DatabaseLogger } from "../common/database/index";
@@ -80,18 +80,19 @@ const run = async (
});
if (!res) {
initAfterSync();
- userstore.setSyncing(false);
+ userstore.setSyncing(false, SyncStatus.Failed);
return onCompleted?.(false);
}
if (typeof res === "string") throw error;
userstore.setSyncing(false);
return onCompleted?.(true);
} catch (e) {
+ error = e;
if (
!ignoredMessages.find((im) => e.message?.includes(im)) &&
userstore.user
) {
- userstore.setSyncing(false);
+ userstore.setSyncing(false, SyncStatus.Failed);
if (status.isConnected && status.isInternetReachable) {
ToastEvent.error(e, "Sync failed", context);
}
@@ -99,12 +100,15 @@ const run = async (
DatabaseLogger.error(e, "[Client] Failed to sync");
onCompleted?.(false);
} finally {
- userstore.setSyncing(false);
+ userstore.setSyncing(
+ false,
+ error ? SyncStatus.Failed : SyncStatus.Passed
+ );
if (full || forced) {
db.eventManager.publish(EVENTS.syncCompleted);
}
}
- }, 1000);
+ }, 300);
};
const Sync = {
diff --git a/apps/mobile/app/stores/use-user-store.ts b/apps/mobile/app/stores/use-user-store.ts
index 3c4e9e4a3..894bfcf67 100644
--- a/apps/mobile/app/stores/use-user-store.ts
+++ b/apps/mobile/app/stores/use-user-store.ts
@@ -19,14 +19,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import create, { State } from "zustand";
+export enum SyncStatus {
+ Passed,
+ Failed,
+ Never
+}
+
export interface UserStore extends State {
user: User | null | undefined;
premium: boolean;
lastSynced: string;
syncing: boolean;
+ lastSyncStatus: SyncStatus;
setUser: (user: User | null | undefined) => void;
setPremium: (premium: boolean) => void;
- setSyncing: (syncing: boolean) => void;
+ setSyncing: (syncing: boolean, status?: SyncStatus) => void;
setLastSynced: (lastSynced: string) => void;
verifyUser: boolean;
setVerifyUser: (verified: boolean) => void;
@@ -40,7 +47,9 @@ export const useUserStore = create<UserStore>((set) => ({
verifyUser: false,
setUser: (user) => set({ user: user }),
setPremium: (premium) => set({ premium: premium }),
- setSyncing: (syncing) => set({ syncing: syncing }),
+ setSyncing: (syncing, status = SyncStatus.Passed) =>
+ set({ syncing: syncing, lastSyncStatus: status }),
setLastSynced: (lastSynced) => set({ lastSynced: lastSynced }),
- setVerifyUser: (verified) => set({ verifyUser: verified })
+ setVerifyUser: (verified) => set({ verifyUser: verified }),
+ lastSyncStatus: SyncStatus.Never
}));
diff --git a/apps/mobile/native/package.json b/apps/mobile/native/package.json
index 9cc1770a9..e07365206 100644
--- a/apps/mobile/native/package.json
+++ b/apps/mobile/native/package.json
@@ -8,8 +8,7 @@
"@callstack/repack": "^3.0.0",
"@react-native-clipboard/clipboard": "^1.9.0",
"@react-native-community/checkbox": "^0.5.8",
- "@react-native-community/netinfo": "^6.0.4",
- "@react-native-community/push-notification-ios": "^1.10.1",
+ "@react-native-community/netinfo": "^9.3.7",
"@react-native-community/toolbar-android": "^0.2.1",
"@react-native-masked-view/masked-view": "^0.2.6",
"@react-navigation/elements": "^1.3.3",
@@ -58,7 +57,6 @@
"@react-native-community/datetimepicker":"6.6.0",
"react-native-date-picker": "4.2.6",
"react-native-notification-sounds": "0.5.5"
-
},
"devDependencies": {
"@babel/core": "^7.12.9",
@@ -70,7 +68,6 @@
"@types/html-to-text": "^8.0.1",
"@types/jest": "^27.0.3",
"@types/react-native": "^0.69.1",
- "@types/react-native-push-notification": "^7.3.2",
"@types/react-native-vector-icons": "^6.4.10",
"@types/react-test-renderer": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^5.14.0",
diff --git a/apps/mobile/package-lock.json b/apps/mobile/package-lock.json
index fe2bbfc2c..b8914fd29 100644
--- a/apps/mobile/package-lock.json
+++ b/apps/mobile/package-lock.json
@@ -66,8 +66,7 @@
"@react-native-clipboard/clipboard": "^1.9.0",
"@react-native-community/checkbox": "^0.5.8",
"@react-native-community/datetimepicker": "6.6.0",
- "@react-native-community/netinfo": "^6.0.4",
- "@react-native-community/push-notification-ios": "^1.10.1",
+ "@react-native-community/netinfo": "^9.3.7",
"@react-native-community/toolbar-android": "^0.2.1",
"@react-native-masked-view/masked-view": "^0.2.6",
"@react-navigation/elements": "^1.3.3",
@@ -124,7 +123,6 @@
"@types/html-to-text": "^8.0.1",
"@types/jest": "^27.0.3",
"@types/react-native": "^0.69.1",
- "@types/react-native-push-notification": "^7.3.2",
"@types/react-native-vector-icons": "^6.4.10",
"@types/react-test-renderer": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^5.14.0",
@@ -5474,25 +5472,13 @@
"dev": true
},
"node_modules/@react-native-community/netinfo": {
- "version": "6.2.1",
- "resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-6.2.1.tgz",
- "integrity": "sha512-742sh+NMbPo59MaLRXBWwkT5K6HQPrmoS0pg0z9QuXshXieQIOTkqEEDMkQZS0QnS8fPFr8MxMPw/TAxH9b8Ig==",
+ "version": "9.3.7",
+ "resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-9.3.7.tgz",
+ "integrity": "sha512-+taWmE5WpBp0uS6kf+bouCx/sn89G9EpR4s2M/ReLvctVIFL2Qh8WnWfBxqK9qwgmFha/uqjSr2Gq03OOtiDcw==",
"peerDependencies": {
"react-native": ">=0.59"
}
},
- "node_modules/@react-native-community/push-notification-ios": {
- "version": "1.10.1",
- "resolved": "https://registry.npmjs.org/@react-native-community/push-notification-ios/-/push-notification-ios-1.10.1.tgz",
- "integrity": "sha512-k6bZWUKLif4GjenyTD3aQLwA2VT3bNmt22INO/34lexnpmqkPDZF7nreqbckTHG0Zso9wDTe4N/AZJUC/d8iRg==",
- "dependencies": {
- "invariant": "^2.2.4"
- },
- "peerDependencies": {
- "react": ">=16.6.3",
- "react-native": ">=0.58.4"
- }
- },
"node_modules/@react-native-community/toolbar-android": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/@react-native-community/toolbar-android/-/toolbar-android-0.2.1.tgz",
@@ -5904,12 +5890,6 @@
"@types/react": "*"
}
},
- "node_modules/@types/react-native-push-notification": {
- "version": "7.3.3",
- "resolved": "https://registry.npmjs.org/@types/react-native-push-notification/-/react-native-push-notification-7.3.3.tgz",
- "integrity": "sha512-6LmfaZ0cRuk4oEdBZEJVRZ8DoPHz95fqD7wW3jBbcJFy3U23eSE+MeSQall4BCZFBZDGT1KCEGFCwflTxFEZMw==",
- "dev": true
- },
"node_modules/@types/react-native-vector-icons": {
"version": "6.4.12",
"resolved": "https://registry.npmjs.org/@types/react-native-vector-icons/-/react-native-vector-icons-6.4.12.tgz",
@@ -24342,8 +24322,7 @@
"@react-native-community/checkbox": "^0.5.8",
"@react-native-community/datetimepicker": "6.6.0",
"@react-native-community/eslint-config": "^2.0.0",
- "@react-native-community/netinfo": "^6.0.4",
- "@react-native-community/push-notification-ios": "^1.10.1",
+ "@react-native-community/netinfo": "^9.3.7",
"@react-native-community/toolbar-android": "^0.2.1",
"@react-native-masked-view/masked-view": "^0.2.6",
"@react-navigation/elements": "^1.3.3",
@@ -24354,7 +24333,6 @@
"@types/html-to-text": "^8.0.1",
"@types/jest": "^27.0.3",
"@types/react-native": "^0.69.1",
- "@types/react-native-push-notification": "^7.3.2",
"@types/react-native-vector-icons": "^6.4.10",
"@types/react-test-renderer": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^5.14.0",
@@ -25476,17 +25454,9 @@
"dev": true
},
"@react-native-community/netinfo": {
- "version": "6.2.1",
- "resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-6.2.1.tgz",
- "integrity": "sha512-742sh+NMbPo59MaLRXBWwkT5K6HQPrmoS0pg0z9QuXshXieQIOTkqEEDMkQZS0QnS8fPFr8MxMPw/TAxH9b8Ig=="
- },
- "@react-native-community/push-notification-ios": {
- "version": "1.10.1",
- "resolved": "https://registry.npmjs.org/@react-native-community/push-notification-ios/-/push-notification-ios-1.10.1.tgz",
- "integrity": "sha512-k6bZWUKLif4GjenyTD3aQLwA2VT3bNmt22INO/34lexnpmqkPDZF7nreqbckTHG0Zso9wDTe4N/AZJUC/d8iRg==",
- "requires": {
- "invariant": "^2.2.4"
- }
+ "version": "9.3.7",
+ "resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-9.3.7.tgz",
+ "integrity": "sha512-+taWmE5WpBp0uS6kf+bouCx/sn89G9EpR4s2M/ReLvctVIFL2Qh8WnWfBxqK9qwgmFha/uqjSr2Gq03OOtiDcw=="
},
"@react-native-community/toolbar-android": {
"version": "0.2.1",
@@ -25837,12 +25807,6 @@
"@types/react": "*"
}
},
- "@types/react-native-push-notification": {
- "version": "7.3.3",
- "resolved": "https://registry.npmjs.org/@types/react-native-push-notification/-/react-native-push-notification-7.3.3.tgz",
- "integrity": "sha512-6LmfaZ0cRuk4oEdBZEJVRZ8DoPHz95fqD7wW3jBbcJFy3U23eSE+MeSQall4BCZFBZDGT1KCEGFCwflTxFEZMw==",
- "dev": true
- },
"@types/react-native-vector-icons": {
"version": "6.4.12",
"resolved": "https://registry.npmjs.org/@types/react-native-vector-icons/-/react-native-vector-icons-6.4.12.tgz",