DiscoverComponent.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div>
  3. <div v-if="!loaded" style="height: 70vh;" class="d-flex justify-content-center align-items-center">
  4. <img src="/img/pixelfed-icon-grey.svg">
  5. </div>
  6. <div v-else>
  7. <div class="d-block d-md-none border-top-0 pt-3">
  8. <input class="form-control rounded-pill shadow-sm" placeholder="Search" v-model="searchTerm" v-on:keyup.enter="searchSubmit">
  9. </div>
  10. <section class="mt-3 mb-5 section-explore">
  11. <div class="profile-timeline">
  12. <div class="row p-0 mt-5">
  13. <div class="col-12 mb-3 d-flex justify-content-between align-items-center">
  14. <p class="d-block d-md-none h1 font-weight-bold mb-0">Trending</p>
  15. <p class="d-none d-md-block display-4 font-weight-bold mb-0">Trending</p>
  16. <div>
  17. <div class="btn-group">
  18. <button @click="trendingRangeToggle('daily')" :class="trendingRange == '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'">Daily</button>
  19. <button @click="trendingRangeToggle('monthly')" :class="trendingRange == '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'">Monthly</button>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. <div v-if="!trendingLoading" class="row p-0 d-flex">
  25. <div v-if="trending.length" v-for="(s, index) in trending.slice(0, 12)" class="col-4 p-1 p-sm-2 p-md-3 pt-0">
  26. <a class="card info-overlay card-md-border-0" :href="s.url">
  27. <div class="square">
  28. <div v-if="s.sensitive" class="square-content">
  29. <div class="info-overlay-text-label">
  30. <h5 class="text-white m-auto font-weight-bold">
  31. <span>
  32. <span class="far fa-eye-slash fa-lg p-2 d-flex-inline"></span>
  33. </span>
  34. </h5>
  35. </div>
  36. <blur-hash-canvas
  37. width="32"
  38. height="32"
  39. :hash="s.media_attachments[0].blurhash"
  40. />
  41. </div>
  42. <div v-else class="square-content">
  43. <blur-hash-image
  44. width="32"
  45. height="32"
  46. :hash="s.media_attachments[0].blurhash"
  47. :src="s.media_attachments[0].preview_url"
  48. />
  49. </div>
  50. <span v-if="s.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  51. <span v-if="s.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  52. <span v-if="s.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  53. <div class="info-overlay-text">
  54. <h5 class="text-white m-auto font-weight-bold">
  55. <span>
  56. <span class="far fa-heart fa-lg p-2 d-flex-inline"></span>
  57. <span class="d-flex-inline">{{formatCount(s.favourites_count)}}</span>
  58. </span>
  59. <span>
  60. <span class="far fa-comment fa-lg p-2 d-flex-inline"></span>
  61. <span class="d-flex-inline">{{formatCount(s.reply_count)}}</span>
  62. </span>
  63. </h5>
  64. </div>
  65. </div>
  66. </a>
  67. </div>
  68. <div v-else class="col-12 d-flex align-items-center justify-content-center bg-light border" style="min-height: 40vh;">
  69. <div class="h2">No posts found :(</div>
  70. </div>
  71. </div>
  72. <div v-else class="row d-flex align-items-center justify-content-center bg-light border" style="min-height: 40vh;">
  73. <div class="spinner-border" role="status">
  74. <span class="sr-only">Loading...</span>
  75. </div>
  76. </div>
  77. </div>
  78. </section>
  79. <section class="pt-5 mb-5 section-explore">
  80. <div class="profile-timeline pt-3">
  81. <div class="row p-0 mt-5">
  82. <div class="col-12 mb-3 d-flex justify-content-between align-items-center">
  83. <p class="d-block d-md-none h1 font-weight-bold mb-0">For You</p>
  84. <p class="d-none d-md-block display-4 font-weight-bold mb-0">For You</p>
  85. </div>
  86. </div>
  87. <div v-if="!recommendedLoading" class="row p-0 d-flex">
  88. <div v-if="posts.length" v-for="(s, index) in posts" :key="'rmki:'+index" class="col-4 p-1 p-sm-2 p-md-3 pt-0">
  89. <a class="card info-overlay card-md-border-0" :href="s.url">
  90. <div class="square">
  91. <div v-if="s.sensitive" class="square-content">
  92. <div class="info-overlay-text-label">
  93. <h5 class="text-white m-auto font-weight-bold">
  94. <span>
  95. <span class="far fa-eye-slash fa-lg p-2 d-flex-inline"></span>
  96. </span>
  97. </h5>
  98. </div>
  99. <blur-hash-canvas
  100. width="32"
  101. height="32"
  102. :hash="s.media_attachments[0].blurhash"
  103. />
  104. </div>
  105. <div v-else class="square-content">
  106. <blur-hash-image
  107. width="32"
  108. height="32"
  109. :hash="s.media_attachments[0].blurhash"
  110. :src="s.media_attachments[0].preview_url"
  111. />
  112. </div>
  113. <span v-if="s.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  114. <span v-if="s.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  115. <span v-if="s.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  116. <div class="info-overlay-text">
  117. <h5 class="text-white m-auto font-weight-bold">
  118. <span>
  119. <span class="far fa-heart fa-lg p-2 d-flex-inline"></span>
  120. <span class="d-flex-inline">{{formatCount(s.favourites_count)}}</span>
  121. </span>
  122. <span>
  123. <span class="far fa-comment fa-lg p-2 d-flex-inline"></span>
  124. <span class="d-flex-inline">{{formatCount(s.reply_count)}}</span>
  125. </span>
  126. </h5>
  127. </div>
  128. </div>
  129. </a>
  130. </div>
  131. <div v-else class="col-12 d-flex align-items-center justify-content-center bg-light border" style="min-height: 40vh;">
  132. <div class="h2">No posts found :(</div>
  133. </div>
  134. </div>
  135. <div v-else class="row d-flex align-items-center justify-content-center bg-light border" style="min-height: 40vh;">
  136. <div class="spinner-border" role="status">
  137. <span class="sr-only">Loading...</span>
  138. </div>
  139. </div>
  140. </div>
  141. </section>
  142. </div>
  143. </div>
  144. </template>
  145. <script type="text/javascript">
  146. export default {
  147. data() {
  148. return {
  149. loaded: false,
  150. config: window.App.config,
  151. posts: {},
  152. trending: {},
  153. trendingDaily: {},
  154. trendingMonthly: {},
  155. searchTerm: '',
  156. trendingRange: 'daily',
  157. trendingLoading: true,
  158. recommendedLoading: true
  159. }
  160. },
  161. mounted() {
  162. this.loaded = true;
  163. this.loadTrending();
  164. this.fetchData();
  165. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  166. window._sharedData.curUser = res.data;
  167. window.App.util.navatar();
  168. });
  169. },
  170. methods: {
  171. fetchData() {
  172. if(!this.recommendedLoading) {
  173. return;
  174. }
  175. axios.get('/api/pixelfed/v2/discover/posts')
  176. .then((res) => {
  177. this.posts = res.data.posts;
  178. this.recommendedLoading = false;
  179. });
  180. },
  181. searchSubmit() {
  182. if(this.searchTerm.length > 1) {
  183. window.location.href = '/i/results?q=' + this.searchTerm;
  184. }
  185. },
  186. loadTrending() {
  187. if(this.trendingRange == 'daily' && this.trendingDaily.length) {
  188. this.trending = this.trendingDaily;
  189. this.trendingLoading = false;
  190. }
  191. if(this.trendingRange == 'monthly' && this.trendingMonthly.length) {
  192. this.trending = this.trendingMonthly;
  193. this.trendingLoading = false;
  194. }
  195. axios.get('/api/pixelfed/v2/discover/posts/trending', {
  196. params: {
  197. range: this.trendingRange
  198. }
  199. })
  200. .then(res => {
  201. if(this.trendingRange == 'daily') {
  202. this.trendingDaily = res.data.filter(t => t.sensitive == false);
  203. }
  204. if(this.trendingRange == 'monthly') {
  205. this.trendingMonthly = res.data.filter(t => t.sensitive == false);
  206. }
  207. this.trending = res.data;
  208. this.trendingLoading = false;
  209. });
  210. },
  211. trendingRangeToggle(r) {
  212. this.trendingLoading = true;
  213. this.trendingRange = r;
  214. this.loadTrending();
  215. },
  216. formatCount(s) {
  217. return App.util.format.count(s);
  218. }
  219. }
  220. }
  221. </script>