DiscoverComponent.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div class="container">
  3. <section class="mb-5 section-people">
  4. <p class="lead text-muted font-weight-bold mb-0">Discover People</p>
  5. <div class="loader text-center">
  6. <div class="lds-ring"><div></div><div></div><div></div><div></div></div>
  7. </div>
  8. <div class="row d-none">
  9. <div class="col-4 p-0 p-sm-2 p-md-3" v-for="profile in people">
  10. <div class="card card-md-border-0">
  11. <div class="card-body p-4 text-center">
  12. <div class="avatar pb-3">
  13. <a :href="profile.url">
  14. <img :src="profile.avatar" class="img-thumbnail rounded-circle" width="64px">
  15. </a>
  16. </div>
  17. <p class="lead font-weight-bold mb-0 text-truncate"><a :href="profile.url" class="text-dark">{{profile.username}}</a></p>
  18. <p class="text-muted text-truncate">{{profile.name}}</p>
  19. <button class="btn btn-primary font-weight-bold px-4 py-0" v-on:click="followUser(profile.id, $event)">Follow</button>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. </section>
  25. <section class="mb-5 section-explore">
  26. <p class="lead text-muted font-weight-bold mb-0">Explore</p>
  27. <div class="profile-timeline">
  28. <div class="loader text-center">
  29. <div class="lds-ring"><div></div><div></div><div></div><div></div></div>
  30. </div>
  31. <div class="row d-none">
  32. <div class="col-4 p-0 p-sm-2 p-md-3" v-for="post in posts">
  33. <a class="card info-overlay card-md-border-0" :href="post.url">
  34. <div class="square filter_class">
  35. <div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }"></div>
  36. </div>
  37. </a>
  38. </div>
  39. </div>
  40. </div>
  41. </section>
  42. <section class="mb-5">
  43. <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>
  44. </section>
  45. </div>
  46. </template>
  47. <script type="text/javascript">
  48. export default {
  49. data() {
  50. return {
  51. people: {},
  52. posts: {},
  53. trending: {}
  54. }
  55. },
  56. mounted() {
  57. this.fetchData();
  58. },
  59. methods: {
  60. followUser(id, event) {
  61. axios.post('/i/follow', {
  62. item: id
  63. }).then(res => {
  64. let el = $(event.target);
  65. el.addClass('btn-outline-secondary').removeClass('btn-primary');
  66. el.text('Unfollow');
  67. }).catch(err => {
  68. swal(
  69. 'Whoops! Something went wrong...',
  70. 'An error occured, please try again later.',
  71. 'error'
  72. );
  73. });
  74. },
  75. fetchData() {
  76. axios.get('/api/v2/discover/people')
  77. .then((res) => {
  78. let data = res.data;
  79. this.people = data.people;
  80. if(this.people.length > 1) {
  81. $('.section-people .loader').hide();
  82. $('.section-people .row.d-none').removeClass('d-none');
  83. }
  84. });
  85. axios.get('/api/v2/discover/posts')
  86. .then((res) => {
  87. let data = res.data;
  88. this.posts = data.posts;
  89. if(this.posts.length > 1) {
  90. $('.section-explore .loader').hide();
  91. $('.section-explore .row.d-none').removeClass('d-none');
  92. }
  93. });
  94. }
  95. }
  96. }
  97. </script>