ProfileFollowing.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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-following
  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 ProfileFollowing from './partials/profile/ProfileFollowing.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-following": ProfileFollowing
  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.fetchRelationship();
  78. } else {
  79. this.owner = false;
  80. this.fetchRelationship();
  81. }
  82. })
  83. .catch(err => {
  84. this.$router.push('/i/web/404');
  85. });
  86. },
  87. fetchRelationship() {
  88. if(this.owner) {
  89. this.relationship = {};
  90. this.isLoaded = true;
  91. return;
  92. }
  93. axios.get('/api/v1/accounts/relationships', {
  94. params: {
  95. 'id[]': this.profile.id
  96. }
  97. }).then(res => {
  98. this.relationship = res.data[0];
  99. this.isLoaded = true;
  100. })
  101. },
  102. goBack() {
  103. this.$router.push('/i/web/profile/' + this.profile.id);
  104. }
  105. }
  106. }
  107. </script>