Skip to content

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

fix sync toast messages

ammarahm-ed0bbcbbd9d2da
diff --git a/apps/mobile/src/components/ActionSheetComponent/index.js b/apps/mobile/src/components/ActionSheetComponent/index.js
index 28cb457b6..7f2c7f465 100644
--- a/apps/mobile/src/components/ActionSheetComponent/index.js
+++ b/apps/mobile/src/components/ActionSheetComponent/index.js
@@ -454,37 +454,31 @@ export const ActionSheetComponent = ({
) : null;
const onPressSync = async () => {
- let user = await db.user.get();
- if (!user) {
- ToastEvent.show(
- 'You must login to sync',
- 'error',
- 'local',
- 5000,
- () => {
- close();
- setTimeout(() => {
+ setRefreshing(true);
+ try {
+ await db.sync();
+ localRefresh();
+ ToastEvent.show('Sync Complete!', 'success', 'local');
+ } catch (e) {
+ if (e.message === 'You need to login to sync.') {
+ ToastEvent.show(
+ e.message,
+ 'error',
+ 'local',
+ 5000,
+ () => {
eSendEvent(eOpenLoginDialog);
- }, 500);
- },
- 'Login',
- );
- return;
- }
- if (user?.lastSynced < note?.dateEdited || !user.lastSynced) {
- setRefreshing(true);
- try {
- await db.sync();
- localRefresh();
- ToastEvent.show('Note synced', 'success', 'local');
- } catch (e) {
- ToastEvent.show(e.message, 'error', 'local');
- } finally {
- let user = await db.user.get();
- dispatch({type: Actions.USER, user: user});
- dispatch({type: Actions.ALL});
- setRefreshing(false);
+ },
+ 'Login',
+ );
+ } else {
+ ToastEvent.show(e.message, 'error', 'local', 5000);
}
+ } finally {
+ let user = await db.user.get();
+ dispatch({type: Actions.USER, user: user});
+ dispatch({type: Actions.ALL});
+ setRefreshing(false);
}
};
diff --git a/apps/mobile/src/components/Menu/UserSection.js b/apps/mobile/src/components/Menu/UserSection.js
index 71e07312e..4e050e333 100644
--- a/apps/mobile/src/components/Menu/UserSection.js
+++ b/apps/mobile/src/components/Menu/UserSection.js
@@ -23,7 +23,7 @@ export const UserSection = ({noTextMode}) => {
borderRadius: 5,
alignSelf: 'center',
backgroundColor: colors.shade,
- marginTop:10,
+ marginTop: 10,
}}>
<View
style={{
@@ -52,22 +52,19 @@ export const UserSection = ({noTextMode}) => {
syncing: true,
});
try {
- if (!user) {
- let u = await db.user.get();
- dispatch({type: Actions.USER, user: u});
- }
await db.sync();
ToastEvent.show('Sync Complete', 'success');
} catch (e) {
ToastEvent.show(e.message, 'error');
+ } finally {
+ let user = await db.user.get();
+ dispatch({type: Actions.USER, user: user});
+ dispatch({type: Actions.ALL});
+ dispatch({
+ type: Actions.SYNCING,
+ syncing: false,
+ });
}
- let u = await db.user.get();
- dispatch({type: Actions.USER, user: u});
- dispatch({type: Actions.ALL});
- dispatch({
- type: Actions.SYNCING,
- syncing: false,
- });
}}
style={{
flexDirection: 'row',
diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.js
index 9e81e87ef..6c3c5cd4d 100644
--- a/apps/mobile/src/components/SimpleList/index.js
+++ b/apps/mobile/src/components/SimpleList/index.js
@@ -126,17 +126,13 @@ const SimpleList = ({
} else {
setRefreshing(true);
}
- let user;
try {
- user = await db.user.get();
- dispatch({type: Actions.USER, user: user});
await db.sync();
-
ToastEvent.show('Sync Complete', 'success');
} catch (e) {
- if (!user) {
+ if (e.message === 'You need to login to sync.') {
ToastEvent.show(
- 'You must login to sync.',
+ e.message,
'error',
'global',
5000,
@@ -146,7 +142,7 @@ const SimpleList = ({
'Login',
);
} else {
- ToastEvent.show(e.message, 'error', 'global', 3000);
+ ToastEvent.show(e.message, 'error', 'global', 5000);
}
} finally {
if (Platform.OS === 'ios') {
@@ -160,8 +156,10 @@ const SimpleList = ({
if (refreshCallback) {
refreshCallback();
}
+ let user = await db.user.get();
+ dispatch({type: Actions.USER, user: user});
+ dispatch({type: Actions.ALL});
}
- dispatch({type: Actions.ALL});
}, []);
const _ListEmptyComponent = (