ProfileFollowers.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div class="profile-timeline-component">
  3. <div v-if="isLoaded" class="container-fluid mt-3">
  4. <div class="row">
  5. <div class="col-12 col-md-8 offset-md-2 px-md-5">
  6. <profile-followers
  7. :profile="profile"
  8. :relationship="relationship"
  9. @back="goBack()"
  10. />
  11. </div>
  12. </div>
  13. <drawer />
  14. </div>
  15. </div>
  16. </template>
  17. <script type="text/javascript">
  18. import Drawer from './partials/drawer.vue';
  19. import ProfileFollowers from './partials/profile/ProfileFollowers.vue';
  20. export default {
  21. props: {
  22. id: {
  23. type: String
  24. },
  25. profileId: {
  26. type: String
  27. },
  28. username: {
  29. type: String
  30. },
  31. cachedProfile: {
  32. type: Object
  33. },
  34. cachedUser: {
  35. type: Object
  36. }
  37. },
  38. components: {
  39. "drawer": Drawer,
  40. "profile-followers": ProfileFollowers
  41. },
  42. data() {
  43. return {
  44. isLoaded: false,
  45. curUser: undefined,
  46. profile: undefined,
  47. relationship: undefined
  48. }
  49. },
  50. mounted() {
  51. this.init();
  52. },
  53. watch: {
  54. '$route': 'init'
  55. },
  56. methods: {
  57. init() {
  58. this.isLoaded = false;
  59. this.relationship = undefined;
  60. this.owner = false;
  61. if(this.cachedProfile && this.cachedUser) {
  62. this.curUser = this.cachedUser;
  63. this.profile = this.cachedProfile;
  64. this.fetchRelationship();
  65. } else {
  66. this.curUser = window._sharedData.user;
  67. this.fetchProfile();
  68. }
  69. },
  70. fetchProfile() {
  71. let id = this.profileId ? this.profileId : this.id;
  72. axios.get('/api/pixelfed/v1/accounts/' + id)
  73. .then(res => {
  74. this.profile = res.data;
  75. if(res.data.id == this.curUser.id) {
  76. this.owner = true;
  77. // this.isLoaded = true;
  78. // this.loaded();
  79. // this.fetchPosts();
  80. this.fetchRelationship();
  81. } else {
  82. this.owner = false;
  83. this.fetchRelationship();
  84. }
  85. })
  86. .catch(err => {
  87. this.$router.push('/i/web/404');
  88. });
  89. },
  90. fetchRelationship() {
  91. if(this.owner) {
  92. this.relationship = {};
  93. this.isLoaded = true;
  94. return;
  95. }
  96. axios.get('/api/v1/accounts/relationships', {
  97. params: {
  98. 'id[]': this.profile.id
  99. }
  100. }).then(res => {
  101. this.relationship = res.data[0];
  102. this.isLoaded = true;
  103. })
  104. },
  105. goBack() {
  106. this.$router.push('/i/web/profile/' + this.profile.id);
  107. }
  108. }
  109. }
  110. </script>