-
Notifications
You must be signed in to change notification settings - Fork 71
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
[Feat] keep track of previously logged out users #2906
Changes from 1 commit
228d76a
5ef37f6
2b76103
0a8c1de
4df08a5
6e3159e
92c65f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,10 @@ import { default as ROUTES } from '../../../constants/routeNames'; | |
import styles from './accountsBottomSheetStyles'; | ||
|
||
const AccountsBottomSheet = forwardRef( | ||
({ accounts, currentAccount, navigateToRoute, switchAccount, onClose }, ref) => { | ||
( | ||
{ accounts, currentAccount, navigateToRoute, switchAccount, onClose, prevLoggedInUsers }, | ||
ref, | ||
) => { | ||
const bottomSheetModalRef = useRef(); | ||
const userList = useRef(); | ||
const insets = useSafeAreaInsets(); | ||
|
@@ -29,20 +32,42 @@ const AccountsBottomSheet = forwardRef( | |
}, | ||
})); | ||
|
||
// _handlePressAccountTile(item) | ||
const _renderAccountTile = ({ item }) => ( | ||
<TouchableOpacity style={styles.accountTile} onPress={() => switchAccount(item)}> | ||
<View style={styles.avatarAndNameContainer}> | ||
<UserAvatar username={item.username} /> | ||
<View style={styles.nameContainer}> | ||
<Text style={styles.name}>{`@${item.username}`}</Text> | ||
const _handlePressAccountTile = (item) => { | ||
if ( | ||
item && | ||
typeof item === 'object' && | ||
Object.prototype.hasOwnProperty.call(item, 'isLoggedOut') && | ||
item.isLoggedOut | ||
) { | ||
navigateToRoute(ROUTES.SCREENS.LOGIN, { username: item?.username || '' }); | ||
} else { | ||
switchAccount(item); | ||
} | ||
}; | ||
|
||
const _renderAccountTile = ({ item }) => { | ||
if ( | ||
item && | ||
typeof item === 'object' && | ||
Object.prototype.hasOwnProperty.call(item, 'isLoggedOut') && | ||
!item.isLoggedOut | ||
) | ||
return; | ||
|
||
return ( | ||
<TouchableOpacity style={styles.accountTile} onPress={() => _handlePressAccountTile(item)}> | ||
<View style={styles.avatarAndNameContainer}> | ||
<UserAvatar username={item.username} /> | ||
<View style={styles.nameContainer}> | ||
<Text style={styles.name}>{`@${item.username}`}</Text> | ||
</View> | ||
</View> | ||
</View> | ||
{currentAccount.name === item.username && ( | ||
<Icon iconType="AntDesign" name="checkcircle" style={styles.checkIcon} size={24} /> | ||
)} | ||
</TouchableOpacity> | ||
); | ||
{currentAccount.name === item.username && ( | ||
noumantahir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Icon iconType="AntDesign" name="checkcircle" style={styles.checkIcon} size={24} /> | ||
)} | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
return ( | ||
<View style={[styles.accountsModal]}> | ||
|
@@ -55,7 +80,7 @@ const AccountsBottomSheet = forwardRef( | |
onClose={onClose} | ||
> | ||
<FlatList | ||
data={accounts} | ||
data={[...accounts, ...prevLoggedInUsers]} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to keep data flow more organised, why not added a section below list instead of mixing different objects? can even add a section labeled |
||
ref={userList} | ||
scrollEnabled | ||
keyExtractor={(item, index) => `${item.name || item.username}${index}`} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,15 @@ import { | |
SET_IS_BIOMETRIC_ENABLED, | ||
SET_ENC_UNLOCK_PIN, | ||
SET_WAVE_UPVOTE_PERCENT, | ||
SET_PREV_LOGGED_IN_USERS, | ||
CLEAR_PREV_LOGGED_IN_USERS, | ||
} from '../constants/constants'; | ||
|
||
export interface PrevLoggedInUsers { | ||
username: string; | ||
isLoggedOut: boolean; | ||
} | ||
|
||
interface State { | ||
api: string; | ||
currency: { | ||
|
@@ -72,6 +79,7 @@ interface State { | |
hidePostsThumbnails: boolean; | ||
isTermsAccepted: boolean; | ||
isBiometricEnabled: boolean; | ||
prevLoggedInUsers: PrevLoggedInUsers[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
const initialState: State = { | ||
|
@@ -113,6 +121,7 @@ const initialState: State = { | |
hidePostsThumbnails: false, | ||
isTermsAccepted: false, | ||
isBiometricEnabled: false, | ||
prevLoggedInUsers: [], | ||
}; | ||
|
||
const applicationReducer = (state = initialState, action): State => { | ||
|
@@ -298,7 +307,16 @@ const applicationReducer = (state = initialState, action): State => { | |
...state, | ||
encUnlockPin: action.payload, | ||
}; | ||
|
||
case SET_PREV_LOGGED_IN_USERS: | ||
return { | ||
...state, | ||
prevLoggedInUsers: action.payload, | ||
}; | ||
case CLEAR_PREV_LOGGED_IN_USERS: | ||
return { | ||
...state, | ||
prevLoggedInUsers: [], | ||
}; | ||
default: | ||
return state; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this huge logic can be simplified using
?
and!
operators.