GroupTopicFeed.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div class="group-topic-feed-component">
  3. <div v-if="isLoaded" class="bg-white py-5 border-bottom">
  4. <div class="container">
  5. <div class="d-flex justify-content-between align-items-center">
  6. <div>
  7. <h3 class="font-weight-bold mb-1">#{{ name }}</h3>
  8. <p class="mb-0 lead text-muted">
  9. <span>
  10. Posts in <a :href="group.url" class="text-muted font-weight-bold">{{ group.name }}</a>
  11. </span>
  12. <span>·</span>
  13. <span><i class="fas fa-globe"></i></span>
  14. <span>·</span>
  15. <span>{{ group.membership != 'all' ? 'Private' : 'Public'}} Group</span>
  16. </p>
  17. </div>
  18. <!-- <div>
  19. <button class="btn btn-light border btn-lg text-muted">
  20. <i class="fas fa-ellipsis-h"></i>
  21. </button>
  22. </div> -->
  23. </div>
  24. </div>
  25. </div>
  26. <div v-if="isLoaded" class="row justify-content-center mt-3">
  27. <div v-if="feed.length" class="col-12 col-md-5">
  28. <group-status
  29. v-for="(status, index) in feed"
  30. :key="'gs:' + status.id + index"
  31. :prestatus="status"
  32. :profile="profile"
  33. :group="group"
  34. :show-group-chevron="true"
  35. :group-id="gid" />
  36. <div v-if="feed.length > 2">
  37. <infinite-loading @infinite="infiniteFeed">
  38. <div slot="no-more"></div>
  39. <div slot="no-results"></div>
  40. </infinite-loading>
  41. </div>
  42. </div>
  43. <div v-else class="col-12 col-md-5 d-flex justify-content-center">
  44. <div class="mt-5">
  45. <p class="text-lighter text-center">
  46. <i class="fal fa-exclamation-circle fa-4x"></i>
  47. </p>
  48. <p class="font-weight-bold text-muted">Cannot load any posts containg the <span class="font-weight-normal">#{{ name }}</span> hashtag</p>
  49. <p class="text-left">
  50. This can happen for a few reasons:
  51. </p>
  52. <ul class="text-left">
  53. <li>There is a typo in the url</li>
  54. <li>No posts exist that contain this hashtag</li>
  55. <li>This hashtag has been banned by group admins</li>
  56. <li>The hashtag is new or used infrequently</li>
  57. <li>A technical issue has occured</li>
  58. </ul>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </template>
  64. <script type="text/javascript">
  65. import GroupStatus from '@/groups/partials/GroupStatus.vue';
  66. export default {
  67. props: {
  68. gid: {
  69. type: String
  70. },
  71. name: {
  72. type: String
  73. }
  74. },
  75. components: {
  76. GroupStatus
  77. },
  78. data() {
  79. return {
  80. isLoaded: false,
  81. group: false,
  82. profile: false,
  83. feed: [],
  84. page: 1,
  85. ids: []
  86. }
  87. },
  88. mounted() {
  89. this.fetchProfile();
  90. },
  91. methods: {
  92. fetchProfile() {
  93. axios.get('/api/pixelfed/v1/accounts/verify_credentials')
  94. .then(res => {
  95. this.profile = res.data;
  96. this.fetchGroup();
  97. });
  98. },
  99. fetchGroup() {
  100. axios.get('/api/v0/groups/' + this.gid)
  101. .then(res => {
  102. this.group = res.data;
  103. this.fetchFeed();
  104. });
  105. },
  106. fetchFeed() {
  107. axios.get('/api/v0/groups/topics/tag', {
  108. params: {
  109. gid: this.gid,
  110. name: this.name
  111. }
  112. }).then(res => {
  113. this.feed = res.data;
  114. this.isLoaded = true;
  115. let self = this;
  116. res.data.forEach(d => {
  117. if(self.ids.indexOf(d.id) == -1) {
  118. self.ids.push(d.id);
  119. }
  120. });
  121. this.page++;
  122. })
  123. },
  124. infiniteFeed($state) {
  125. if(this.feed.length < 2) {
  126. $state.complete();
  127. return;
  128. }
  129. axios.get('/api/v0/groups/topics/tag', {
  130. params: {
  131. gid: this.gid,
  132. name: this.name,
  133. limit: 1,
  134. page: this.page
  135. },
  136. }).then(res => {
  137. if (res.data.length) {
  138. let data = res.data;
  139. let self = this;
  140. data.forEach(d => {
  141. if(self.ids.indexOf(d.id) == -1) {
  142. self.ids.push(d.id);
  143. self.feed.push(d);
  144. }
  145. });
  146. $state.loaded();
  147. this.page++;
  148. } else {
  149. $state.complete();
  150. }
  151. });
  152. }
  153. }
  154. }
  155. </script>