1
1
/* @flow strict-local */
2
2
import React , { useContext } from 'react' ;
3
3
import type { Node } from 'react' ;
4
- import { ScrollView , View } from 'react-native' ;
4
+ import { ScrollView } from 'react-native' ;
5
5
import { SafeAreaView } from 'react-native-safe-area-context' ;
6
6
7
- import { type UserId } from '../api/idTypes' ;
8
7
import { TranslationContext } from '../boot/TranslationProvider' ;
9
8
import type { RouteProp } from '../react-navigation' ;
10
9
import type { MainTabsNavigationProp } from '../main/MainTabsScreen' ;
11
- import { createStyleSheet } from '../styles' ;
12
10
import { useDispatch , useSelector } from '../react-redux' ;
13
- import ZulipButton from '../common/ZulipButton' ;
14
11
import { logout } from '../account/logoutActions' ;
15
12
import { tryStopNotifications } from '../notification/notifTokens' ;
16
13
import AccountDetails from './AccountDetails' ;
@@ -26,88 +23,7 @@ import * as api from '../api';
26
23
import { identityOfAccount } from '../account/accountMisc' ;
27
24
import NavRow from '../common/NavRow' ;
28
25
import { 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' ;
111
27
112
28
type Props = $ReadOnly < { |
113
29
navigation : MainTabsNavigationProp < 'profile' > ,
@@ -119,7 +35,11 @@ type Props = $ReadOnly<{|
119
35
*/
120
36
export default function ProfileScreen ( props : Props ) : Node {
121
37
const navigation = useNavigation ( ) ;
38
+ const dispatch = useDispatch ( ) ;
39
+ const _ = useContext ( TranslationContext ) ;
122
40
41
+ const account = useSelector ( getAccount ) ;
42
+ const identity = identityOfAccount ( account ) ;
123
43
const auth = useSelector ( getAuth ) ;
124
44
const zulipFeatureLevel = useSelector ( getZulipFeatureLevel ) ;
125
45
const ownUser = useSelector ( getOwnUser ) ;
@@ -171,16 +91,42 @@ export default function ProfileScreen(props: Props): Node {
171
91
} }
172
92
/>
173
93
) }
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
+ />
184
130
</ ScrollView >
185
131
</ SafeAreaView >
186
132
) ;
0 commit comments