ensure timelines only start fetching on click (#150)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
no more parallel fetching Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk> Reviewed-on: AkkomaGang/pleroma-fe#150
This commit is contained in:
parent
064b8ba7f7
commit
6f2058a8fc
2 changed files with 26 additions and 16 deletions
|
@ -48,8 +48,9 @@ const UserProfile = {
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
const routeParams = this.$route.params
|
const routeParams = this.$route.params
|
||||||
|
const hash = get(this.$route, 'hash', defaultTabKey).replace(/^#/, '')
|
||||||
|
if (hash !== '') this.tab = hash
|
||||||
this.load(routeParams.name || routeParams.id)
|
this.load(routeParams.name || routeParams.id)
|
||||||
this.tab = get(this.$route, 'query.hash', defaultTabKey).replace(/^#/, '')
|
|
||||||
},
|
},
|
||||||
unmounted () {
|
unmounted () {
|
||||||
this.stopFetching()
|
this.stopFetching()
|
||||||
|
@ -91,23 +92,31 @@ const UserProfile = {
|
||||||
setFooterRef (el) {
|
setFooterRef (el) {
|
||||||
this.footerRef = el
|
this.footerRef = el
|
||||||
},
|
},
|
||||||
load (userNameOrId) {
|
onRouteChange (previousTab, nextTab) {
|
||||||
const startFetchingTimeline = (timeline, userId) => {
|
const timelineTabMap = {
|
||||||
// Clear timeline only if load another user's profile
|
statuses: 'user',
|
||||||
if (userId !== this.$store.state.statuses.timelines[timeline].userId) {
|
replies: 'replies',
|
||||||
this.$store.commit('clearTimeline', { timeline })
|
media: 'media'
|
||||||
}
|
|
||||||
this.$store.dispatch('startFetchingTimeline', { timeline, userId })
|
|
||||||
}
|
}
|
||||||
|
// only we can see our own favourites
|
||||||
|
if (this.isUs) timelineTabMap['favorites'] = 'favorites'
|
||||||
|
|
||||||
|
const timeline = timelineTabMap[nextTab]
|
||||||
|
const lastTimeline = timelineTabMap[previousTab]
|
||||||
|
if (timeline) {
|
||||||
|
this.stopFetching()
|
||||||
|
if (lastTimeline) this.$store.commit('clearTimeline', { timeline: lastTimeline })
|
||||||
|
this.$store.dispatch('startFetchingTimeline', { timeline: timeline, userId: this.userId })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
load (userNameOrId) {
|
||||||
const loadById = (userId) => {
|
const loadById = (userId) => {
|
||||||
this.userId = userId
|
this.userId = userId
|
||||||
startFetchingTimeline('user', userId)
|
const timelines = ['user', 'favorites', 'replies', 'media']
|
||||||
startFetchingTimeline('replies', userId)
|
timelines.forEach((timeline) => {
|
||||||
startFetchingTimeline('media', userId)
|
this.$store.commit('clearTimeline', { timeline: timeline })
|
||||||
if (this.isUs) {
|
})
|
||||||
startFetchingTimeline('favorites', userId)
|
this.onRouteChange(null, this.tab)
|
||||||
}
|
|
||||||
// Fetch all pinned statuses immediately
|
// Fetch all pinned statuses immediately
|
||||||
this.$store.dispatch('fetchPinnedStatuses', userId)
|
this.$store.dispatch('fetchPinnedStatuses', userId)
|
||||||
}
|
}
|
||||||
|
@ -182,7 +191,9 @@ const UserProfile = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'$route.hash': function (newVal) {
|
'$route.hash': function (newVal) {
|
||||||
|
const oldTab = this.tab
|
||||||
this.tab = newVal.replace(/^#/, '') || defaultTabKey
|
this.tab = newVal.replace(/^#/, '') || defaultTabKey
|
||||||
|
this.onRouteChange(oldTab, this.tab)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|
|
@ -121,7 +121,6 @@
|
||||||
<Timeline
|
<Timeline
|
||||||
key="media"
|
key="media"
|
||||||
:label="$t('user_card.media')"
|
:label="$t('user_card.media')"
|
||||||
:disabled="!media.visibleStatuses.length"
|
|
||||||
:embedded="true"
|
:embedded="true"
|
||||||
:title="$t('user_card.media')"
|
:title="$t('user_card.media')"
|
||||||
timeline-name="media"
|
timeline-name="media"
|
||||||
|
@ -134,7 +133,7 @@
|
||||||
v-if="isUs"
|
v-if="isUs"
|
||||||
key="favorites"
|
key="favorites"
|
||||||
:label="$t('user_card.favorites')"
|
:label="$t('user_card.favorites')"
|
||||||
:disabled="!favorites.visibleStatuses.length"
|
:disabled="!isUs"
|
||||||
:embedded="true"
|
:embedded="true"
|
||||||
:title="$t('user_card.favorites')"
|
:title="$t('user_card.favorites')"
|
||||||
timeline-name="favorites"
|
timeline-name="favorites"
|
||||||
|
|
Loading…
Reference in a new issue