forked from AkkomaGang/akkoma-fe
clear timelines only if load user not viewed previously
This commit is contained in:
parent
9f6be4fe65
commit
2e0603bdca
1 changed files with 32 additions and 27 deletions
|
@ -30,13 +30,11 @@ const UserProfile = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
// Make sure that timelines used in this page are empty
|
|
||||||
this.cleanUp()
|
|
||||||
const routeParams = this.$route.params
|
const routeParams = this.$route.params
|
||||||
this.load(routeParams.name || routeParams.id)
|
this.load(routeParams.name || routeParams.id)
|
||||||
},
|
},
|
||||||
destroyed () {
|
destroyed () {
|
||||||
this.cleanUp()
|
this.stopFetching()
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
timeline () {
|
timeline () {
|
||||||
|
@ -67,17 +65,35 @@ const UserProfile = {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
load (userNameOrId) {
|
load (userNameOrId) {
|
||||||
|
const startFetchingTimeline = (timeline, userId) => {
|
||||||
|
// Clear timeline only if load another user's profile
|
||||||
|
if (userId !== this.$store.state.statuses.timelines[timeline].userId) {
|
||||||
|
this.$store.commit('clearTimeline', { timeline })
|
||||||
|
}
|
||||||
|
this.$store.dispatch('startFetchingTimeline', { timeline, userId })
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadById = (userId) => {
|
||||||
|
this.userId = userId
|
||||||
|
startFetchingTimeline('user', userId)
|
||||||
|
startFetchingTimeline('media', userId)
|
||||||
|
if (this.isUs) {
|
||||||
|
startFetchingTimeline('favorites', userId)
|
||||||
|
}
|
||||||
|
// Fetch all pinned statuses immediately
|
||||||
|
this.$store.dispatch('fetchPinnedStatuses', userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset view
|
||||||
|
this.userId = null
|
||||||
|
|
||||||
// Check if user data is already loaded in store
|
// Check if user data is already loaded in store
|
||||||
const user = this.$store.getters.findUser(userNameOrId)
|
const user = this.$store.getters.findUser(userNameOrId)
|
||||||
if (user) {
|
if (user) {
|
||||||
this.userId = user.id
|
loadById(user.id)
|
||||||
this.fetchTimelines()
|
|
||||||
} else {
|
} else {
|
||||||
this.$store.dispatch('fetchUser', userNameOrId)
|
this.$store.dispatch('fetchUser', userNameOrId)
|
||||||
.then(({ id }) => {
|
.then(({ id }) => loadById(id))
|
||||||
this.userId = id
|
|
||||||
this.fetchTimelines()
|
|
||||||
})
|
|
||||||
.catch((reason) => {
|
.catch((reason) => {
|
||||||
const errorMessage = get(reason, 'error.error')
|
const errorMessage = get(reason, 'error.error')
|
||||||
if (errorMessage === 'No user with such user_id') { // Known error
|
if (errorMessage === 'No user with such user_id') { // Known error
|
||||||
|
@ -90,36 +106,25 @@ const UserProfile = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fetchTimelines () {
|
stopFetching () {
|
||||||
const userId = this.userId
|
|
||||||
this.$store.dispatch('startFetchingTimeline', { timeline: 'user', userId })
|
|
||||||
this.$store.dispatch('startFetchingTimeline', { timeline: 'media', userId })
|
|
||||||
if (this.isUs) {
|
|
||||||
this.$store.dispatch('startFetchingTimeline', { timeline: 'favorites', userId })
|
|
||||||
}
|
|
||||||
// Fetch all pinned statuses immediately
|
|
||||||
this.$store.dispatch('fetchPinnedStatuses', userId)
|
|
||||||
},
|
|
||||||
cleanUp () {
|
|
||||||
this.$store.dispatch('stopFetching', 'user')
|
this.$store.dispatch('stopFetching', 'user')
|
||||||
this.$store.dispatch('stopFetching', 'favorites')
|
this.$store.dispatch('stopFetching', 'favorites')
|
||||||
this.$store.dispatch('stopFetching', 'media')
|
this.$store.dispatch('stopFetching', 'media')
|
||||||
this.$store.commit('clearTimeline', { timeline: 'user' })
|
},
|
||||||
this.$store.commit('clearTimeline', { timeline: 'favorites' })
|
switchUser (userNameOrId) {
|
||||||
this.$store.commit('clearTimeline', { timeline: 'media' })
|
this.stopFetching()
|
||||||
|
this.load(userNameOrId)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
'$route.params.id': function (newVal) {
|
'$route.params.id': function (newVal) {
|
||||||
if (newVal) {
|
if (newVal) {
|
||||||
this.cleanUp()
|
this.switchUser(newVal)
|
||||||
this.load(newVal)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'$route.params.name': function (newVal) {
|
'$route.params.name': function (newVal) {
|
||||||
if (newVal) {
|
if (newVal) {
|
||||||
this.cleanUp()
|
this.switchUser(newVal)
|
||||||
this.load(newVal)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
$route () {
|
$route () {
|
||||||
|
|
Loading…
Reference in a new issue