DiscoverComponent.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. <div class="pt-3">
  11. <p class="d-block d-md-none h1 font-weight-bold text-lighter pt-3" style="opacity: 0.4"><i class="far fa-compass"></i> DISCOVER</p>
  12. <p class="d-none d-md-block display-3 font-weight-bold text-lighter pt-3" style="opacity: 0.4"><i class="far fa-compass"></i> DISCOVER</p>
  13. </div>
  14. <section v-if="hashtags.length" class="mb-4 pb-5 section-explore mt-4 pt-4">
  15. <div class="lead">
  16. <i class="fas fa-hashtag text-lighter fa-lg mr-3"></i>
  17. <a v-for="(tag, index) in hashtags" :href="tag.url" class="badge badge-light rounded-pill border py-2 px-3 mr-2 mb-2 shadow-sm border-danger text-danger">{{tag.name}}</a>
  18. </div>
  19. <div class="lead mt-4">
  20. <i class="fas fa-map-marker-alt text-lighter fa-lg mr-3"></i>
  21. <a v-for="(tag, index) in places" :href="tag.url" class="badge badge-light rounded-pill border py-2 px-3 mr-2 mb-2 shadow-sm border-danger text-danger">{{tag.name}}, {{tag.country}}</a>
  22. </div>
  23. </section>
  24. <section v-if="trending.length" class="mb-5 section-explore">
  25. <div class="profile-timeline">
  26. <div class="row p-0 mt-5">
  27. <div class="col-12 mb-3 d-flex justify-content-between align-items-center">
  28. <p class="d-block d-md-none h1 font-weight-bold mb-0">Trending</p>
  29. <p class="d-none d-md-block display-4 font-weight-bold mb-0">Trending</p>
  30. <div>
  31. <div class="btn-group">
  32. <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>
  33. <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>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. <div class="row p-0" style="display: flex;">
  39. <div v-for="(s, index) in trending.slice(0, 12)" class="col-4 p-1 p-sm-2 p-md-3 pt-0">
  40. <a class="card info-overlay card-md-border-0" :href="s.url">
  41. <div class="square">
  42. <div v-if="s.sensitive" class="square-content">
  43. <div class="info-overlay-text-label">
  44. <h5 class="text-white m-auto font-weight-bold">
  45. <span>
  46. <span class="far fa-eye-slash fa-lg p-2 d-flex-inline"></span>
  47. </span>
  48. </h5>
  49. </div>
  50. <blur-hash-canvas
  51. width="32"
  52. height="32"
  53. :hash="s.media_attachments[0].blurhash"
  54. />
  55. </div>
  56. <div v-else class="square-content">
  57. <blur-hash-image
  58. width="32"
  59. height="32"
  60. :hash="s.media_attachments[0].blurhash"
  61. :src="s.media_attachments[0].preview_url"
  62. />
  63. </div>
  64. <span v-if="s.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  65. <span v-if="s.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  66. <span v-if="s.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  67. <div class="info-overlay-text">
  68. <h5 class="text-white m-auto font-weight-bold">
  69. <span>
  70. <span class="far fa-heart fa-lg p-2 d-flex-inline"></span>
  71. <span class="d-flex-inline">{{formatCount(s.favourites_count)}}</span>
  72. </span>
  73. <span>
  74. <span class="far fa-comment fa-lg p-2 d-flex-inline"></span>
  75. <span class="d-flex-inline">{{formatCount(s.reply_count)}}</span>
  76. </span>
  77. </h5>
  78. </div>
  79. </div>
  80. </a>
  81. </div>
  82. </div>
  83. </div>
  84. </section>
  85. <section v-if="categories.length > 0" class="mb-5 section-explore">
  86. <div class="profile-timeline pt-3">
  87. <div class="row p-0 mt-5">
  88. <div class="col-12 mb-4 d-flex justify-content-between align-items-center">
  89. <p class="d-block d-md-none h1 font-weight-bold mb-0">Categories</p>
  90. <p class="d-none d-md-block display-4 font-weight-bold mb-0">Categories</p>
  91. </div>
  92. </div>
  93. <section class="d-none d-md-flex mb-md-2 discover-bar" style="width:auto; overflow: auto hidden;">
  94. <a v-for="(category, index) in categories" :key="index+'_cat_'" class="bg-dark rounded d-inline-flex align-items-end justify-content-center mr-3 box-shadow card-disc text-decoration-none" :href="category.url" :style="'background: linear-gradient(rgba(0, 0, 0, 0.3),rgba(0, 0, 0, 0.3)),url('+category.thumb+');'">
  95. <p class="text-white font-weight-bold" style="text-shadow: 3px 3px 16px #272634;">{{category.name}}</p>
  96. </a>
  97. </section>
  98. </div>
  99. </section>
  100. <section v-if="categories.length > 0" class="py-5 mb-5 section-explore bg-warning rounded">
  101. <div class="profile-timeline py-3">
  102. <div class="row p-0 my-5">
  103. <div class="col-12 mb-3 text-center text-dark">
  104. <p class="d-none d-md-block display-3 font-weight-bold">Discover. Categories.</p>
  105. <p class="d-block d-md-none h1 font-weight-bold">Discover. Categories.</p>
  106. <p class="h4 font-weight-light mb-0">Discover amazing posts, people, places and hashtags.</p>
  107. </div>
  108. </div>
  109. </div>
  110. </section>
  111. <section v-if="posts.length" class="pt-5 mb-5 section-explore">
  112. <div class="profile-timeline pt-3">
  113. <div class="row p-0 mt-5">
  114. <!-- <div class="col-12 mb-3 d-flex justify-content-between align-items-center">
  115. <p class="d-block d-md-none h1 font-weight-bold mb-0">Spotlight</p>
  116. <p class="d-none d-md-block display-4 font-weight-bold mb-0">Spotlight</p>
  117. <div>
  118. <div class="btn-group">
  119. <button class="btn btn-danger py-1 font-weight-bold px-3 text-uppercase btn-sm">Today</button>
  120. <button class="btn btn-outline-danger py-1 font-weight-bold px-3 text-uppercase btn-sm">Yesterday</button>
  121. </div>
  122. </div>
  123. </div> -->
  124. <!-- <div class="col-12 col-md-6">
  125. <div class="mb-4">
  126. <a class="card info-overlay card-md-border-0" :href="posts[10].url">
  127. <div class="square">
  128. <span v-if="posts[10].type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  129. <span v-if="posts[10].type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  130. <span v-if="posts[10].type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  131. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + posts[10].thumb + ')' }">
  132. </div>
  133. </div>
  134. </a>
  135. </div>
  136. </div>
  137. <div class="col-12 col-md-6 row p-0 m-0">
  138. <div v-for="(post, index) in posts.slice(11,15)" class="col-6" style="margin-bottom:1.8rem;">
  139. <a class="card info-overlay card-md-border-0" :href="post.url">
  140. <div class="square">
  141. <span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  142. <span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  143. <span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  144. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
  145. </div>
  146. </div>
  147. </a>
  148. </div>
  149. </div> -->
  150. <div class="col-12 mb-3 d-flex justify-content-between align-items-center">
  151. <p class="d-block d-md-none h1 font-weight-bold mb-0">For You</p>
  152. <p class="d-none d-md-block display-4 font-weight-bold mb-0">For You</p>
  153. </div>
  154. </div>
  155. <div class="row p-0" style="display: flex;">
  156. <div v-for="(s, index) in posts" class="col-4 p-1 p-sm-2 p-md-3 pt-0">
  157. <a class="card info-overlay card-md-border-0" :href="s.url">
  158. <div class="square">
  159. <div v-if="s.sensitive" class="square-content">
  160. <div class="info-overlay-text-label">
  161. <h5 class="text-white m-auto font-weight-bold">
  162. <span>
  163. <span class="far fa-eye-slash fa-lg p-2 d-flex-inline"></span>
  164. </span>
  165. </h5>
  166. </div>
  167. <blur-hash-canvas
  168. width="32"
  169. height="32"
  170. :hash="s.media_attachments[0].blurhash"
  171. />
  172. </div>
  173. <div v-else class="square-content">
  174. <blur-hash-image
  175. width="32"
  176. height="32"
  177. :hash="s.media_attachments[0].blurhash"
  178. :src="s.media_attachments[0].preview_url"
  179. />
  180. </div>
  181. <span v-if="s.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  182. <span v-if="s.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  183. <span v-if="s.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  184. <div class="info-overlay-text">
  185. <h5 class="text-white m-auto font-weight-bold">
  186. <span>
  187. <span class="far fa-heart fa-lg p-2 d-flex-inline"></span>
  188. <span class="d-flex-inline">{{formatCount(s.favourites_count)}}</span>
  189. </span>
  190. <span>
  191. <span class="far fa-comment fa-lg p-2 d-flex-inline"></span>
  192. <span class="d-flex-inline">{{formatCount(s.reply_count)}}</span>
  193. </span>
  194. </h5>
  195. </div>
  196. </div>
  197. </a>
  198. </div>
  199. </div>
  200. </div>
  201. </section>
  202. <!-- <section class="pt-5 mb-5 section-explore">
  203. <div class="profile-timeline pt-3">
  204. <div class="row p-0 mt-5">
  205. <div class="col-12 mb-3 d-flex justify-content-between align-items-center">
  206. <p class="display-4 font-weight-bold mb-0">Recommended</p>
  207. <!-- <div>
  208. <div class="btn-group">
  209. <button class="btn btn-dark py-1 font-weight-bold px-3 text-uppercase btn-sm">Today</button>
  210. <button class="btn btn-outline-secondary py-1 font-weight-bold px-3 text-uppercase btn-sm">Weekly</button>
  211. <button class="btn btn-outline-secondary py-1 font-weight-bold px-3 text-uppercase btn-sm">Monthly</button>
  212. </div>
  213. </div> - - ->
  214. </div>
  215. <div class="col-12 col-md-6">
  216. <div class="mb-4">
  217. <a class="card info-overlay card-md-border-0" :href="posts[20].url">
  218. <div class="square">
  219. <span v-if="posts[20].type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  220. <span v-if="posts[20].type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  221. <span v-if="posts[20].type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  222. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + posts[20].thumb + ')' }">
  223. </div>
  224. </div>
  225. </a>
  226. </div>
  227. </div>
  228. <div class="col-12 col-md-6 row p-0 m-0">
  229. <div v-for="(post, index) in posts.slice(21,25)" class="col-6" style="margin-bottom:1.8rem;">
  230. <a class="card info-overlay card-md-border-0" :href="post.url">
  231. <div class="square">
  232. <span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  233. <span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  234. <span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  235. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
  236. </div>
  237. </div>
  238. </a>
  239. </div>
  240. </div>
  241. </div>
  242. <div class="row p-0" style="display: flex;">
  243. <div v-for="(post, index) in posts.slice(25, 29)" class="col-3 p-1 p-sm-2 p-md-3 pt-0">
  244. <a class="card info-overlay card-md-border-0" :href="post.url">
  245. <div class="square">
  246. <span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  247. <span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  248. <span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  249. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
  250. </div>
  251. </div>
  252. </a>
  253. </div>
  254. </div>
  255. </div>
  256. </section> -->
  257. </div>
  258. </div>
  259. </template>
  260. <style type="text/css" scoped>
  261. .discover-bar::-webkit-scrollbar {
  262. display: none;
  263. }
  264. .card-disc {
  265. flex: 0 0 160px;
  266. width:160px;
  267. height:100px;
  268. background-size: cover !important;
  269. }
  270. .post-icon {
  271. color: #fff;
  272. position:relative;
  273. margin-top: 10px;
  274. z-index: 9;
  275. opacity: 0.6;
  276. text-shadow: 3px 3px 16px #272634;
  277. }
  278. </style>
  279. <script type="text/javascript">
  280. export default {
  281. data() {
  282. return {
  283. loaded: false,
  284. config: window.App.config,
  285. posts: {},
  286. hashtags: {},
  287. places: {},
  288. trending: {},
  289. trendingDaily: {},
  290. trendingMonthly: {},
  291. categories: {},
  292. allCategories: {},
  293. searchTerm: '',
  294. trendingRange: 'daily'
  295. }
  296. },
  297. mounted() {
  298. this.fetchData();
  299. this.fetchCategories();
  300. this.loadTrending();
  301. this.loadTrendingHashtags();
  302. this.loadTrendingPlaces();
  303. },
  304. methods: {
  305. fetchData() {
  306. axios.get('/api/pixelfed/v2/discover/posts')
  307. .then((res) => {
  308. this.posts = res.data.posts;
  309. this.loaded = true;
  310. });
  311. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  312. window._sharedData.curUser = res.data;
  313. window.App.util.navatar();
  314. });
  315. },
  316. fetchCategories() {
  317. axios.get('/api/v2/discover/categories')
  318. .then(res => {
  319. this.allCategories = res.data;
  320. this.categories = res.data;
  321. });
  322. },
  323. searchSubmit() {
  324. if(this.searchTerm.length > 1) {
  325. window.location.href = '/i/results?q=' + this.searchTerm;
  326. }
  327. },
  328. loadTrending() {
  329. if(this.trendingRange == 'daily' && this.trendingDaily.length) {
  330. this.trending = this.trendingDaily;
  331. return;
  332. }
  333. if(this.trendingRange == 'monthly' && this.trendingMonthly.length) {
  334. this.trending = this.trendingMonthly;
  335. return;
  336. }
  337. axios.get('/api/pixelfed/v2/discover/posts/trending', {
  338. params: {
  339. range: this.trendingRange
  340. }
  341. })
  342. .then(res => {
  343. if(this.trendingRange == 'daily') {
  344. this.trendingDaily = res.data.filter(t => t.sensitive == false);
  345. }
  346. if(this.trendingRange == 'monthly') {
  347. this.trendingMonthly = res.data.filter(t => t.sensitive == false);
  348. }
  349. this.trending = res.data;
  350. });
  351. },
  352. trendingRangeToggle(r) {
  353. this.trendingRange = r;
  354. this.loadTrending();
  355. },
  356. loadTrendingHashtags() {
  357. axios.get('/api/pixelfed/v2/discover/posts/hashtags')
  358. .then(res => {
  359. this.hashtags = res.data;
  360. });
  361. },
  362. loadTrendingPlaces() {
  363. axios.get('/api/pixelfed/v2/discover/posts/places')
  364. .then(res => {
  365. this.places = res.data;
  366. });
  367. },
  368. formatCount(s) {
  369. return App.util.format.count(s);
  370. }
  371. }
  372. }
  373. </script>