mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
add sync from menu
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
TouchableOpacity,
|
TouchableOpacity,
|
||||||
View,
|
View,
|
||||||
|
ActivityIndicator,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import MMKV from 'react-native-mmkv-storage';
|
import MMKV from 'react-native-mmkv-storage';
|
||||||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||||
@@ -28,7 +29,7 @@ import {ACTIONS} from '../../provider/actions';
|
|||||||
import {eSendEvent} from '../../services/eventManager';
|
import {eSendEvent} from '../../services/eventManager';
|
||||||
import {eClearSearch, eOpenModalMenu} from '../../services/events';
|
import {eClearSearch, eOpenModalMenu} from '../../services/events';
|
||||||
import NavigationService from '../../services/NavigationService';
|
import NavigationService from '../../services/NavigationService';
|
||||||
import {db, DDS, hexToRGBA, timeSince} from '../../utils/utils';
|
import {db, DDS, hexToRGBA, timeSince, ToastEvent} from '../../utils/utils';
|
||||||
import {sideMenuOverlayRef} from '../../utils/refs';
|
import {sideMenuOverlayRef} from '../../utils/refs';
|
||||||
|
|
||||||
export const Menu = ({
|
export const Menu = ({
|
||||||
@@ -38,7 +39,7 @@ export const Menu = ({
|
|||||||
noTextMode = false,
|
noTextMode = false,
|
||||||
}) => {
|
}) => {
|
||||||
const [state, dispatch] = useTracked();
|
const [state, dispatch] = useTracked();
|
||||||
const {colors, tags, colorNotes, user, currentScreen} = state;
|
const {colors, tags, colorNotes, user, currentScreen, syncing} = state;
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
|
|
||||||
@@ -477,7 +478,6 @@ export const Menu = ({
|
|||||||
</View> */}
|
</View> */}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
@@ -595,7 +595,30 @@ export const Menu = ({
|
|||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View
|
<TouchableOpacity
|
||||||
|
onPress={async () => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.SYNCING,
|
||||||
|
syncing: true,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
let user = await db.user.get();
|
||||||
|
dispatch({type: ACTIONS.USER, user: user});
|
||||||
|
await db.sync();
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.SYNCING,
|
||||||
|
syncing: false,
|
||||||
|
});
|
||||||
|
ToastEvent.show('Sync Complete', 'success');
|
||||||
|
} catch (e) {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.SYNCING,
|
||||||
|
syncing: false,
|
||||||
|
});
|
||||||
|
ToastEvent.show(e.message, 'error');
|
||||||
|
}
|
||||||
|
dispatch({type: ACTIONS.ALL});
|
||||||
|
}}
|
||||||
style={{
|
style={{
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
@@ -603,24 +626,45 @@ export const Menu = ({
|
|||||||
paddingHorizontal: 5,
|
paddingHorizontal: 5,
|
||||||
paddingVertical: pv + 5,
|
paddingVertical: pv + 5,
|
||||||
}}>
|
}}>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}>
|
||||||
|
{syncing ? (
|
||||||
|
<ActivityIndicator size={SIZE.xs} color={colors.accent} />
|
||||||
|
) : (
|
||||||
|
<Icon color={colors.accent} name="sync" size={SIZE.sm} />
|
||||||
|
)}
|
||||||
<Text
|
<Text
|
||||||
style={{
|
style={{
|
||||||
fontFamily: WEIGHT.regular,
|
fontFamily: WEIGHT.regular,
|
||||||
color: colors.pri,
|
color: colors.pri,
|
||||||
fontSize: SIZE.xs,
|
fontSize: SIZE.xs,
|
||||||
|
marginLeft: 5,
|
||||||
}}>
|
}}>
|
||||||
<Icon color={colors.accent} name="sync" size={SIZE.xs} /> Synced{' '}
|
{syncing ? 'Syncing ' : 'Synced '}
|
||||||
{user.lastSynced && user.lastSynced !== 0
|
{!syncing
|
||||||
|
? user.lastSynced && user.lastSynced !== 0
|
||||||
? timeSince(user.lastSynced)
|
? timeSince(user.lastSynced)
|
||||||
: 'never'}
|
: 'never'
|
||||||
|
: null}
|
||||||
|
{'\n'}
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 8,
|
||||||
|
color: colors.icon,
|
||||||
|
}}>
|
||||||
|
Tap to sync
|
||||||
</Text>
|
</Text>
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
<Icon
|
<Icon
|
||||||
size={SIZE.md}
|
size={SIZE.md}
|
||||||
color={colors.accent}
|
color={colors.accent}
|
||||||
name="check-circle-outline"
|
name="check-circle-outline"
|
||||||
/>
|
/>
|
||||||
</View>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
) : (
|
) : (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
|
|||||||
Reference in New Issue
Block a user