search-results-tweets-popular.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { Component } from "@angular/core";
  2. import {
  3. IonicPage,
  4. NavController,
  5. NavParams,
  6. Refresher,
  7. InfiniteScroll,
  8. Events
  9. } from "ionic-angular";
  10. @IonicPage()
  11. @Component({
  12. selector: "page-search-results-tweets-popular",
  13. templateUrl: "search-results-tweets-popular.html"
  14. })
  15. export class SearchResultsTweetsPopularPage {
  16. query: string;
  17. tweets = [];
  18. constructor(
  19. public navCtrl: NavController,
  20. public navParams: NavParams,
  21. private events: Events
  22. ) {
  23. this.query = this.navParams.data;
  24. this.events.subscribe("query:changed", query => {
  25. if (query.length) {
  26. // this.twitter
  27. // .searchPopularTweets(query)
  28. // .then(res => (this.tweets = res));
  29. // this.query = query;
  30. }
  31. });
  32. }
  33. async ionViewDidLoad() {
  34. if (this.query.length) {
  35. // this.tweets = await this.twitter.searchPopularTweets(this.query);
  36. }
  37. }
  38. doRefresh(refresher: Refresher) {
  39. // this.twitter.searchPopularTweets(this.query).then(tweets => {
  40. // this.tweets = tweets;
  41. // refresher.complete();
  42. // });
  43. }
  44. loadMore(infiniteScroll: InfiniteScroll) {
  45. // this.twitter
  46. // .searchPopularTweets(this.query, this.oldestTweet)
  47. // .then(tweets => {
  48. // this.tweets["statuses"] = this.tweets["statuses"].concat(
  49. // tweets["statuses"]
  50. // );
  51. // infiniteScroll.complete();
  52. // });
  53. }
  54. get oldestTweet() {
  55. if (this.tweets.length > 0) {
  56. return this.tweets.reduce((acc, cur) => (acc.id < cur.id ? acc : cur))[
  57. "id_str"
  58. ];
  59. } else {
  60. return undefined;
  61. }
  62. }
  63. get enableRefresh() {
  64. return this.query.length > 0;
  65. }
  66. get enableInfiniteScroll() {
  67. return this.query.length > 0;
  68. }
  69. }