DiscoverFeed.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div class="discover-feed-component">
  3. <section class="mt-3 mb-5 section-explore">
  4. <div class="profile-timeline">
  5. <div class="row p-0 mt-5">
  6. <div class="col-12 mb-4 d-flex justify-content-between align-items-center flex-column flex-lg-row">
  7. <p class="d-block d-md-none h1 font-weight-bold mb-3 font-default">Trending</p>
  8. <p class="d-none d-md-block display-4 font-weight-bold mb-0 font-default">Trending</p>
  9. <div>
  10. <div class="btn-group trending-range">
  11. <button @click="rangeToggle('daily')" :class="range == 'daily' ? 'btn py-1 font-weight-bold px-3 text-uppercase btn-sm btn-danger':'btn py-1 font-weight-bold px-3 text-uppercase btn-sm btn-outline-danger'">Today</button>
  12. <button @click="rangeToggle('monthly')" :class="range == 'monthly' ? 'btn py-1 font-weight-bold px-3 text-uppercase btn-sm btn-danger':'btn py-1 font-weight-bold px-3 text-uppercase btn-sm btn-outline-danger'">This month</button>
  13. <button @click="rangeToggle('yearly')" :class="range == 'yearly' ? 'btn py-1 font-weight-bold px-3 text-uppercase btn-sm btn-danger':'btn py-1 font-weight-bold px-3 text-uppercase btn-sm btn-outline-danger'">This year</button>
  14. </div>
  15. </div>
  16. </div>
  17. </div>
  18. <div v-if="!loading" class="row p-0 px-lg-3">
  19. <div v-if="trending.length" v-for="(s, index) in trending" class="col-6 col-lg-4 col-xl-3 p-1">
  20. <a class="card info-overlay card-md-border-0" :href="s.url" @click.prevent="goToPost(s)">
  21. <div class="square square-next">
  22. <div v-if="s.sensitive" class="square-content">
  23. <div class="info-overlay-text-label">
  24. <h5 class="text-white m-auto font-weight-bold">
  25. <span>
  26. <span class="far fa-eye-slash fa-lg p-2 d-flex-inline"></span>
  27. </span>
  28. </h5>
  29. </div>
  30. <blur-hash-canvas
  31. width="32"
  32. height="32"
  33. :hash="s.media_attachments[0].blurhash"
  34. />
  35. </div>
  36. <div v-else class="square-content">
  37. <blur-hash-image
  38. width="32"
  39. height="32"
  40. :hash="s.media_attachments[0].blurhash"
  41. :src="s.media_attachments[0].preview_url"
  42. />
  43. </div>
  44. <div class="info-overlay-text">
  45. <div class="text-white m-auto">
  46. <p class="info-overlay-text-field font-weight-bold">
  47. <span class="far fa-heart fa-lg p-2 d-flex-inline"></span>
  48. <span class="d-flex-inline">{{formatCount(s.favourites_count)}}</span>
  49. </p>
  50. <p class="info-overlay-text-field font-weight-bold">
  51. <span class="far fa-comment fa-lg p-2 d-flex-inline"></span>
  52. <span class="d-flex-inline">{{formatCount(s.reply_count)}}</span>
  53. </p>
  54. <p class="mb-0 info-overlay-text-field font-weight-bold">
  55. <span class="far fa-sync fa-lg p-2 d-flex-inline"></span>
  56. <span class="d-flex-inline">{{formatCount(s.reblogs_count)}}</span>
  57. </p>
  58. </div>
  59. </div>
  60. </div>
  61. </a>
  62. </div>
  63. <div v-else class="col-12 d-flex align-items-center justify-content-center bg-light border" style="min-height: 40vh;">
  64. <div class="h2">No posts found :(</div>
  65. </div>
  66. </div>
  67. <div v-else class="row p-0 px-lg-3">
  68. <div class="col-12 d-flex align-items-center justify-content-center" style="min-height: 40vh;">
  69. <b-spinner size="lg" />
  70. </div>
  71. </div>
  72. </div>
  73. </section>
  74. </div>
  75. </template>
  76. <script type="text/javascript">
  77. export default {
  78. props: {
  79. profile: {
  80. type: Object
  81. }
  82. },
  83. data() {
  84. return {
  85. loading: true,
  86. trending: [],
  87. range: 'daily',
  88. breadcrumbItems: [
  89. {
  90. text: 'Discover',
  91. href: '/i/web/discover'
  92. },
  93. {
  94. text: 'Trending',
  95. active: true
  96. }
  97. ]
  98. }
  99. },
  100. mounted() {
  101. this.loadTrending();
  102. },
  103. methods: {
  104. fetchData() {
  105. axios.get('/api/pixelfed/v2/discover/posts')
  106. .then((res) => {
  107. this.posts = res.data.posts.filter(r => r != null);
  108. this.recommendedLoading = false;
  109. });
  110. },
  111. loadTrending() {
  112. this.loading = true;
  113. axios.get('/api/pixelfed/v2/discover/posts/trending', {
  114. params: {
  115. range: this.range
  116. }
  117. })
  118. .then(res => {
  119. let data = res.data.filter(r => {
  120. return r !== null;
  121. });
  122. this.trending = data.filter(t => t.sensitive == false);
  123. if(this.range == 'daily' && data.length == 0) {
  124. this.range = 'yearly';
  125. this.loadTrending();
  126. }
  127. this.loading = false;
  128. });
  129. },
  130. formatCount(s) {
  131. return App.util.format.count(s);
  132. },
  133. goToPost(status) {
  134. this.$router.push({
  135. name: 'post',
  136. params: {
  137. id: status.id,
  138. cachedStatus: status,
  139. cachedProfile: this.profile
  140. }
  141. })
  142. },
  143. rangeToggle(range) {
  144. event.currentTarget.blur();
  145. this.range = range;
  146. this.loadTrending();
  147. }
  148. }
  149. }
  150. </script>
  151. <style lang="scss">
  152. .discover-feed-component {
  153. .font-default {
  154. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  155. letter-spacing: -0.7px;
  156. }
  157. .info-overlay {
  158. border-radius: 15px !important;
  159. }
  160. .square-next {
  161. img,
  162. .info-overlay-text {
  163. border-radius: 15px !important;
  164. }
  165. }
  166. .trending-range {
  167. .btn {
  168. &:hover:not(.btn-danger) {
  169. background-color: #fca5a5
  170. }
  171. }
  172. }
  173. .info-overlay-text-field {
  174. font-size: 13.5px;
  175. margin-bottom: 2px;
  176. @media (min-width: 768px) {
  177. font-size: 20px;
  178. margin-bottom: 15px;
  179. }
  180. }
  181. }
  182. </style>