DiscoverComponent.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 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 filter_class">
  23. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }"></div>
  24. </div>
  25. </a>
  26. </div>
  27. </div>
  28. </div>
  29. </section>
  30. <section class="mb-5">
  31. <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>
  32. </section>
  33. </div>
  34. </template>
  35. <style type="text/css" scoped>
  36. .discover-bar::-webkit-scrollbar {
  37. display: none;
  38. }
  39. .card-disc {
  40. flex: 0 0 160px;
  41. width:160px;
  42. height:100px;
  43. background-size: cover !important;
  44. }
  45. </style>
  46. <script type="text/javascript">
  47. export default {
  48. data() {
  49. return {
  50. posts: {},
  51. trending: {},
  52. categories: {},
  53. allCategories: {},
  54. }
  55. },
  56. mounted() {
  57. this.fetchData();
  58. this.fetchCategories();
  59. },
  60. methods: {
  61. followUser(id, event) {
  62. axios.post('/i/follow', {
  63. item: id
  64. }).then(res => {
  65. let el = $(event.target);
  66. el.addClass('btn-outline-secondary').removeClass('btn-primary');
  67. el.text('Unfollow');
  68. }).catch(err => {
  69. if(err.response.data.message) {
  70. swal('Error', err.response.data.message, 'error');
  71. }
  72. });
  73. },
  74. fetchData() {
  75. axios.get('/api/v2/discover/posts')
  76. .then((res) => {
  77. let data = res.data;
  78. this.posts = data.posts;
  79. if(this.posts.length > 1) {
  80. $('.section-explore .loader').hide();
  81. $('.section-explore .row.d-none').removeClass('d-none');
  82. }
  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. }
  93. }
  94. </script>