|
@@ -34,15 +34,22 @@ export class HomePage {
|
|
|
ionViewDidEnter() {
|
|
|
this.twitter
|
|
|
.fetchHomeFeed()
|
|
|
- .then(res => (this.data = this.data.concat(res.data)));
|
|
|
+ .then(
|
|
|
+ res =>
|
|
|
+ (this.data = this.data
|
|
|
+ .concat(res.data)
|
|
|
+ .sort((a, b) => this.sortByDateAsc(a, b)))
|
|
|
+ );
|
|
|
this.gun
|
|
|
.getLastTweetFromUser("username")
|
|
|
.then(hash => this.ipfs.fetchTweet(hash))
|
|
|
.then(tweet => this.addUserObject(tweet))
|
|
|
- .then(res => {
|
|
|
- this.data = this.data.concat(res);
|
|
|
- console.log(this.data, res);
|
|
|
- });
|
|
|
+ .then(
|
|
|
+ res =>
|
|
|
+ (this.data = this.data
|
|
|
+ .concat(res)
|
|
|
+ .sort((a, b) => this.sortByDateAsc(a, b)))
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
doRefresh(refresher) {
|
|
@@ -57,7 +64,9 @@ export class HomePage {
|
|
|
this.twitter
|
|
|
.fetchHomeFeedSince(this.data[this.data.length - 1].id)
|
|
|
.then(res => {
|
|
|
- this.data = this.data.concat(res.data);
|
|
|
+ this.data = this.data
|
|
|
+ .concat(res.data)
|
|
|
+ .sort((a, b) => this.sortByDateAsc(a, b));
|
|
|
infiniteScroll.complete();
|
|
|
});
|
|
|
}
|
|
@@ -70,4 +79,17 @@ export class HomePage {
|
|
|
tweet.user = await this.twitter.fetchUser(tweet.user_id);
|
|
|
return tweet;
|
|
|
}
|
|
|
+
|
|
|
+ private sortByDateAsc(a, b) {
|
|
|
+ const dateA = new Date(a.created_at);
|
|
|
+ const dateB = new Date(b.created_at);
|
|
|
+
|
|
|
+ if (dateA > dateB) {
|
|
|
+ return -1;
|
|
|
+ } else if (dateA < dateB) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|