fix sync toast messages

This commit is contained in:
ammarahm-ed
2020-12-12 11:13:46 +05:00
parent 8576673b09
commit 0bbcbbd9d2
3 changed files with 38 additions and 49 deletions

View File

@@ -454,37 +454,31 @@ export const ActionSheetComponent = ({
) : null; ) : null;
const onPressSync = async () => { const onPressSync = async () => {
let user = await db.user.get(); setRefreshing(true);
if (!user) { try {
ToastEvent.show( await db.sync();
'You must login to sync', localRefresh();
'error', ToastEvent.show('Sync Complete!', 'success', 'local');
'local', } catch (e) {
5000, if (e.message === 'You need to login to sync.') {
() => { ToastEvent.show(
close(); e.message,
setTimeout(() => { 'error',
'local',
5000,
() => {
eSendEvent(eOpenLoginDialog); eSendEvent(eOpenLoginDialog);
}, 500); },
}, 'Login',
'Login', );
); } else {
return; ToastEvent.show(e.message, 'error', 'local', 5000);
}
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);
} }
} finally {
let user = await db.user.get();
dispatch({type: Actions.USER, user: user});
dispatch({type: Actions.ALL});
setRefreshing(false);
} }
}; };

View File

@@ -23,7 +23,7 @@ export const UserSection = ({noTextMode}) => {
borderRadius: 5, borderRadius: 5,
alignSelf: 'center', alignSelf: 'center',
backgroundColor: colors.shade, backgroundColor: colors.shade,
marginTop:10, marginTop: 10,
}}> }}>
<View <View
style={{ style={{
@@ -52,22 +52,19 @@ export const UserSection = ({noTextMode}) => {
syncing: true, syncing: true,
}); });
try { try {
if (!user) {
let u = await db.user.get();
dispatch({type: Actions.USER, user: u});
}
await db.sync(); await db.sync();
ToastEvent.show('Sync Complete', 'success'); ToastEvent.show('Sync Complete', 'success');
} catch (e) { } catch (e) {
ToastEvent.show(e.message, 'error'); 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={{ style={{
flexDirection: 'row', flexDirection: 'row',

View File

@@ -126,17 +126,13 @@ const SimpleList = ({
} else { } else {
setRefreshing(true); setRefreshing(true);
} }
let user;
try { try {
user = await db.user.get();
dispatch({type: Actions.USER, user: user});
await db.sync(); await db.sync();
ToastEvent.show('Sync Complete', 'success'); ToastEvent.show('Sync Complete', 'success');
} catch (e) { } catch (e) {
if (!user) { if (e.message === 'You need to login to sync.') {
ToastEvent.show( ToastEvent.show(
'You must login to sync.', e.message,
'error', 'error',
'global', 'global',
5000, 5000,
@@ -146,7 +142,7 @@ const SimpleList = ({
'Login', 'Login',
); );
} else { } else {
ToastEvent.show(e.message, 'error', 'global', 3000); ToastEvent.show(e.message, 'error', 'global', 5000);
} }
} finally { } finally {
if (Platform.OS === 'ios') { if (Platform.OS === 'ios') {
@@ -160,8 +156,10 @@ const SimpleList = ({
if (refreshCallback) { if (refreshCallback) {
refreshCallback(); refreshCallback();
} }
let user = await db.user.get();
dispatch({type: Actions.USER, user: user});
dispatch({type: Actions.ALL});
} }
dispatch({type: Actions.ALL});
}, []); }, []);
const _ListEmptyComponent = ( const _ListEmptyComponent = (