1
0

Directory.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="landing-directory-component">
  3. <section class="page-wrapper">
  4. <div class="container container-compact">
  5. <div class="card bg-bluegray-900" style="border-radius: 10px;">
  6. <div class="card-header bg-bluegray-800 nav-menu" style="border-top-left-radius: 10px; border-top-right-radius: 10px;">
  7. <ul class="nav justify-content-around">
  8. <li class="nav-item">
  9. <router-link to="/" class="nav-link">About</router-link>
  10. </li>
  11. <li v-if="config.show_directory" class="nav-item">
  12. <router-link to="/web/directory" class="nav-link">Directory</router-link>
  13. </li>
  14. <li v-if="config.show_explore_feed" class="nav-item">
  15. <router-link to="/web/explore" class="nav-link">Explore</router-link>
  16. </li>
  17. </ul>
  18. </div>
  19. <div class="card-body">
  20. <div class="py-3">
  21. <p class="lead text-center">Discover accounts and people</p>
  22. </div>
  23. <div v-if="loading" class="d-flex justify-content-center align-items-center" style="min-height: 500px;">
  24. <b-spinner />
  25. </div>
  26. <div v-else class="feed-list">
  27. <user-card
  28. v-for="account in feed"
  29. :key="account.id"
  30. :account="account" />
  31. <intersect v-if="canLoadMore && !isEmpty" @enter="enterIntersect">
  32. <div class="d-flex justify-content-center pt-5 pb-3">
  33. <b-spinner v-if="isLoadingMore" />
  34. </div>
  35. </intersect>
  36. </div>
  37. <div v-if="isEmpty">
  38. <div class="card card-body bg-bluegray-800">
  39. <div class="d-flex justify-content-center align-items-center flex-column py-5">
  40. <i class="fal fa-clock fa-6x text-bluegray-500"></i>
  41. <p class="lead font-weight-bold mt-3 mb-0">Nothing to show yet! Check back later.</p>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. <footer-component />
  49. </section>
  50. </div>
  51. </template>
  52. <script type="text/javascript">
  53. import UserCard from './partials/UserCard';
  54. import Intersect from 'vue-intersect';
  55. export default {
  56. components: {
  57. "user-card": UserCard,
  58. "intersect": Intersect,
  59. },
  60. data() {
  61. return {
  62. loading: true,
  63. config: window.pfl,
  64. pagination: undefined,
  65. feed: [],
  66. isEmpty: false,
  67. canLoadMore: false,
  68. isIntersecting: false,
  69. isLoadingMore: false
  70. }
  71. },
  72. beforeMount() {
  73. if(this.config.show_directory == false) {
  74. this.$router.push('/');
  75. }
  76. },
  77. mounted() {
  78. this.init();
  79. },
  80. methods: {
  81. init() {
  82. axios.get('/api/landing/v1/directory')
  83. .then(res => {
  84. if(!res.data.data.length) {
  85. this.isEmpty = true;
  86. }
  87. this.feed = res.data.data;
  88. this.pagination = {...res.data.links, ...res.data.meta};
  89. })
  90. .finally(() => {
  91. this.canLoadMore = true;
  92. this.$nextTick(() => {
  93. this.loading = false;
  94. })
  95. })
  96. },
  97. enterIntersect(e) {
  98. if(this.isIntersecting || !this.pagination.next_cursor) {
  99. return;
  100. }
  101. this.isIntersecting = true;
  102. this.isLoadingMore = true;
  103. axios.get('/api/landing/v1/directory', {
  104. params: {
  105. cursor: this.pagination.next_cursor
  106. }
  107. })
  108. .then(res => {
  109. this.feed.push(...res.data.data);
  110. this.pagination = {...res.data.links, ...res.data.meta};
  111. })
  112. .finally(() => {
  113. if(this.pagination.next_cursor) {
  114. this.canLoadMore = true;
  115. } else {
  116. this.canLoadMore = false;
  117. }
  118. this.isLoadingMore = false;
  119. this.isIntersecting = false;
  120. });
  121. console.log(e);
  122. }
  123. }
  124. }
  125. </script>