daily-trending.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div class="discover-daily-trending">
  3. <div class="card bg-stellar">
  4. <div class="card-body m-5">
  5. <div class="row d-flex align-items-center">
  6. <div class="col-12 col-md-5">
  7. <p class="font-default text-light mb-0">Popular and trending posts</p>
  8. <h1 class="display-4 font-default text-white" style="font-weight: 700;">Daily Trending</h1>
  9. <button class="btn btn-outline-light rounded-pill" @click="viewMore()">View more trending posts</button>
  10. </div>
  11. <div class="col-12 col-md-7">
  12. <div v-if="isLoaded" class="row">
  13. <div v-for="(post, index) in trending" class="col-4">
  14. <a :href="post.url" @click.prevent="gotoPost(post.id)">
  15. <img :src="post.media_attachments[0].url" class="shadow m-1" width="170" height="170" style="object-fit: cover;border-radius:8px">
  16. </a>
  17. </div>
  18. </div>
  19. <div v-else class="row">
  20. <div class="col-12 d-flex justify-content-center">
  21. <b-spinner type="grow" variant="light" />
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. </template>
  30. <script type="text/javascript">
  31. export default {
  32. data() {
  33. return {
  34. isLoaded: false,
  35. initialFetch: false,
  36. trending: []
  37. }
  38. },
  39. mounted() {
  40. if(!this.initialFetch) {
  41. this.fetchTrending();
  42. }
  43. },
  44. methods: {
  45. fetchTrending() {
  46. axios.get('/api/pixelfed/v2/discover/posts/trending', {
  47. params: {
  48. range: 'daily'
  49. }
  50. })
  51. .then(res => {
  52. this.trending = res.data.filter(p => p.pf_type === 'photo').slice(0, 9);
  53. this.isLoaded = true;
  54. this.initialFetch = true;
  55. });
  56. },
  57. gotoPost(id) {
  58. this.$router.push('/i/web/post/' + id);
  59. },
  60. viewMore() {
  61. this.$emit('btn-click', 'trending');
  62. }
  63. }
  64. }
  65. </script>
  66. <style lang="scss">
  67. .discover-daily-trending {
  68. .bg-stellar {
  69. background: #7474BF;
  70. background: -webkit-linear-gradient(to right, #348AC7, #7474BF);
  71. background: linear-gradient(to right, #348AC7, #7474BF);
  72. }
  73. .font-default {
  74. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  75. letter-spacing: -0.7px;
  76. }
  77. }
  78. </style>