11/* @flow strict-local */
22import React , { useContext } from 'react' ;
33import type { Node } from 'react' ;
4- import { ScrollView , View } from 'react-native' ;
4+ import { ScrollView } from 'react-native' ;
55import { SafeAreaView } from 'react-native-safe-area-context' ;
66
7- import { type UserId } from '../api/idTypes' ;
87import { TranslationContext } from '../boot/TranslationProvider' ;
98import type { RouteProp } from '../react-navigation' ;
109import type { MainTabsNavigationProp } from '../main/MainTabsScreen' ;
11- import { createStyleSheet } from '../styles' ;
1210import { useDispatch , useSelector } from '../react-redux' ;
13- import ZulipButton from '../common/ZulipButton' ;
1411import { logout } from '../account/logoutActions' ;
1512import { tryStopNotifications } from '../notification/notifTokens' ;
1613import AccountDetails from './AccountDetails' ;
@@ -26,88 +23,7 @@ import * as api from '../api';
2623import { identityOfAccount } from '../account/accountMisc' ;
2724import NavRow from '../common/NavRow' ;
2825import { emojiTypeFromReactionType } from '../emoji/data' ;
29-
30- const styles = createStyleSheet ( {
31- buttonRow : {
32- flexDirection : 'row' ,
33- marginHorizontal : 8 ,
34- } ,
35- button : {
36- flex : 1 ,
37- margin : 8 ,
38- } ,
39- } ) ;
40-
41- function ProfileButton ( props : { | + ownUserId : UserId | } ) {
42- const navigation = useNavigation ( ) ;
43- return (
44- < ZulipButton
45- style = { styles . button }
46- secondary
47- text = "Full profile"
48- onPress = { ( ) => {
49- navigation . push ( 'account-details' , { userId : props . ownUserId } ) ;
50- } }
51- />
52- ) ;
53- }
54-
55- function SettingsButton ( props : { || } ) {
56- const navigation = useNavigation ( ) ;
57- return (
58- < ZulipButton
59- style = { styles . button }
60- secondary
61- text = "Settings"
62- onPress = { ( ) => {
63- navigation . push ( 'settings' ) ;
64- } }
65- />
66- ) ;
67- }
68-
69- function SwitchAccountButton ( props : { || } ) {
70- const navigation = useNavigation ( ) ;
71- return (
72- < ZulipButton
73- style = { styles . button }
74- secondary
75- text = "Switch account"
76- onPress = { ( ) => {
77- navigation . push ( 'account-pick' ) ;
78- } }
79- />
80- ) ;
81- }
82-
83- function LogoutButton ( props : { || } ) {
84- const dispatch = useDispatch ( ) ;
85- const _ = useContext ( TranslationContext ) ;
86- const account = useSelector ( getAccount ) ;
87- const identity = identityOfAccount ( account ) ;
88- return (
89- < ZulipButton
90- style = { styles . button }
91- secondary
92- text = "Log out"
93- onPress = { ( ) => {
94- showConfirmationDialog ( {
95- destructive : true ,
96- title : 'Log out' ,
97- message : {
98- text : 'This will log out {email} on {realmUrl} from the mobile app on this device.' ,
99- values : { email : identity . email , realmUrl : identity . realm . toString ( ) } ,
100- } ,
101- onPressConfirm : ( ) => {
102- dispatch ( tryStopNotifications ( account ) ) ;
103- dispatch ( logout ( ) ) ;
104- } ,
105- _,
106- } ) ;
107- } }
108- />
109- ) ;
110- }
26+ import TextRow from '../common/TextRow' ;
11127
11228type Props = $ReadOnly < { |
11329 navigation : MainTabsNavigationProp < 'profile' > ,
@@ -119,7 +35,11 @@ type Props = $ReadOnly<{|
11935 */
12036export default function ProfileScreen ( props : Props ) : Node {
12137 const navigation = useNavigation ( ) ;
38+ const dispatch = useDispatch ( ) ;
39+ const _ = useContext ( TranslationContext ) ;
12240
41+ const account = useSelector ( getAccount ) ;
42+ const identity = identityOfAccount ( account ) ;
12343 const auth = useSelector ( getAuth ) ;
12444 const zulipFeatureLevel = useSelector ( getZulipFeatureLevel ) ;
12545 const ownUser = useSelector ( getOwnUser ) ;
@@ -171,16 +91,42 @@ export default function ProfileScreen(props: Props): Node {
17191 } }
17292 />
17393 ) }
174- < View style = { styles . buttonRow } >
175- < ProfileButton ownUserId = { ownUser . user_id } />
176- </ View >
177- < View style = { styles . buttonRow } >
178- < SettingsButton />
179- </ View >
180- < View style = { styles . buttonRow } >
181- < SwitchAccountButton />
182- < LogoutButton />
183- </ View >
94+ < NavRow
95+ title = "Full profile"
96+ onPress = { ( ) => {
97+ navigation . push ( 'account-details' , { userId : ownUserId } ) ;
98+ } }
99+ />
100+ < NavRow
101+ title = "Settings"
102+ onPress = { ( ) => {
103+ navigation . push ( 'settings' ) ;
104+ } }
105+ />
106+ < NavRow
107+ title = "Switch account"
108+ onPress = { ( ) => {
109+ navigation . push ( 'account-pick' ) ;
110+ } }
111+ />
112+ < TextRow
113+ title = "Log out"
114+ onPress = { ( ) => {
115+ showConfirmationDialog ( {
116+ destructive : true ,
117+ title : 'Log out' ,
118+ message : {
119+ text : 'This will log out {email} on {realmUrl} from the mobile app on this device.' ,
120+ values : { email : identity . email , realmUrl : identity . realm . toString ( ) } ,
121+ } ,
122+ onPressConfirm : ( ) => {
123+ dispatch ( tryStopNotifications ( account ) ) ;
124+ dispatch ( logout ( ) ) ;
125+ } ,
126+ _,
127+ } ) ;
128+ } }
129+ />
184130 </ ScrollView >
185131 </ SafeAreaView >
186132 ) ;
0 commit comments