Skip to content

Commit ab6f2cf

Browse files
lex111Houssein Djirdeh
authored andcommitted
refactor(profiles): simplify check of fully loaded user data (#419)
1 parent 9529c09 commit ab6f2cf

File tree

3 files changed

+109
-97
lines changed

3 files changed

+109
-97
lines changed

src/auth/screens/auth-profile.screen.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ class AuthProfile extends Component {
121121
renderContent={() =>
122122
<UserProfile
123123
type="user"
124-
initialUser={hasInitialUser && !!starCount ? user : {}}
125-
user={hasInitialUser && !!starCount ? user : {}}
126-
starCount={hasInitialUser && !!starCount ? starCount : ''}
124+
initialUser={hasInitialUser ? user : {}}
125+
user={hasInitialUser ? user : {}}
126+
starCount={hasInitialUser ? starCount : ''}
127127
language={language}
128128
navigation={navigation}
129129
/>}
130130
refreshControl={
131131
<RefreshControl
132-
refreshing={isPending}
132+
refreshing={isPendingUser}
133133
onRefresh={this.refreshProfile}
134134
/>
135135
}

src/components/user-profile.component.js

Lines changed: 98 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type Props = {
1919
const styles = StyleSheet.create({
2020
container: {
2121
flex: 1,
22+
},
23+
wrapperContainer: {
24+
flex: 1,
2225
alignItems: 'center',
2326
justifyContent: 'center',
2427
},
@@ -104,99 +107,103 @@ export const UserProfile = ({
104107
navigation,
105108
}: Props) =>
106109
<View style={styles.container}>
107-
<View style={styles.profile}>
108-
<ImageZoom
109-
uri={{
110-
uri: initialUser.avatar_url
111-
? `${initialUser.avatar_url}&lastModified=${initialUser.updated_at}`
112-
: `${user.avatar_url}&lastModified=${user.updated_at}`,
113-
}}
114-
style={[
115-
styles.avatar,
116-
(initialUser.type === 'User' || user.type === 'User') &&
117-
styles.userAvatar,
118-
]}
119-
/>
120-
<Text style={styles.title}>
121-
{user.name || ' '}
122-
</Text>
123-
<Text style={styles.subtitle}>
124-
{initialUser.login || ' '}
125-
</Text>
126-
</View>
127-
<View style={styles.details}>
128-
{user.hasOwnProperty('public_repos') &&
129-
<TouchableOpacity
130-
style={styles.unit}
131-
onPress={() =>
132-
navigation.navigate('RepositoryList', {
133-
title: translate('user.repositoryList.title', language),
134-
user,
135-
repoCount: user.public_repos > 15 ? 15 : user.public_repos,
136-
})}
137-
>
138-
<Text style={styles.unitNumber}>
139-
{!isNaN(parseInt(user.public_repos, 10))
140-
? user.public_repos + (user.total_private_repos || 0)
141-
: ' '}
142-
</Text>
143-
<Text style={styles.unitText}>
144-
{translate('common.repositories', language)}
145-
</Text>
146-
</TouchableOpacity>}
147-
148-
{type !== 'org' && !isNaN(parseInt(starCount, 10)) &&
149-
<TouchableOpacity style={styles.unit}>
150-
<Text style={styles.unitNumber}>
151-
{abbreviateNumber(starCount)}
110+
{((user.hasOwnProperty('public_repos') &&
111+
!isNaN(parseInt(starCount, 10))) ||
112+
type === 'org') &&
113+
<View style={styles.wrapperContainer}>
114+
<View style={styles.profile}>
115+
<ImageZoom
116+
uri={{
117+
uri: initialUser.avatar_url
118+
? `${initialUser.avatar_url}&lastModified=${initialUser.updated_at}`
119+
: `${user.avatar_url}&lastModified=${user.updated_at}`,
120+
}}
121+
style={[
122+
styles.avatar,
123+
(initialUser.type === 'User' || user.type === 'User') &&
124+
styles.userAvatar,
125+
]}
126+
/>
127+
<Text style={styles.title}>
128+
{user.name || ' '}
152129
</Text>
153-
<Text style={styles.unitText}>
154-
{translate('common.stars', language)}
130+
<Text style={styles.subtitle}>
131+
{initialUser.login || ' '}
155132
</Text>
156-
</TouchableOpacity>}
133+
</View>
134+
<View style={styles.details}>
135+
<TouchableOpacity
136+
style={styles.unit}
137+
onPress={() =>
138+
navigation.navigate('RepositoryList', {
139+
title: translate('user.repositoryList.title', language),
140+
user,
141+
repoCount: user.public_repos > 15 ? 15 : user.public_repos,
142+
})}
143+
>
144+
<Text style={styles.unitNumber}>
145+
{!isNaN(parseInt(user.public_repos, 10))
146+
? user.public_repos + (user.total_private_repos || 0)
147+
: ' '}
148+
</Text>
149+
<Text style={styles.unitText}>
150+
{translate('common.repositories', language)}
151+
</Text>
152+
</TouchableOpacity>
157153

158-
{type !== 'org' && user.hasOwnProperty('followers') &&
159-
<TouchableOpacity
160-
style={styles.unit}
161-
onPress={() =>
162-
navigation.navigate('FollowerList', {
163-
title: translate('user.followers.title', language),
164-
user,
165-
followerCount: user.followers > 15 ? 15 : user.followers,
166-
})}
167-
>
168-
<Text style={styles.unitNumber}>
169-
{!isNaN(parseInt(user.followers, 10)) ? user.followers : ' '}
170-
</Text>
171-
<Text style={styles.unitText}>
172-
{translate('user.followers.text', language)}
173-
</Text>
174-
{isFollowing &&
175-
<Text style={[styles.unitStatus, styles.badge]}>
176-
{translate('user.following.followingYou', language)}
177-
</Text>}
178-
</TouchableOpacity>}
154+
{type !== 'org' &&
155+
<TouchableOpacity style={styles.unit}>
156+
<Text style={styles.unitNumber}>
157+
{abbreviateNumber(starCount)}
158+
</Text>
159+
<Text style={styles.unitText}>
160+
{translate('common.stars', language)}
161+
</Text>
162+
</TouchableOpacity>}
179163

180-
{type !== 'org' && user.hasOwnProperty('following') &&
181-
<TouchableOpacity
182-
style={styles.unit}
183-
onPress={() =>
184-
navigation.navigate('FollowingList', {
185-
title: translate('user.following.title', language),
186-
user,
187-
followingCount: user.following > 15 ? 15 : user.following,
188-
})}
189-
>
190-
<Text style={styles.unitNumber}>
191-
{!isNaN(parseInt(user.following, 10)) ? user.following : ' '}
192-
</Text>
193-
<Text style={styles.unitText}>
194-
{translate('user.following.text', language)}
195-
</Text>
196-
{isFollower &&
197-
<Text style={[styles.unitStatus, styles.badge]}>
198-
{translate('user.followers.followsYou')}
199-
</Text>}
200-
</TouchableOpacity>}
201-
</View>
164+
{type !== 'org' &&
165+
<TouchableOpacity
166+
style={styles.unit}
167+
onPress={() =>
168+
navigation.navigate('FollowerList', {
169+
title: translate('user.followers.title', language),
170+
user,
171+
followerCount: user.followers > 15 ? 15 : user.followers,
172+
})}
173+
>
174+
<Text style={styles.unitNumber}>
175+
{!isNaN(parseInt(user.followers, 10)) ? user.followers : ' '}
176+
</Text>
177+
<Text style={styles.unitText}>
178+
{translate('user.followers.text', language)}
179+
</Text>
180+
{isFollowing &&
181+
<Text style={[styles.unitStatus, styles.badge]}>
182+
{translate('user.following.followingYou', language)}
183+
</Text>}
184+
</TouchableOpacity>}
185+
186+
{type !== 'org' &&
187+
<TouchableOpacity
188+
style={styles.unit}
189+
onPress={() =>
190+
navigation.navigate('FollowingList', {
191+
title: translate('user.following.title', language),
192+
user,
193+
followingCount: user.following > 15 ? 15 : user.following,
194+
})}
195+
>
196+
<Text style={styles.unitNumber}>
197+
{!isNaN(parseInt(user.following, 10)) ? user.following : ' '}
198+
</Text>
199+
<Text style={styles.unitText}>
200+
{translate('user.following.text', language)}
201+
</Text>
202+
{isFollower &&
203+
<Text style={[styles.unitStatus, styles.badge]}>
204+
{translate('user.followers.followsYou')}
205+
</Text>}
206+
</TouchableOpacity>}
207+
</View>
208+
</View>}
202209
</View>;

src/user/screens/profile.screen.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ class Profile extends Component {
150150
} = this.props;
151151
const { refreshing } = this.state;
152152
const initialUser = navigation.state.params.user;
153-
const isPending = isPendingUser || isPendingOrgs || isPendingStarCount || isPendingCheckFollowing || isPendingCheckFollower;
153+
const isPending =
154+
isPendingUser ||
155+
isPendingOrgs ||
156+
isPendingStarCount ||
157+
isPendingCheckFollowing ||
158+
isPendingCheckFollower;
154159
const userActions = [
155160
isFollowing
156161
? translate('user.profile.unfollow', language)
@@ -173,7 +178,7 @@ class Profile extends Component {
173178
/>}
174179
refreshControl={
175180
<RefreshControl
176-
refreshing={refreshing}
181+
refreshing={refreshing || isPending}
177182
onRefresh={this.getUserInfo}
178183
/>
179184
}

0 commit comments

Comments
 (0)