import React from 'react';
import {ActivityIndicator, TouchableOpacity, View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import {eSendEvent, ToastEvent} from '../../services/EventManager';
import {getElevation, SUBSCRIPTION_STATUS_STRINGS} from '../../utils';
import {db} from '../../utils/DB';
import {eOpenLoginDialog} from '../../utils/Events';
import {pv, SIZE} from '../../utils/SizeUtils';
import {PressableButton} from '../PressableButton';
import Paragraph from '../Typography/Paragraph';
import {TimeSince} from './TimeSince';
export const UserSection = ({noTextMode}) => {
const [state, dispatch] = useTracked();
const {colors, syncing, user} = state;
return user && user.username ? (
{user.username}
{SUBSCRIPTION_STATUS_STRINGS[user.subscription.status]}
{
dispatch({
type: Actions.SYNCING,
syncing: true,
});
try {
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,
});
}
}}
style={{
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingRight: 5,
paddingVertical: 12,
}}>
{syncing ? 'Syncing ' : 'Last synced: '}
{!syncing ? (
user?.lastSynced ? (
) : (
'never'
)
) : null}
{'\n'}
{syncing ? 'Fetching your notes ' : 'Tap to sync '}
{syncing ? (
) : (
)}
) : (
{
eSendEvent(eOpenLoginDialog);
}}
type="shade"
customStyle={{
paddingVertical: 12,
marginVertical: 5,
marginTop: pv + 5,
borderRadius: 5,
width: '100%',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
paddingHorizontal: 8,
}}>
{noTextMode ? null : (
You are not logged in
Login to sync notes.
)}
);
};