DiscoverComponent.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 px-0 border-top-0 mx-n3">
  8. <input class="form-control rounded-0" placeholder="Search" v-model="searchTerm" v-on:keyup.enter="searchSubmit">
  9. </div>
  10. <section class="d-none d-md-flex mb-md-2 pt-5 discover-bar" style="width:auto; overflow: auto hidden;" v-if="categories.length > 0">
  11. <a v-if="config.ab.loops == true" class="text-decoration-none bg-transparent border border-success rounded d-inline-flex align-items-center justify-content-center mr-3 card-disc" href="/discover/loops">
  12. <p class="text-success lead font-weight-bold mb-0">Loops</p>
  13. </a>
  14. <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+');'">
  15. <p class="text-white font-weight-bold" style="text-shadow: 3px 3px 16px #272634;">{{category.name}}</p>
  16. </a>
  17. </section>
  18. <section class="mb-5 section-explore">
  19. <div class="profile-timeline">
  20. <div class="row p-0">
  21. <div class="col-4 p-1 p-sm-2 p-md-3" v-for="post in posts">
  22. <a class="card info-overlay card-md-border-0" :href="post.url">
  23. <div class="square">
  24. <span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  25. <span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  26. <span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  27. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
  28. </div>
  29. </div>
  30. </a>
  31. </div>
  32. </div>
  33. </div>
  34. </section>
  35. <section class="mb-5">
  36. <p class="lead text-center">To view more posts, check the <a href="/" class="font-weight-bold">home</a> or <a href="/timeline/public" class="font-weight-bold">local</a> timelines.</p>
  37. </section>
  38. </div>
  39. </div>
  40. </template>
  41. <style type="text/css" scoped>
  42. .discover-bar::-webkit-scrollbar {
  43. display: none;
  44. }
  45. .card-disc {
  46. flex: 0 0 160px;
  47. width:160px;
  48. height:100px;
  49. background-size: cover !important;
  50. }
  51. .post-icon {
  52. color: #fff;
  53. position:relative;
  54. margin-top: 10px;
  55. z-index: 9;
  56. opacity: 0.6;
  57. text-shadow: 3px 3px 16px #272634;
  58. }
  59. </style>
  60. <script type="text/javascript">
  61. export default {
  62. data() {
  63. return {
  64. loaded: false,
  65. config: window.App.config,
  66. posts: {},
  67. trending: {},
  68. categories: {},
  69. allCategories: {},
  70. searchTerm: '',
  71. }
  72. },
  73. mounted() {
  74. this.fetchData();
  75. this.fetchCategories();
  76. },
  77. methods: {
  78. fetchData() {
  79. axios.get('/api/v2/discover/posts')
  80. .then((res) => {
  81. this.posts = res.data.posts;
  82. this.loaded = true;
  83. });
  84. },
  85. fetchCategories() {
  86. axios.get('/api/v2/discover/categories')
  87. .then(res => {
  88. this.allCategories = res.data;
  89. this.categories = res.data;
  90. });
  91. },
  92. searchSubmit() {
  93. if(this.searchTerm.length > 1) {
  94. window.location.href = '/i/results?q=' + this.searchTerm;
  95. }
  96. }
  97. }
  98. }
  99. </script>