Skip to content

Commit d2f7bf1

Browse files
author
Eric Kirkham
authored
Merge pull request #1685 from hippware/1628
Addresses #1628, #1639
2 parents bf103d7 + 21dde84 commit d2f7bf1

File tree

8 files changed

+35
-6
lines changed

8 files changed

+35
-6
lines changed

src/components/ListFooter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Props = {
1212
};
1313

1414
const ListFooter = observer(({footerImage, finished, style}: Props) => (
15-
<View style={[{...style}, {paddingTop: 10, alignItems: 'center', paddingBottom: 21}]}>{finished ? <Image source={footerImage} /> : <Spinner />}</View>
15+
<View style={[{...style}, {paddingTop: 10, alignItems: 'center', paddingBottom: 21}]}>{finished ? footerImage ? <Image source={footerImage} /> : null : <Spinner />}</View>
1616
));
1717

1818
export default ListFooter;

src/components/Router.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const TinyRobotRouter = () => (
188188
<Scene key='botAddress' component={BotAddressScene} clone back title='Edit Location' />
189189
<Scene key='profileDetails' component={ProfileDetail} clone back navTransparent={false} />
190190
<Scene key='myAccount' component={MyAccount} editMode clone back />
191-
<Scene key='followers' component={peopleLists.FollowersList} clone title='Followers' back />
191+
<Scene key='followers' path='followers' component={peopleLists.FollowersList} clone title='Followers' back />
192192
<Scene key='following' component={peopleLists.FollowingList} clone title='Following' back />
193193
<Scene key='blocked' component={peopleLists.BlockedList} clone title='Blocked Users' back right={() => null} />
194194
</Stack>

src/components/people-lists/FollowersList.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import PeopleList from './PeopleList';
1919
import SectionHeader from './SectionHeader';
2020
import {FollowableProfileItem} from './customProfileItems';
2121
import {followersSectionIndex} from '../../utils/friendUtils';
22+
import ListFooter from '../ListFooter';
2223

2324
type Props = {
2425
userId: string,
@@ -39,7 +40,7 @@ class FollowersList extends React.Component<Props> {
3940
};
4041

4142
componentDidMount() {
42-
this.profile = profileStore.create(this.props.userId, null, true);
43+
this.profile = profileStore.create(this.props.userId, null, true) || model.profile;
4344
this.loadFollowers();
4445
}
4546

@@ -53,10 +54,14 @@ class FollowersList extends React.Component<Props> {
5354
const followers = this.profile.isOwn ? model.friends.followers : this.profileList.alphaByHandleList;
5455
const newFollowers = this.profile.isOwn ? model.friends.newFollowers : [];
5556
const followersCount = this.profile.isOwn ? model.friends.followers.length : this.profile.followersSize;
57+
const {connected} = model;
58+
const finished = this.profile.isOwn || this.profileList.finished;
59+
const loading = this.profile.isOwn || this.profileList.loading;
5660
return (
5761
<Screen isDay={location.isDay}>
5862
<PeopleList
5963
renderItem={({item}) => <FollowableProfileItem profile={item} />}
64+
ListFooterComponent={connected && loading ? <ListFooter finished={finished} /> : null}
6065
renderSectionHeader={({section}) => {
6166
return section.key === 'new' ? (
6267
<SectionHeader section={section} title='New Followers' count={section.data.length}>

src/components/people-lists/FollowingList.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import PeopleList from './PeopleList';
1616
import SectionHeader from './SectionHeader';
1717
import {FollowableProfileItem} from './customProfileItems';
1818
import {followingSectionIndex} from '../../utils/friendUtils';
19+
import ListFooter from '../ListFooter';
1920

2021
type Props = {
2122
userId: string,
@@ -49,6 +50,10 @@ class FollowingList extends React.Component {
4950
render() {
5051
if (!this.profile) return null;
5152
const following = this.profile.isOwn ? model.friends.following : this.profileList.alphaByHandleList;
53+
const followedCount = this.profile.isOwn ? model.friends.following.length : this.profile.followedSize;
54+
const {connected} = model;
55+
const finished = this.profile.isOwn || this.profileList.finished;
56+
const loading = this.profile.isOwn || this.profileList.loading;
5257
return (
5358
<Screen>
5459
<PeopleList
@@ -62,8 +67,9 @@ class FollowingList extends React.Component {
6267
autoCapitalize='none'
6368
/>
6469
}
70+
ListFooterComponent={connected && loading ? <ListFooter finished={finished} /> : null}
6571
renderItem={({item}) => <FollowableProfileItem profile={item} />}
66-
renderSectionHeader={({section}) => <SectionHeader section={section} title='Following' count={this.profile.followedSize} />}
72+
renderSectionHeader={({section}) => <SectionHeader section={section} title='Following' count={followedCount} />}
6773
sections={followingSectionIndex(this.searchText, following)}
6874
loadMore={this.loadFollowing}
6975
/>

src/components/people-lists/SectionHeader.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {StyleSheet, View} from 'react-native';
55
import {k} from '../Global';
66
import {colors} from '../../constants';
77
import {RText} from '../common';
8+
import {observer} from 'mobx-react/native';
89

910
type Props = {
1011
section: Object,
@@ -13,7 +14,7 @@ type Props = {
1314
count: number,
1415
};
1516

16-
const SectionHeader = ({section, title, children, count}: Props) => (
17+
const SectionHeader = observer(({section, title, children, count}: Props) => (
1718
<View style={styles.headerBar} key={section.key}>
1819
<RText size={13}>
1920
<RText size={16} weight='Bold'>
@@ -23,7 +24,7 @@ const SectionHeader = ({section, title, children, count}: Props) => (
2324
</RText>
2425
{children}
2526
</View>
26-
);
27+
));
2728

2829
export default SectionHeader;
2930

src/model/FriendList.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import assert from 'assert';
88
export default class FriendList {
99
@observable _list: IObservableArray<Profile> = [];
1010
lastId: ?string = null;
11+
@observable loading = false;
12+
@observable finished = false;
1113

1214
@computed
1315
get list(): Profile[] {

src/store/friendStore.js

+12
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ class FriendStore {
119119
assert(userId, 'User id should not be null');
120120
assert(profileList, 'Profile list should not be null');
121121
assert(relation, 'Relation type must be defined');
122+
if (profileList.loading) {
123+
return;
124+
}
125+
if (profileList.finished) {
126+
return;
127+
}
128+
profileList.loading = true;
122129

123130
const iq = $iq({
124131
type: 'get',
@@ -164,9 +171,14 @@ class FriendStore {
164171
profileList.add(profileToAdd);
165172
});
166173
profileList.lastId = stanza.contacts.set.last;
174+
if (profileList.length === parseInt(stanza.contacts.set.count)) {
175+
profileList.finished = true;
176+
}
167177
}
168178
} catch (error) {
169179
log.log('REQUEST RELATIONS error:', error, {level: log.levels.ERROR});
180+
} finally {
181+
profileList.loading = false;
170182
}
171183
};
172184

src/store/profileStore.js

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class ProfileStore {
6666

6767
@action
6868
create = (user: string, data?: Object, force?: boolean): Profile => {
69+
if (!user) {
70+
return null;
71+
}
6972
return factory.create(user, data, force);
7073
};
7174

0 commit comments

Comments
 (0)