ProfileDirectory.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div>
  3. <div class="col-12">
  4. <p class="font-weight-bold text-lighter text-uppercase">Profiles Directory</p>
  5. <div v-if="loaded" class="">
  6. <div class="row">
  7. <div class="col-12 col-md-6 p-1" v-for="(profile, index) in profiles">
  8. <div class="card card-body border shadow-none py-2">
  9. <div class="media">
  10. <a :href="profile.url"><img :src="profile.avatar" class="rounded-circle border mr-3" alt="..." width="40px" height="40px"></a>
  11. <div class="media-body">
  12. <p class="mt-0 mb-0 font-weight-bold">
  13. <a :href="profile.url" class="text-dark">{{profile.username}}</a>
  14. </p>
  15. <p class="mb-1 small text-lighter d-flex justify-content-between font-weight-bold">
  16. <span>
  17. <span>{{prettyCount(profile.statuses_count)}}</span> POSTS
  18. </span>
  19. <span>
  20. <span>{{prettyCount(profile.followers_count)}}</span> FOLLOWERS
  21. </span>
  22. </p>
  23. <p class="mb-1">
  24. <span v-for="(post, i) in profile.posts" class="shadow-sm" :key="'profile_posts_'+i">
  25. <a :href="post.url" class="text-decoration-none mr-1">
  26. <img :src="thumbUrl(post)" width="62.3px" height="62.3px" class="border rounded">
  27. </a>
  28. </span>
  29. </p>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. <div v-if="showLoadMore" class="col-12">
  35. <p class="text-center mb-0 pt-3">
  36. <button class="btn btn-outline-secondary btn-sm px-4 py-1 font-weight-bold" @click="loadMore()">Load More</button>
  37. </p>
  38. </div>
  39. </div>
  40. </div>
  41. <div v-else>
  42. <div class="row">
  43. <div class="col-12 d-flex justify-content-center align-items-center">
  44. <div class="spinner-border" role="status">
  45. <span class="sr-only">Loading...</span>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </template>
  53. <style type="text/css" scoped></style>
  54. <script type="text/javascript">
  55. export default {
  56. data() {
  57. return {
  58. loaded: false,
  59. showLoadMore: true,
  60. profiles: [],
  61. page: 1
  62. }
  63. },
  64. beforeMount() {
  65. this.fetchData();
  66. },
  67. methods: {
  68. fetchData() {
  69. axios.get('/api/pixelfed/v2/discover/profiles', {
  70. params: {
  71. page: this.page
  72. }
  73. })
  74. .then(res => {
  75. if(res.data.length == 0) {
  76. this.showLoadMore = false;
  77. this.loaded = true;
  78. return;
  79. }
  80. this.profiles = res.data;
  81. this.showLoadMore = this.profiles.length == 8;
  82. this.loaded = true;
  83. });
  84. },
  85. prettyCount(val) {
  86. return App.util.format.count(val);
  87. },
  88. loadMore() {
  89. this.loaded = false;
  90. this.page++;
  91. this.fetchData();
  92. },
  93. thumbUrl(p) {
  94. return p.media_attachments[0].url;
  95. }
  96. }
  97. }
  98. </script>