FindFriends.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div class="discover-find-friends-component">
  3. <div v-if="isLoaded" class="container-fluid mt-3">
  4. <div class="row">
  5. <div class="col-md-4 col-lg-3">
  6. <sidebar :user="profile" />
  7. </div>
  8. <div class="col-md-6 col-lg-6">
  9. <b-breadcrumb class="font-default" :items="breadcrumbItems"></b-breadcrumb>
  10. <h1 class="font-default">Find Friends</h1>
  11. <!-- <p class="font-default lead">Posts from hashtags you follow</p> -->
  12. <hr>
  13. <b-spinner v-if="isLoading" />
  14. <div v-if="!isLoading" class="row justify-content-center">
  15. <div class="col-12 col-lg-10 mb-3" v-for="(profile, index) in popularAccounts">
  16. <div class="card shadow-sm border-0 rounded-px">
  17. <div class="card-body p-2">
  18. <profile-card
  19. :key="'pfc' + index"
  20. :profile="profile"
  21. class="w-100"
  22. v-on:follow="follow(index)"
  23. v-on:unfollow="unfollow(index)"
  24. />
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script type="text/javascript">
  35. import Drawer from './../partials/drawer.vue';
  36. import Sidebar from './../partials/sidebar.vue';
  37. import StatusCard from './../partials/TimelineStatus.vue';
  38. import ProfileCard from './../partials/profile/ProfileHoverCard.vue';
  39. export default {
  40. components: {
  41. "drawer": Drawer,
  42. "sidebar": Sidebar,
  43. "status-card": StatusCard,
  44. "profile-card": ProfileCard
  45. },
  46. data() {
  47. return {
  48. isLoaded: true,
  49. isLoading: true,
  50. profile: window._sharedData.user,
  51. feed: [],
  52. popular: [],
  53. popularAccounts: [],
  54. popularLoaded: false,
  55. breadcrumbItems: [
  56. {
  57. text: 'Discover',
  58. href: '/i/web/discover'
  59. },
  60. {
  61. text: 'Find Friends',
  62. active: true
  63. }
  64. ]
  65. }
  66. },
  67. mounted() {
  68. this.fetchConfig();
  69. },
  70. methods: {
  71. fetchConfig() {
  72. axios.get('/api/pixelfed/v2/discover/meta')
  73. .then(res => {
  74. if(res.data.friends.enabled == false) {
  75. this.$router.push('/i/web/discover');
  76. } else {
  77. this.fetchPopularAccounts();
  78. }
  79. })
  80. .catch(e => {
  81. this.isLoading = false;
  82. })
  83. },
  84. fetchPopular() {
  85. axios.get('/api/pixelfed/v2/discover/account-insights')
  86. .then(res => {
  87. this.popular = res.data;
  88. this.popularLoaded = true;
  89. this.isLoading = false;
  90. })
  91. .catch(e => {
  92. this.isLoading = false;
  93. })
  94. },
  95. formatCount(val) {
  96. return App.util.format.count(val);
  97. },
  98. timeago(ts) {
  99. return App.util.format.timeAgo(ts);
  100. },
  101. fetchPopularAccounts() {
  102. axios.get('/api/pixelfed/discover/accounts/popular')
  103. .then(res => {
  104. this.popularAccounts = res.data;
  105. this.isLoading = false;
  106. })
  107. .catch(e => {
  108. this.isLoading = false;
  109. })
  110. },
  111. follow(index) {
  112. axios.post('/api/v1/accounts/' + this.popularAccounts[index].id + '/follow')
  113. .then(res => {
  114. this.newlyFollowed++;
  115. this.$store.commit('updateRelationship', [res.data]);
  116. this.$emit('update-profile', {
  117. 'following_count': this.profile.following_count + 1
  118. })
  119. });
  120. },
  121. unfollow(index) {
  122. axios.post('/api/v1/accounts/' + this.popularAccounts[index].id + '/unfollow')
  123. .then(res => {
  124. this.newlyFollowed--;
  125. this.$store.commit('updateRelationship', [res.data]);
  126. this.$emit('update-profile', {
  127. 'following_count': this.profile.following_count - 1
  128. })
  129. });
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss">
  135. .discover-find-friends-component {
  136. .bg-stellar {
  137. background: #7474BF;
  138. background: -webkit-linear-gradient(to right, #348AC7, #7474BF);
  139. background: linear-gradient(to right, #348AC7, #7474BF);
  140. }
  141. .bg-midnight {
  142. background: #232526;
  143. background: -webkit-linear-gradient(to right, #414345, #232526);
  144. background: linear-gradient(to right, #414345, #232526);
  145. }
  146. .font-default {
  147. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  148. letter-spacing: -0.7px;
  149. }
  150. .active {
  151. font-weight: 700;
  152. }
  153. .profile-hover-card-inner {
  154. width: 100%;
  155. .d-flex {
  156. max-width: 100% !important;
  157. }
  158. }
  159. }
  160. </style>