akkoma-fe/src/components/user_profile/user_profile.js
Henry Jameson 8f255fbad4 Refactor follower/friends out of statuses/timeline into user_profile where it
belongs. Changed display of profile to single panel with tabs.
2018-12-17 19:14:38 +03:00

66 lines
1.6 KiB
JavaScript

import UserCardContent from '../user_card_content/user_card_content.vue'
import UserCard from '../user_card/user_card.vue'
import Timeline from '../timeline/timeline.vue'
const UserProfile = {
created () {
this.$store.commit('clearTimeline', { timeline: 'user' })
this.$store.dispatch('startFetching', ['user', this.userId])
if (!this.$store.state.users.usersObject[this.userId]) {
this.$store.dispatch('fetchUser', this.userId)
}
},
destroyed () {
this.$store.dispatch('stopFetching', 'user')
},
computed: {
timeline () { return this.$store.state.statuses.timelines.user },
friends () {
return this.user.friends
},
followers () {
return this.user.followers
},
userId () {
return this.$route.params.id
},
user () {
if (this.timeline.statuses[0]) {
return this.timeline.statuses[0].user
} else {
return this.$store.state.users.usersObject[this.userId] || false
}
}
},
methods: {
fetchFollowers () {
const id = this.userId
this.$store.dispatch('addFollowers', { id })
},
fetchFriends () {
const id = this.userId
this.$store.dispatch('addFriends', { id })
}
},
watch: {
userId () {
this.$store.dispatch('stopFetching', 'user')
this.$store.commit('clearTimeline', { timeline: 'user' })
this.$store.dispatch('startFetching', ['user', this.userId])
},
user () {
if (!this.user.followers) {
this.fetchFollowers()
this.fetchFriends()
}
}
},
components: {
UserCardContent,
UserCard,
Timeline
}
}
export default UserProfile