revert some stuff, turns out it's actually breaking. Fixed some local user things

This commit is contained in:
Henry Jameson 2019-03-09 01:19:56 +02:00
parent 4f3a220487
commit 690c1dcd7a
2 changed files with 34 additions and 31 deletions

View file

@ -37,27 +37,7 @@ const UserProfile = {
}, },
created () { created () {
if (!this.user.id) { if (!this.user.id) {
let fetchPromise this.fetchUserId()
if (this.userId) {
fetchPromise = this.$store.dispatch('fetchUser', this.userId)
} else {
fetchPromise = this.$store.dispatch('fetchUserByScreenName', this.userName)
.then(userId => {
this.fetchedUserId = userId
})
}
fetchPromise
.catch((reason) => {
const errorMessage = get(reason, 'error.error')
if (errorMessage === 'No user with such user_id') { // Known error
this.error = this.$t('user_profile.profile_does_not_exist')
} else if (errorMessage) {
this.error = errorMessage
} else {
this.error = this.$t('user_profile.profile_loading_error')
}
})
.then(() => this.startUp())
} }
}, },
destroyed () { destroyed () {
@ -112,8 +92,30 @@ const UserProfile = {
this.$store.dispatch('startFetching', { timeline: 'favorites', userId: this.userId }) this.$store.dispatch('startFetching', { timeline: 'favorites', userId: this.userId })
} }
}, },
fetchUserId () {
let fetchPromise
if (this.userId && !this.$route.params.name) {
fetchPromise = this.$store.dispatch('fetchUser', this.userId)
} else {
fetchPromise = this.$store.dispatch('fetchUserByScreenName', this.userName)
.then(userId => {
this.fetchedUserId = userId
})
}
fetchPromise
.catch((reason) => {
const errorMessage = get(reason, 'error.error')
if (errorMessage === 'No user with such user_id') { // Known error
this.error = this.$t('user_profile.profile_does_not_exist')
} else if (errorMessage) {
this.error = errorMessage
} else {
this.error = this.$t('user_profile.profile_loading_error')
}
})
.then(() => this.startUp())
},
startUp () { startUp () {
this.$store.dispatch('fetchUserRelationship', this.userId)
this.$store.dispatch('startFetching', { timeline: 'user', userId: this.userId }) this.$store.dispatch('startFetching', { timeline: 'user', userId: this.userId })
this.$store.dispatch('startFetching', { timeline: 'media', userId: this.userId }) this.$store.dispatch('startFetching', { timeline: 'media', userId: this.userId })
this.startFetchFavorites() this.startFetchFavorites()
@ -134,6 +136,13 @@ const UserProfile = {
this.startUp() this.startUp()
} }
}, },
userName (newVal, oldVal) {
if (this.$route.params.name) {
this.fetchUserId()
this.cleanUp()
this.startUp()
}
},
$route () { $route () {
this.$refs.tabSwitcher.activateTab(0)() this.$refs.tabSwitcher.activateTab(0)()
} }

View file

@ -108,17 +108,11 @@ export const mutations = {
state.currentUser.muteIds = muteIds state.currentUser.muteIds = muteIds
}, },
setUserForStatus (state, status) { setUserForStatus (state, status) {
// Not setting it again since it's already reactive if it has getters status.user = state.usersObject[status.user.id]
if (!Object.getOwnPropertyDescriptor(status.user, 'id').get) {
status.user = state.usersObject[status.user.id]
}
}, },
setUserForNotification (state, notification) { setUserForNotification (state, notification) {
// Not setting it again since it's already reactive if it has getters notification.action.user = state.usersObject[notification.action.user.id]
if (!Object.getOwnPropertyDescriptor(notification.action.user, 'id').get) { notification.from_profile = state.usersObject[notification.action.user.id]
notification.action.user = state.usersObject[notification.action.user.id]
notification.from_profile = state.usersObject[notification.action.user.id]
}
}, },
setColor (state, { user: { id }, highlighted }) { setColor (state, { user: { id }, highlighted }) {
const user = state.usersObject[id] const user = state.usersObject[id]