Changeset View
Changeset View
Standalone View
Standalone View
native/profile/profile-screen.react.js
Show All 33 Lines | import { | ||||
AppearancePreferencesRouteName, | AppearancePreferencesRouteName, | ||||
FriendListRouteName, | FriendListRouteName, | ||||
BlockListRouteName, | BlockListRouteName, | ||||
PrivacyPreferencesRouteName, | PrivacyPreferencesRouteName, | ||||
DefaultNotificationsPreferencesRouteName, | DefaultNotificationsPreferencesRouteName, | ||||
} from '../navigation/route-names.js'; | } from '../navigation/route-names.js'; | ||||
import { useSelector } from '../redux/redux-utils.js'; | import { useSelector } from '../redux/redux-utils.js'; | ||||
import { type Colors, useColors, useStyles } from '../themes/colors.js'; | import { type Colors, useColors, useStyles } from '../themes/colors.js'; | ||||
import { useShouldRenderAvatars } from '../utils/avatar-utils.js'; | |||||
import { useStaffCanSee } from '../utils/staff-utils.js'; | import { useStaffCanSee } from '../utils/staff-utils.js'; | ||||
type ProfileRowProps = { | type ProfileRowProps = { | ||||
+content: string, | +content: string, | ||||
+onPress: () => void, | +onPress: () => void, | ||||
+danger?: boolean, | +danger?: boolean, | ||||
}; | }; | ||||
Show All 18 Lines | type Props = { | ||||
+logOutLoading: boolean, | +logOutLoading: boolean, | ||||
+colors: Colors, | +colors: Colors, | ||||
+styles: typeof unboundStyles, | +styles: typeof unboundStyles, | ||||
+dispatchActionPromise: DispatchActionPromise, | +dispatchActionPromise: DispatchActionPromise, | ||||
+logOut: (preRequestUserState: PreRequestUserState) => Promise<LogOutResult>, | +logOut: (preRequestUserState: PreRequestUserState) => Promise<LogOutResult>, | ||||
+staffCanSee: boolean, | +staffCanSee: boolean, | ||||
+stringForUser: ?string, | +stringForUser: ?string, | ||||
+isAccountWithPassword: boolean, | +isAccountWithPassword: boolean, | ||||
+shouldRenderAvatars: boolean, | |||||
}; | }; | ||||
class ProfileScreen extends React.PureComponent<Props> { | class ProfileScreen extends React.PureComponent<Props> { | ||||
get loggedOutOrLoggingOut() { | get loggedOutOrLoggingOut() { | ||||
return ( | return ( | ||||
!this.props.currentUserInfo || | !this.props.currentUserInfo || | ||||
this.props.currentUserInfo.anonymous || | this.props.currentUserInfo.anonymous || | ||||
this.props.logOutLoading | this.props.logOutLoading | ||||
Show All 39 Lines | render() { | ||||
const avatarInfo = getAvatarForUser(this.props.currentUserInfo); | const avatarInfo = getAvatarForUser(this.props.currentUserInfo); | ||||
const avatar = ( | const avatar = ( | ||||
<View style={this.props.styles.avatarSection}> | <View style={this.props.styles.avatarSection}> | ||||
<Avatar size="profile" avatarInfo={avatarInfo} /> | <Avatar size="profile" avatarInfo={avatarInfo} /> | ||||
</View> | </View> | ||||
); | ); | ||||
let avatarSection; | |||||
if (this.props.shouldRenderAvatars) { | |||||
avatarSection = ( | |||||
<> | |||||
<Text style={this.props.styles.header}>USER AVATAR</Text> | |||||
<View style={this.props.styles.section}>{avatar}</View> | |||||
</> | |||||
); | |||||
} | |||||
return ( | return ( | ||||
<View style={this.props.styles.container}> | <View style={this.props.styles.container}> | ||||
<ScrollView | <ScrollView | ||||
contentContainerStyle={this.props.styles.scrollViewContentContainer} | contentContainerStyle={this.props.styles.scrollViewContentContainer} | ||||
style={this.props.styles.scrollView} | style={this.props.styles.scrollView} | ||||
> | > | ||||
<Text style={this.props.styles.header}>USER AVATAR</Text> | {avatarSection} | ||||
<View style={this.props.styles.section}>{avatar}</View> | |||||
<Text style={this.props.styles.header}>ACCOUNT</Text> | <Text style={this.props.styles.header}>ACCOUNT</Text> | ||||
<View style={this.props.styles.section}> | <View style={this.props.styles.section}> | ||||
<Action.Row> | <Action.Row> | ||||
<Text style={this.props.styles.loggedInLabel}>Logged in as </Text> | <Text style={this.props.styles.loggedInLabel}>Logged in as </Text> | ||||
<SingleLine | <SingleLine | ||||
style={[this.props.styles.label, this.props.styles.username]} | style={[this.props.styles.label, this.props.styles.username]} | ||||
> | > | ||||
{this.props.stringForUser} | {this.props.stringForUser} | ||||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | React.memo<BaseProps>(function ConnectedProfileScreen(props: BaseProps) { | ||||
const styles = useStyles(unboundStyles); | const styles = useStyles(unboundStyles); | ||||
const callLogOut = useServerCall(logOut); | const callLogOut = useServerCall(logOut); | ||||
const dispatchActionPromise = useDispatchActionPromise(); | const dispatchActionPromise = useDispatchActionPromise(); | ||||
const staffCanSee = useStaffCanSee(); | const staffCanSee = useStaffCanSee(); | ||||
const stringForUser = useStringForUser(currentUserInfo); | const stringForUser = useStringForUser(currentUserInfo); | ||||
const isAccountWithPassword = useSelector(state => | const isAccountWithPassword = useSelector(state => | ||||
accountHasPassword(state.currentUserInfo), | accountHasPassword(state.currentUserInfo), | ||||
); | ); | ||||
const shouldRenderAvatars = useShouldRenderAvatars(); | |||||
return ( | return ( | ||||
<ProfileScreen | <ProfileScreen | ||||
{...props} | {...props} | ||||
currentUserInfo={currentUserInfo} | currentUserInfo={currentUserInfo} | ||||
preRequestUserState={preRequestUserState} | preRequestUserState={preRequestUserState} | ||||
logOutLoading={logOutLoading} | logOutLoading={logOutLoading} | ||||
colors={colors} | colors={colors} | ||||
styles={styles} | styles={styles} | ||||
logOut={callLogOut} | logOut={callLogOut} | ||||
dispatchActionPromise={dispatchActionPromise} | dispatchActionPromise={dispatchActionPromise} | ||||
staffCanSee={staffCanSee} | staffCanSee={staffCanSee} | ||||
stringForUser={stringForUser} | stringForUser={stringForUser} | ||||
isAccountWithPassword={isAccountWithPassword} | isAccountWithPassword={isAccountWithPassword} | ||||
shouldRenderAvatars={shouldRenderAvatars} | |||||
/> | /> | ||||
); | ); | ||||
}); | }); | ||||
export default ConnectedProfileScreen; | export default ConnectedProfileScreen; |