Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProfileScreen: Use NavRows and a TextRow instead of ZulipButtons #5688

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 42 additions & 96 deletions src/account-info/ProfileScreen.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/* @flow strict-local */
import React, { useContext } from 'react';
import type { Node } from 'react';
import { ScrollView, View } from 'react-native';
import { ScrollView } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';

import { type UserId } from '../api/idTypes';
import { TranslationContext } from '../boot/TranslationProvider';
import type { RouteProp } from '../react-navigation';
import type { MainTabsNavigationProp } from '../main/MainTabsScreen';
import { createStyleSheet } from '../styles';
import { useDispatch, useSelector } from '../react-redux';
import ZulipButton from '../common/ZulipButton';
import { logout } from '../account/logoutActions';
import { tryStopNotifications } from '../notification/notifTokens';
import AccountDetails from './AccountDetails';
Expand All @@ -26,88 +23,7 @@ import * as api from '../api';
import { identityOfAccount } from '../account/accountMisc';
import NavRow from '../common/NavRow';
import { emojiTypeFromReactionType } from '../emoji/data';

const styles = createStyleSheet({
buttonRow: {
flexDirection: 'row',
marginHorizontal: 8,
},
button: {
flex: 1,
margin: 8,
},
});

function ProfileButton(props: {| +ownUserId: UserId |}) {
const navigation = useNavigation();
return (
<ZulipButton
style={styles.button}
secondary
text="Full profile"
onPress={() => {
navigation.push('account-details', { userId: props.ownUserId });
}}
/>
);
}

function SettingsButton(props: {||}) {
const navigation = useNavigation();
return (
<ZulipButton
style={styles.button}
secondary
text="Settings"
onPress={() => {
navigation.push('settings');
}}
/>
);
}

function SwitchAccountButton(props: {||}) {
const navigation = useNavigation();
return (
<ZulipButton
style={styles.button}
secondary
text="Switch account"
onPress={() => {
navigation.push('account-pick');
}}
/>
);
}

function LogoutButton(props: {||}) {
const dispatch = useDispatch();
const _ = useContext(TranslationContext);
const account = useSelector(getAccount);
const identity = identityOfAccount(account);
return (
<ZulipButton
style={styles.button}
secondary
text="Log out"
onPress={() => {
showConfirmationDialog({
destructive: true,
title: 'Log out',
message: {
text: 'This will log out {email} on {realmUrl} from the mobile app on this device.',
values: { email: identity.email, realmUrl: identity.realm.toString() },
},
onPressConfirm: () => {
dispatch(tryStopNotifications(account));
dispatch(logout());
},
_,
});
}}
/>
);
}
import TextRow from '../common/TextRow';

type Props = $ReadOnly<{|
navigation: MainTabsNavigationProp<'profile'>,
Expand All @@ -119,7 +35,11 @@ type Props = $ReadOnly<{|
*/
export default function ProfileScreen(props: Props): Node {
const navigation = useNavigation();
const dispatch = useDispatch();
const _ = useContext(TranslationContext);

const account = useSelector(getAccount);
const identity = identityOfAccount(account);
const auth = useSelector(getAuth);
const zulipFeatureLevel = useSelector(getZulipFeatureLevel);
const ownUser = useSelector(getOwnUser);
Expand Down Expand Up @@ -171,16 +91,42 @@ export default function ProfileScreen(props: Props): Node {
}}
/>
)}
<View style={styles.buttonRow}>
<ProfileButton ownUserId={ownUser.user_id} />
</View>
<View style={styles.buttonRow}>
<SettingsButton />
</View>
<View style={styles.buttonRow}>
<SwitchAccountButton />
<LogoutButton />
</View>
<NavRow
title="Full profile"
onPress={() => {
navigation.push('account-details', { userId: ownUserId });
}}
/>
<NavRow
title="Settings"
onPress={() => {
navigation.push('settings');
}}
/>
<NavRow
title="Switch account"
onPress={() => {
navigation.push('account-pick');
}}
/>
<TextRow
title="Log out"
onPress={() => {
showConfirmationDialog({
destructive: true,
title: 'Log out',
message: {
text: 'This will log out {email} on {realmUrl} from the mobile app on this device.',
values: { email: identity.email, realmUrl: identity.realm.toString() },
},
onPressConfirm: () => {
dispatch(tryStopNotifications(account));
dispatch(logout());
},
_,
});
}}
/>
</ScrollView>
</SafeAreaView>
);
Expand Down