import React, {useEffect} from 'react'; import { ActivityIndicator, Platform, Text, 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 {eOpenLoginDialog} from '../../utils/Events'; import {showContext} from '../../utils'; import {PressableButton} from '../PressableButton'; import {TimeSince} from './TimeSince'; import {hexToRGBA} from "../../utils/ColorUtils"; import {pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; import {db} from "../../utils/DB"; export const UserSection = ({noTextMode}) => { const [state, dispatch] = useTracked(); const {colors, syncing, user} = state; useEffect(() => { console.log(user); dispatch({type: Actions.TAGS}); }, []); return user && user.username ? ( {user.username} Basic { dispatch({ type: Actions.SYNCING, 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'); } 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', justifyContent: 'space-between', alignItems: 'center', paddingHorizontal: 5, paddingVertical: pv + 5, }}> {syncing ? ( ) : ( )} {syncing ? 'Syncing ' : 'Synced '} {!syncing ? ( user?.notesnook?.lastSynced ? ( ) : ( 'never' ) ) : null} {'\n'} Tap to sync ) : ( { eSendEvent(eOpenLoginDialog); }} onLongPress={(event) => { showContext(event, 'Login'); }} color={noTextMode ? 'transparent' : colors.shade} selectedColor={colors.accent} alpha={!colors.night ? -0.02 : 0.1} opacity={0.12} customStyle={{ paddingVertical: 12, marginVertical: 5, marginTop: pv + 5, borderRadius: noTextMode ? 0 : 5, width: noTextMode ? '100%' : '93%', flexDirection: 'row', alignItems: 'center', justifyContent: noTextMode ? 'center' : 'flex-start', paddingHorizontal: noTextMode ? 0 : 12, }}> {noTextMode ? null : ( You are not logged in Login to sync notes. )} ); };