@@ -8,6 +8,8 @@ import ZulipText from '../common/ZulipText';
8
8
import Touchable from '../common/Touchable' ;
9
9
import ZulipTextIntl from '../common/ZulipTextIntl' ;
10
10
import { IconDone , IconTrash } from '../common/Icons' ;
11
+ import { useGlobalSelector } from '../react-redux' ;
12
+ import { getIsActiveAccount } from './accountsSelectors' ;
11
13
import type { AccountStatus } from './accountsSelectors' ;
12
14
13
15
const styles = createStyleSheet ( {
@@ -44,26 +46,27 @@ const styles = createStyleSheet({
44
46
} ) ;
45
47
46
48
type Props = $ReadOnly < { |
47
- index : number ,
48
49
account : AccountStatus ,
49
- onSelect : ( index : number ) => Promise < void > | void ,
50
- onRemove : ( index : number ) => Promise < void > | void ,
50
+ onSelect : AccountStatus => Promise < void > | void ,
51
+ onRemove : AccountStatus => Promise < void > | void ,
51
52
| } > ;
52
53
53
54
export default function AccountItem ( props : Props ) : Node {
54
55
const { email, realm, isLoggedIn } = props . account ;
55
56
57
+ const isActiveAccount = useGlobalSelector ( state => getIsActiveAccount ( state , { email, realm } ) ) ;
58
+
56
59
// Don't show the "remove account" button (the "trash" icon) for the
57
60
// active account when it's logged in. This prevents removing it when the
58
61
// main app UI, relying on that account's data, may be on the nav stack.
59
62
// See `getHaveServerData`.
60
- const showDoneIcon = props . index === 0 && isLoggedIn ;
63
+ const showDoneIcon = isActiveAccount && isLoggedIn ;
61
64
62
65
const backgroundItemColor = isLoggedIn ? 'hsla(177, 70%, 47%, 0.1)' : 'hsla(0,0%,50%,0.1)' ;
63
66
const textColor = isLoggedIn ? BRAND_COLOR : 'gray' ;
64
67
65
68
return (
66
- < Touchable style = { styles . wrapper } onPress = { ( ) => props . onSelect ( props . index ) } >
69
+ < Touchable style = { styles . wrapper } onPress = { ( ) => props . onSelect ( props . account ) } >
67
70
< View
68
71
style = { [
69
72
styles . accountItem ,
@@ -87,7 +90,7 @@ export default function AccountItem(props: Props): Node {
87
90
style = { styles . icon }
88
91
size = { 24 }
89
92
color = "crimson"
90
- onPress = { ( ) => props . onRemove ( props . index ) }
93
+ onPress = { ( ) => props . onRemove ( props . account ) }
91
94
/>
92
95
) : (
93
96
< IconDone style = { styles . icon } size = { 24 } color = { BRAND_COLOR } />
0 commit comments