DiscoverComponent.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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="(post, 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="post.url">
  41. <div class="square">
  42. <span v-if="post.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  43. <span v-if="post.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  44. <span v-if="post.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  45. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.media_attachments[0].preview_url + ')' }">
  46. </div>
  47. </div>
  48. </a>
  49. </div>
  50. </div>
  51. </div>
  52. </section>
  53. <section v-if="categories.length > 0" class="mb-5 section-explore">
  54. <div class="profile-timeline pt-3">
  55. <div class="row p-0 mt-5">
  56. <div class="col-12 mb-4 d-flex justify-content-between align-items-center">
  57. <p class="d-block d-md-none h1 font-weight-bold mb-0">Categories</p>
  58. <p class="d-none d-md-block display-4 font-weight-bold mb-0">Categories</p>
  59. </div>
  60. </div>
  61. <section class="d-none d-md-flex mb-md-2 discover-bar" style="width:auto; overflow: auto hidden;">
  62. <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+');'">
  63. <p class="text-white font-weight-bold" style="text-shadow: 3px 3px 16px #272634;">{{category.name}}</p>
  64. </a>
  65. </section>
  66. </div>
  67. </section>
  68. <section v-if="categories.length > 0" class="py-5 mb-5 section-explore bg-warning rounded">
  69. <div class="profile-timeline py-3">
  70. <div class="row p-0 my-5">
  71. <div class="col-12 mb-3 text-center text-dark">
  72. <p class="d-none d-md-block display-3 font-weight-bold">Discover. Categories.</p>
  73. <p class="d-block d-md-none h1 font-weight-bold">Discover. Categories.</p>
  74. <p class="h4 font-weight-light mb-0">Discover amazing posts, people, places and hashtags.</p>
  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">Spotlight</p>
  84. <p class="d-none d-md-block display-4 font-weight-bold mb-0">Spotlight</p>
  85. <div>
  86. <div class="btn-group">
  87. <button class="btn btn-danger py-1 font-weight-bold px-3 text-uppercase btn-sm">Today</button>
  88. <button class="btn btn-outline-danger py-1 font-weight-bold px-3 text-uppercase btn-sm">Yesterday</button>
  89. </div>
  90. </div>
  91. </div> -->
  92. <!-- <div class="col-12 col-md-6">
  93. <div class="mb-4">
  94. <a class="card info-overlay card-md-border-0" :href="posts[10].url">
  95. <div class="square">
  96. <span v-if="posts[10].type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  97. <span v-if="posts[10].type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  98. <span v-if="posts[10].type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  99. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + posts[10].thumb + ')' }">
  100. </div>
  101. </div>
  102. </a>
  103. </div>
  104. </div>
  105. <div class="col-12 col-md-6 row p-0 m-0">
  106. <div v-for="(post, index) in posts.slice(11,15)" class="col-6" style="margin-bottom:1.8rem;">
  107. <a class="card info-overlay card-md-border-0" :href="post.url">
  108. <div class="square">
  109. <span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  110. <span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  111. <span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  112. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
  113. </div>
  114. </div>
  115. </a>
  116. </div>
  117. </div> -->
  118. <div class="col-12 mb-3 d-flex justify-content-between align-items-center">
  119. <p class="d-block d-md-none h1 font-weight-bold mb-0">For You</p>
  120. <p class="d-none d-md-block display-4 font-weight-bold mb-0">For You</p>
  121. </div>
  122. </div>
  123. <div class="row p-0" style="display: flex;">
  124. <div v-for="(post, index) in posts" class="col-4 p-1 p-sm-2 p-md-3 pt-0">
  125. <a class="card info-overlay card-md-border-0" :href="post.url">
  126. <div class="square">
  127. <span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  128. <span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  129. <span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  130. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
  131. </div>
  132. </div>
  133. </a>
  134. </div>
  135. </div>
  136. </div>
  137. </section>
  138. <!-- <section class="pt-5 mb-5 section-explore">
  139. <div class="profile-timeline pt-3">
  140. <div class="row p-0 mt-5">
  141. <div class="col-12 mb-3 d-flex justify-content-between align-items-center">
  142. <p class="display-4 font-weight-bold mb-0">Recommended</p>
  143. <!-- <div>
  144. <div class="btn-group">
  145. <button class="btn btn-dark py-1 font-weight-bold px-3 text-uppercase btn-sm">Today</button>
  146. <button class="btn btn-outline-secondary py-1 font-weight-bold px-3 text-uppercase btn-sm">Weekly</button>
  147. <button class="btn btn-outline-secondary py-1 font-weight-bold px-3 text-uppercase btn-sm">Monthly</button>
  148. </div>
  149. </div> - - ->
  150. </div>
  151. <div class="col-12 col-md-6">
  152. <div class="mb-4">
  153. <a class="card info-overlay card-md-border-0" :href="posts[20].url">
  154. <div class="square">
  155. <span v-if="posts[20].type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  156. <span v-if="posts[20].type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  157. <span v-if="posts[20].type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  158. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + posts[20].thumb + ')' }">
  159. </div>
  160. </div>
  161. </a>
  162. </div>
  163. </div>
  164. <div class="col-12 col-md-6 row p-0 m-0">
  165. <div v-for="(post, index) in posts.slice(21,25)" class="col-6" style="margin-bottom:1.8rem;">
  166. <a class="card info-overlay card-md-border-0" :href="post.url">
  167. <div class="square">
  168. <span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  169. <span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  170. <span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  171. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
  172. </div>
  173. </div>
  174. </a>
  175. </div>
  176. </div>
  177. </div>
  178. <div class="row p-0" style="display: flex;">
  179. <div v-for="(post, index) in posts.slice(25, 29)" class="col-3 p-1 p-sm-2 p-md-3 pt-0">
  180. <a class="card info-overlay card-md-border-0" :href="post.url">
  181. <div class="square">
  182. <span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  183. <span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  184. <span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  185. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
  186. </div>
  187. </div>
  188. </a>
  189. </div>
  190. </div>
  191. </div>
  192. </section> -->
  193. </div>
  194. </div>
  195. </template>
  196. <style type="text/css" scoped>
  197. .discover-bar::-webkit-scrollbar {
  198. display: none;
  199. }
  200. .card-disc {
  201. flex: 0 0 160px;
  202. width:160px;
  203. height:100px;
  204. background-size: cover !important;
  205. }
  206. .post-icon {
  207. color: #fff;
  208. position:relative;
  209. margin-top: 10px;
  210. z-index: 9;
  211. opacity: 0.6;
  212. text-shadow: 3px 3px 16px #272634;
  213. }
  214. </style>
  215. <script type="text/javascript">
  216. export default {
  217. data() {
  218. return {
  219. loaded: false,
  220. config: window.App.config,
  221. posts: {},
  222. hashtags: {},
  223. places: {},
  224. trending: {},
  225. trendingDaily: {},
  226. trendingMonthly: {},
  227. categories: {},
  228. allCategories: {},
  229. searchTerm: '',
  230. trendingRange: 'daily'
  231. }
  232. },
  233. mounted() {
  234. this.fetchData();
  235. this.fetchCategories();
  236. this.loadTrending();
  237. this.loadTrendingHashtags();
  238. this.loadTrendingPlaces();
  239. },
  240. methods: {
  241. fetchData() {
  242. axios.get('/api/pixelfed/v2/discover/posts')
  243. .then((res) => {
  244. this.posts = res.data.posts;
  245. this.loaded = true;
  246. });
  247. },
  248. fetchCategories() {
  249. axios.get('/api/v2/discover/categories')
  250. .then(res => {
  251. this.allCategories = res.data;
  252. this.categories = res.data;
  253. });
  254. },
  255. searchSubmit() {
  256. if(this.searchTerm.length > 1) {
  257. window.location.href = '/i/results?q=' + this.searchTerm;
  258. }
  259. },
  260. loadTrending() {
  261. if(this.trendingRange == 'daily' && this.trendingDaily.length) {
  262. this.trending = this.trendingDaily;
  263. return;
  264. }
  265. if(this.trendingRange == 'monthly' && this.trendingMonthly.length) {
  266. this.trending = this.trendingMonthly;
  267. return;
  268. }
  269. axios.get('/api/pixelfed/v2/discover/posts/trending', {
  270. params: {
  271. range: this.trendingRange
  272. }
  273. })
  274. .then(res => {
  275. if(this.trendingRange == 'daily') {
  276. this.trendingDaily = res.data;
  277. }
  278. if(this.trendingRange == 'monthly') {
  279. this.trendingMonthly = res.data;
  280. }
  281. this.trending = res.data;
  282. });
  283. },
  284. trendingRangeToggle(r) {
  285. this.trendingRange = r;
  286. this.loadTrending();
  287. },
  288. loadTrendingHashtags() {
  289. axios.get('/api/pixelfed/v2/discover/posts/hashtags')
  290. .then(res => {
  291. this.hashtags = res.data;
  292. });
  293. },
  294. loadTrendingPlaces() {
  295. axios.get('/api/pixelfed/v2/discover/posts/places')
  296. .then(res => {
  297. this.places = res.data;
  298. });
  299. }
  300. }
  301. }
  302. </script>