import React, {useEffect} from 'react' import { ActivityIndicator, StyleSheet, TouchableOpacity, View, } from 'react-native' import { FontAwesomeIcon, FontAwesomeIconStyle, } from '@fortawesome/react-native-fontawesome' import {observer} from 'mobx-react-lite' import * as AppInfo from 'lib/app-info' import {useStores} from 'state/index' import {ScreenParams} from '../routes' import {s} from 'lib/styles' import {ScrollView} from '../com/util/Views' import {ViewHeader} from '../com/util/ViewHeader' import {Link} from '../com/util/Link' import {Text} from '../com/util/text/Text' import * as Toast from '../com/util/Toast' import {UserAvatar} from '../com/util/UserAvatar' import {usePalette} from 'lib/hooks/usePalette' import {AccountData} from 'state/models/session' import {useAnalytics} from 'lib/analytics' export const Settings = observer(function Settings({ navIdx, visible, }: ScreenParams) { const pal = usePalette('default') const store = useStores() const {screen, track} = useAnalytics() const [isSwitching, setIsSwitching] = React.useState(false) useEffect(() => { screen('Settings') }, [screen]) useEffect(() => { if (!visible) { return } store.shell.setMinimalShellMode(false) store.nav.setTitle(navIdx, 'Settings') }, [visible, store, navIdx]) const onPressSwitchAccount = async (acct: AccountData) => { track('Settings:SwitchAccountButtonClicked') setIsSwitching(true) if (await store.session.resumeSession(acct)) { setIsSwitching(false) store.nav.tab.fixedTabReset() Toast.show(`Signed in as ${acct.displayName || acct.handle}`) return } setIsSwitching(false) Toast.show('Sorry! We need you to enter your password.') store.nav.tab.fixedTabReset() store.session.clear() } const onPressAddAccount = () => { track('Settings:AddAccountButtonClicked') store.session.clear() } const onPressSignout = () => { track('Settings:SignOutButtonClicked') store.session.logout() } const onPressDeleteAccount = () => { store.shell.openModal({name: 'delete-account'}) } return ( Signed in as Sign out {isSwitching ? ( ) : ( {store.me.displayName || store.me.handle} @{store.me.handle} )} Switch to: {store.session.switchableAccounts.map(account => ( onPressSwitchAccount(account) }> {account.displayName || account.handle} @{account.handle} ))} Add account Danger zone Delete my account Developer tools System log Storybook Build version {AppInfo.appVersion} ({AppInfo.buildVersion}) ) }) const styles = StyleSheet.create({ dimmed: { opacity: 0.5, }, spacer: { height: 50, }, alignCenter: { alignItems: 'center', }, title: { fontSize: 32, fontWeight: 'bold', marginTop: 20, marginBottom: 14, }, profile: { flexDirection: 'row', marginVertical: 6, borderRadius: 4, paddingVertical: 10, paddingHorizontal: 10, }, avi: { width: 40, height: 40, borderRadius: 30, marginRight: 8, }, })