DiscoverComponent.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 mt-5">
  21. <div class="col-12 col-md-6">
  22. <div class="mb-4">
  23. <a class="card info-overlay card-md-border-0" :href="posts[0].url">
  24. <div class="square">
  25. <span v-if="posts[0].type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  26. <span v-if="posts[0].type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  27. <span v-if="posts[0].type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  28. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + posts[0].thumb + ')' }">
  29. </div>
  30. </div>
  31. </a>
  32. </div>
  33. </div>
  34. <div class="col-12 col-md-6 row p-0 m-0">
  35. <div v-for="(post, index) in posts.slice(1,5)" class="col-6" style="margin-bottom:1.8rem;">
  36. <a class="card info-overlay card-md-border-0" :href="post.url">
  37. <div class="square">
  38. <span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  39. <span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  40. <span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  41. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
  42. </div>
  43. </div>
  44. </a>
  45. </div>
  46. </div>
  47. </div>
  48. <div class="row p-0" style="display: flex;">
  49. <div v-for="(post, index) in posts.slice(5)" class="col-3 p-1 p-sm-2 p-md-3">
  50. <a class="card info-overlay card-md-border-0" :href="post.url">
  51. <div class="square">
  52. <span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  53. <span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  54. <span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  55. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
  56. </div>
  57. </div>
  58. </a>
  59. </div>
  60. </div>
  61. </div>
  62. </section>
  63. <section class="mb-5">
  64. <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>
  65. </section>
  66. </div>
  67. </div>
  68. </template>
  69. <style type="text/css" scoped>
  70. .discover-bar::-webkit-scrollbar {
  71. display: none;
  72. }
  73. .card-disc {
  74. flex: 0 0 160px;
  75. width:160px;
  76. height:100px;
  77. background-size: cover !important;
  78. }
  79. .post-icon {
  80. color: #fff;
  81. position:relative;
  82. margin-top: 10px;
  83. z-index: 9;
  84. opacity: 0.6;
  85. text-shadow: 3px 3px 16px #272634;
  86. }
  87. </style>
  88. <script type="text/javascript">
  89. export default {
  90. data() {
  91. return {
  92. loaded: false,
  93. config: window.App.config,
  94. posts: {},
  95. trending: {},
  96. categories: {},
  97. allCategories: {},
  98. searchTerm: '',
  99. }
  100. },
  101. mounted() {
  102. this.fetchData();
  103. this.fetchCategories();
  104. },
  105. methods: {
  106. fetchData() {
  107. axios.get('/api/pixelfed/v2/discover/posts')
  108. .then((res) => {
  109. this.posts = res.data.posts;
  110. this.loaded = true;
  111. });
  112. },
  113. fetchCategories() {
  114. axios.get('/api/v2/discover/categories')
  115. .then(res => {
  116. this.allCategories = res.data;
  117. this.categories = res.data;
  118. });
  119. },
  120. searchSubmit() {
  121. if(this.searchTerm.length > 1) {
  122. window.location.href = '/i/results?q=' + this.searchTerm;
  123. }
  124. }
  125. }
  126. }
  127. </script>