@@ -8,6 +8,8 @@ import ZulipText from '../common/ZulipText';
88import Touchable from '../common/Touchable' ;
99import ZulipTextIntl from '../common/ZulipTextIntl' ;
1010import { IconDone , IconTrash } from '../common/Icons' ;
11+ import { useGlobalSelector } from '../react-redux' ;
12+ import { getIsActiveAccount } from './accountsSelectors' ;
1113import type { AccountStatus } from './accountsSelectors' ;
1214
1315const styles = createStyleSheet ( {
@@ -44,26 +46,27 @@ const styles = createStyleSheet({
4446} ) ;
4547
4648type Props = $ReadOnly < { |
47- index : number ,
4849 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 ,
5152| } > ;
5253
5354export default function AccountItem ( props : Props ) : Node {
5455 const { email, realm, isLoggedIn } = props . account ;
5556
57+ const isActiveAccount = useGlobalSelector ( state => getIsActiveAccount ( state , { email, realm } ) ) ;
58+
5659 // Don't show the "remove account" button (the "trash" icon) for the
5760 // active account when it's logged in. This prevents removing it when the
5861 // main app UI, relying on that account's data, may be on the nav stack.
5962 // See `getHaveServerData`.
60- const showDoneIcon = props . index === 0 && isLoggedIn ;
63+ const showDoneIcon = isActiveAccount && isLoggedIn ;
6164
6265 const backgroundItemColor = isLoggedIn ? 'hsla(177, 70%, 47%, 0.1)' : 'hsla(0,0%,50%,0.1)' ;
6366 const textColor = isLoggedIn ? BRAND_COLOR : 'gray' ;
6467
6568 return (
66- < Touchable style = { styles . wrapper } onPress = { ( ) => props . onSelect ( props . index ) } >
69+ < Touchable style = { styles . wrapper } onPress = { ( ) => props . onSelect ( props . account ) } >
6770 < View
6871 style = { [
6972 styles . accountItem ,
@@ -87,7 +90,7 @@ export default function AccountItem(props: Props): Node {
8790 style = { styles . icon }
8891 size = { 24 }
8992 color = "crimson"
90- onPress = { ( ) => props . onRemove ( props . index ) }
93+ onPress = { ( ) => props . onRemove ( props . account ) }
9194 />
9295 ) : (
9396 < IconDone style = { styles . icon } size = { 24 } color = { BRAND_COLOR } />
0 commit comments