setting logout activity indicator

This commit is contained in:
balzack 2022-11-18 18:24:45 -08:00
parent 0e7de4c40d
commit 1814f97c38
5 changed files with 27 additions and 10 deletions

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.4</string> <string>1.5</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>

View File

@ -20,6 +20,7 @@ export function useAppContext() {
loginTimestamp: null, loginTimestamp: null,
disconnected: null, disconnected: null,
deviceToken: null, deviceToken: null,
loggingOut: false,
}); });
const store = useContext(StoreContext); const store = useContext(StoreContext);
const account = useContext(AccountContext); const account = useContext(AccountContext);
@ -108,6 +109,7 @@ export function useAppContext() {
} }
}, },
logout: async () => { logout: async () => {
updateState({ loggingOut: true });
try { try {
await messaging().deleteToken(); await messaging().deleteToken();
const token = await messaging().getToken(); const token = await messaging().getToken();
@ -119,6 +121,7 @@ export function useAppContext() {
} }
await clearSession(); await clearSession();
await store.actions.clearSession(); await store.actions.clearSession();
updateState({ loggingOut: false });
}, },
remove: async () => { remove: async () => {
await removeProfile(state.server, state.appToken); await removeProfile(state.server, state.appToken);

View File

@ -1,5 +1,5 @@
import { useEffect, useContext } from 'react'; import { useEffect, useContext } from 'react';
import { KeyboardAvoidingView, Modal, Alert, TextInput, ScrollView, View, Switch, TouchableOpacity, Text } from 'react-native'; import { ActivityIndicator, KeyboardAvoidingView, Modal, Alert, TextInput, ScrollView, View, Switch, TouchableOpacity, Text } from 'react-native';
import { styles } from './Profile.styled'; import { styles } from './Profile.styled';
import { useProfile } from './useProfile.hook'; import { useProfile } from './useProfile.hook';
import Ionicons from '@expo/vector-icons/AntDesign'; import Ionicons from '@expo/vector-icons/AntDesign';
@ -21,9 +21,16 @@ export function Profile({ navigation }) {
</View> </View>
), ),
headerRight: () => ( headerRight: () => (
<>
{ state.loggingOut && (
<ActivityIndicator style={styles.action} size="small" />
)}
{ !state.loggingOut && (
<TouchableOpacity style={styles.action} onPress={logout} onLongPress={actions.showDelete}> <TouchableOpacity style={styles.action} onPress={logout} onLongPress={actions.showDelete}>
<Ionicons name="logout" size={22} color={Colors.primary} /> <Ionicons name="logout" size={22} color={Colors.primary} />
</TouchableOpacity> </TouchableOpacity>
)}
</>
), ),
}); });
} }
@ -71,9 +78,14 @@ export function Profile({ navigation }) {
<SafeAreaView style={styles.drawer} edges={['top', 'bottom', 'right']}> <SafeAreaView style={styles.drawer} edges={['top', 'bottom', 'right']}>
<View style={styles.header}> <View style={styles.header}>
<Text style={styles.headerText} numberOfLines={1}>{ `${state.handle}@${state.node}` }</Text> <Text style={styles.headerText} numberOfLines={1}>{ `${state.handle}@${state.node}` }</Text>
{ state.loggingOut && (
<ActivityIndicator size="small" />
)}
{ !state.loggingOut && (
<TouchableOpacity onPress={logout} onLongPress={actions.showDelete}> <TouchableOpacity onPress={logout} onLongPress={actions.showDelete}>
<Ionicons name="logout" size={16} color={Colors.grey} /> <Ionicons name="logout" size={16} color={Colors.grey} />
</TouchableOpacity> </TouchableOpacity>
)}
</View> </View>
<ProfileBody /> <ProfileBody />
<TouchableOpacity style={styles.erase} activeOpacity={1} onPress={actions.showDelete}> <TouchableOpacity style={styles.erase} activeOpacity={1} onPress={actions.showDelete}>

View File

@ -44,6 +44,7 @@ export const styles = StyleSheet.create({
flexDirection: 'row', flexDirection: 'row',
alignItems: 'flex-end', alignItems: 'flex-end',
justifyContent: 'center', justifyContent: 'center',
height: 32,
}, },
headerText: { headerText: {
paddingLeft: 16, paddingLeft: 16,

View File

@ -14,6 +14,7 @@ export function useProfile() {
showDelete: false, showDelete: false,
tabbed: null, tabbed: null,
confirmDelete: null, confirmDelete: null,
logginOut: false,
}); });
const app = useContext(AppContext); const app = useContext(AppContext);
@ -42,8 +43,8 @@ export function useProfile() {
}, [profile]); }, [profile]);
useEffect(() => { useEffect(() => {
const { disconnected } = app.state; const { disconnected, loggingOut } = app.state;
updateState({ disconnected }); updateState({ disconnected, loggingOut });
}, [app]); }, [app]);
const actions = { const actions = {