DiscoverComponent.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div class="container">
  3. <section class="d-none d-md-flex mb-md-5 pb-md-3 px-2" style="overflow-x: hidden;" v-if="categories.length > 0">
  4. <a class="bg-dark rounded d-inline-flex align-items-end justify-content-center mr-3 box-shadow card-disc" href="/discover/personal">
  5. <p class="text-white font-weight-bold" style="text-shadow: 3px 3px 16px #272634;border-bottom: 2px solid #fff;">For You</p>
  6. </a>
  7. <div v-show="categoryCursor > 5" class="text-dark d-inline-flex align-items-center pr-3" v-on:click="categoryPrev()">
  8. <i class="fas fa-chevron-circle-left fa-lg text-muted"></i>
  9. </div>
  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. <div v-show="allCategories.length != categoryCursor" class="text-dark d-flex align-items-center" v-on:click="categoryNext()">
  14. <i class="fas fa-chevron-circle-right fa-lg text-muted"></i>
  15. </div>
  16. </section>
  17. <section class="mb-5 section-explore">
  18. <div class="profile-timeline">
  19. <div class="loader text-center">
  20. <div class="lds-ring"><div></div><div></div><div></div><div></div></div>
  21. </div>
  22. <div class="row d-none">
  23. <div class="col-4 p-0 p-sm-2 p-md-3" v-for="post in posts">
  24. <a class="card info-overlay card-md-border-0" :href="post.url">
  25. <div class="square filter_class">
  26. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }"></div>
  27. </div>
  28. </a>
  29. </div>
  30. </div>
  31. </div>
  32. </section>
  33. <section class="mb-5">
  34. <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>
  35. </section>
  36. </div>
  37. </template>
  38. <style type="text/css" scoped>
  39. .card-disc {
  40. width:160px;
  41. height:100px;
  42. background-size: cover !important;
  43. }
  44. </style>
  45. <script type="text/javascript">
  46. export default {
  47. data() {
  48. return {
  49. people: {},
  50. posts: {},
  51. trending: {},
  52. categories: {},
  53. allCategories: {},
  54. categoryCursor: 5,
  55. }
  56. },
  57. mounted() {
  58. this.fetchData();
  59. this.fetchCategories();
  60. },
  61. methods: {
  62. followUser(id, event) {
  63. axios.post('/i/follow', {
  64. item: id
  65. }).then(res => {
  66. let el = $(event.target);
  67. el.addClass('btn-outline-secondary').removeClass('btn-primary');
  68. el.text('Unfollow');
  69. }).catch(err => {
  70. swal(
  71. 'Whoops! Something went wrong…',
  72. 'An error occurred, please try again later.',
  73. 'error'
  74. );
  75. });
  76. },
  77. fetchData() {
  78. // axios.get('/api/v2/discover/people')
  79. // .then((res) => {
  80. // let data = res.data;
  81. // this.people = data.people;
  82. // if(this.people.length > 1) {
  83. // $('.section-people .loader').hide();
  84. // $('.section-people .row.d-none').removeClass('d-none');
  85. // }
  86. // });
  87. axios.get('/api/v2/discover/posts')
  88. .then((res) => {
  89. let data = res.data;
  90. this.posts = data.posts;
  91. if(this.posts.length > 1) {
  92. $('.section-explore .loader').hide();
  93. $('.section-explore .row.d-none').removeClass('d-none');
  94. }
  95. });
  96. },
  97. fetchCategories() {
  98. axios.get('/api/v2/discover/categories')
  99. .then(res => {
  100. this.allCategories = res.data;
  101. this.categories = _.slice(res.data, 0, 5);
  102. });
  103. },
  104. categoryNext() {
  105. if(this.categoryCursor > this.allCategories.length - 1) {
  106. return;
  107. }
  108. this.categoryCursor++;
  109. let cursor = this.categoryCursor;
  110. let start = cursor - 5;
  111. let end = cursor;
  112. this.categories = _.slice(this.allCategories, start, end);
  113. },
  114. categoryPrev() {
  115. if(this.categoryCursor == 5) {
  116. return;
  117. }
  118. this.categoryCursor--;
  119. let cursor = this.categoryCursor;
  120. let start = cursor - 5;
  121. let end = cursor;
  122. this.categories = _.slice(this.allCategories, start, end);
  123. },
  124. }
  125. }
  126. </script>