DiscoverComponent.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div class="container">
  3. <section class="d-none d-md-flex mb-md-2 pt-2 discover-bar" style="width:auto; overflow: auto hidden;" v-if="categories.length > 0">
  4. <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">
  5. <p class="text-success lead font-weight-bold mb-0">Loops</p>
  6. </a>
  7. <!-- <a class="text-decoration-none rounded d-inline-flex align-items-center justify-content-center mr-3 box-shadow card-disc" href="/discover/personal" style="background: rgb(255, 95, 109);">
  8. <p class="text-white lead font-weight-bold mb-0">For You</p>
  9. </a> -->
  10. <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" :href="category.url" :style="'background: linear-gradient(rgba(0, 0, 0, 0.3),rgba(0, 0, 0, 0.3)),url('+category.thumb+');'">
  11. <p class="text-white font-weight-bold" style="text-shadow: 3px 3px 16px #272634;">{{category.name}}</p>
  12. </a>
  13. </section>
  14. <section class="mb-5 section-explore">
  15. <div class="profile-timeline">
  16. <div class="loader text-center">
  17. <div class="lds-ring"><div></div><div></div><div></div><div></div></div>
  18. </div>
  19. <div class="row d-none">
  20. <div class="col-4 p-0 p-sm-2 p-md-3" v-for="post in posts">
  21. <a class="card info-overlay card-md-border-0" :href="post.url">
  22. <div class="square">
  23. <span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  24. <span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  25. <span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  26. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
  27. </div>
  28. </div>
  29. </a>
  30. </div>
  31. </div>
  32. </div>
  33. </section>
  34. <section class="mb-5">
  35. <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>
  36. </section>
  37. </div>
  38. </template>
  39. <style type="text/css" scoped>
  40. .discover-bar::-webkit-scrollbar {
  41. display: none;
  42. }
  43. .card-disc {
  44. flex: 0 0 160px;
  45. width:160px;
  46. height:100px;
  47. background-size: cover !important;
  48. }
  49. .post-icon {
  50. color: #fff;
  51. position:relative;
  52. margin-top: 10px;
  53. z-index: 9;
  54. opacity: 0.6;
  55. text-shadow: 3px 3px 16px #272634;
  56. }
  57. </style>
  58. <script type="text/javascript">
  59. export default {
  60. data() {
  61. return {
  62. config: window.App.config,
  63. posts: {},
  64. trending: {},
  65. categories: {},
  66. allCategories: {},
  67. }
  68. },
  69. mounted() {
  70. this.fetchData();
  71. this.fetchCategories();
  72. },
  73. methods: {
  74. followUser(id, event) {
  75. axios.post('/i/follow', {
  76. item: id
  77. }).then(res => {
  78. let el = $(event.target);
  79. el.addClass('btn-outline-secondary').removeClass('btn-primary');
  80. el.text('Unfollow');
  81. }).catch(err => {
  82. if(err.response.data.message) {
  83. swal('Error', err.response.data.message, 'error');
  84. }
  85. });
  86. },
  87. fetchData() {
  88. axios.get('/api/v2/discover/posts')
  89. .then((res) => {
  90. let data = res.data;
  91. this.posts = data.posts;
  92. if(this.posts.length > 1) {
  93. $('.section-explore .loader').hide();
  94. $('.section-explore .row.d-none').removeClass('d-none');
  95. }
  96. });
  97. },
  98. fetchCategories() {
  99. axios.get('/api/v2/discover/categories')
  100. .then(res => {
  101. this.allCategories = res.data;
  102. this.categories = res.data;
  103. });
  104. },
  105. }
  106. }
  107. </script>