DiscoverFeed.vue 8.2 KB

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