Explore.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div class="landing-explore-component">
  3. <section class="page-wrapper">
  4. <div class="container container-compact">
  5. <div class="card bg-bluegray-900" style="border-radius: 10px;">
  6. <div class="card-header bg-bluegray-800 nav-menu" style="border-top-left-radius: 10px; border-top-right-radius: 10px;">
  7. <ul class="nav justify-content-around">
  8. <li class="nav-item">
  9. <router-link to="/" class="nav-link">About</router-link>
  10. </li>
  11. <li v-if="config.show_directory" class="nav-item">
  12. <router-link to="/web/directory" class="nav-link">Directory</router-link>
  13. </li>
  14. <li v-if="config.show_explore_feed" class="nav-item">
  15. <router-link to="/web/explore" class="nav-link">Explore</router-link>
  16. </li>
  17. </ul>
  18. </div>
  19. <div class="card-body">
  20. <div class="py-3">
  21. <p class="lead text-center">Explore trending posts</p>
  22. </div>
  23. <div v-if="loading" class="d-flex justify-content-center align-items-center" style="min-height: 500px;">
  24. <b-spinner />
  25. </div>
  26. <div v-else class="feed-list">
  27. <post-card
  28. v-for="post in feed"
  29. :key="post.id"
  30. :post="post"
  31. :range="ranges[rangeIndex]" />
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. <footer-component />
  37. </section>
  38. </div>
  39. </template>
  40. <script type="text/javascript">
  41. import PostCard from './partials/PostCard';
  42. export default {
  43. components: {
  44. "post-card": PostCard
  45. },
  46. data() {
  47. return {
  48. loading: true,
  49. config: window.pfl,
  50. isFetching: false,
  51. range: 'daily',
  52. ranges: ['daily', 'monthly', 'yearly'],
  53. rangeIndex: 0,
  54. feed: [],
  55. }
  56. },
  57. beforeMount() {
  58. if(this.config.show_explore_feed == false) {
  59. this.$router.push('/');
  60. }
  61. },
  62. mounted() {
  63. this.init();
  64. },
  65. methods: {
  66. init() {
  67. axios.get('/api/pixelfed/v2/discover/posts/trending?range=daily')
  68. .then(res => {
  69. if(res && res.data.length > 3) {
  70. this.feed = res.data;
  71. this.loading = false;
  72. } else {
  73. this.rangeIndex++;
  74. this.fetchTrending();
  75. }
  76. })
  77. },
  78. fetchTrending() {
  79. if(this.isFetching || this.rangeIndex >= 3) {
  80. return;
  81. }
  82. this.isFetching = true;
  83. axios.get('/api/pixelfed/v2/discover/posts/trending', {
  84. params: {
  85. range: this.ranges[this.rangeIndex]
  86. }
  87. })
  88. .then(res => {
  89. if(res && res.data.length) {
  90. if(this.rangeIndex == 2 && res.data.length > 3) {
  91. this.feed = res.data;
  92. this.loading = false;
  93. } else {
  94. this.rangeIndex++;
  95. this.isFetching = false;
  96. this.fetchTrending();
  97. }
  98. } else {
  99. this.rangeIndex++;
  100. this.isFetching = false;
  101. this.fetchTrending();
  102. }
  103. })
  104. }
  105. }
  106. }
  107. </script>