|
@@ -0,0 +1,69 @@
|
|
|
+import { Component } from "@angular/core";
|
|
|
+import {
|
|
|
+ IonicPage,
|
|
|
+ NavController,
|
|
|
+ NavParams,
|
|
|
+ Refresher,
|
|
|
+ InfiniteScroll
|
|
|
+} from "ionic-angular";
|
|
|
+import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
|
|
|
+
|
|
|
+@IonicPage()
|
|
|
+@Component({
|
|
|
+ selector: "page-search-results-tweets-popular",
|
|
|
+ templateUrl: "search-results-tweets-popular.html"
|
|
|
+})
|
|
|
+export class SearchResultsTweetsPopularPage {
|
|
|
+ keyword: string;
|
|
|
+ tweets = [];
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ public navCtrl: NavController,
|
|
|
+ public navParams: NavParams,
|
|
|
+ private twitter: TwitterApiProvider
|
|
|
+ ) {
|
|
|
+ this.keyword = navParams.data;
|
|
|
+ }
|
|
|
+
|
|
|
+ async ionViewDidLoad() {
|
|
|
+ if (this.keyword.length) {
|
|
|
+ this.tweets = await this.twitter.searchPopularTweets(this.keyword);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ doRefresh(refresher: Refresher) {
|
|
|
+ this.twitter.searchPopularTweets(this.keyword).then(tweets => {
|
|
|
+ this.tweets = tweets;
|
|
|
+ refresher.complete();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ loadMore(infiniteScroll: InfiniteScroll) {
|
|
|
+ this.twitter
|
|
|
+ .searchPopularTweets(this.keyword, this.oldestTweet)
|
|
|
+ .then(tweets => {
|
|
|
+ this.tweets["statuses"] = this.tweets["statuses"].concat(
|
|
|
+ tweets["statuses"]
|
|
|
+ );
|
|
|
+ infiniteScroll.complete();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ get oldestTweet() {
|
|
|
+ if (this.tweets.length > 0) {
|
|
|
+ return this.tweets.reduce((acc, cur) => (acc.id < cur.id ? acc : cur))[
|
|
|
+ "id_str"
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ return undefined;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ get enableRefresh() {
|
|
|
+ return this.keyword.length > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ get enableInfiniteScroll() {
|
|
|
+ return this.keyword.length > 0;
|
|
|
+ }
|
|
|
+}
|