From 6d44c671979f3954a19774133861c5af5a47b6ec Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Wed, 31 Aug 2022 16:37:49 +0100 Subject: [PATCH 1/2] ensure timelines only start fetching on click --- src/components/user_profile/user_profile.js | 38 ++++++++++++-------- src/components/user_profile/user_profile.vue | 3 +- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index ed30c02e..3e3f3445 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -48,8 +48,8 @@ const UserProfile = { }, created () { const routeParams = this.$route.params + this.tab = get(this.$route, 'hash', defaultTabKey).replace(/^#/, '') this.load(routeParams.name || routeParams.id) - this.tab = get(this.$route, 'query.hash', defaultTabKey).replace(/^#/, '') }, unmounted () { this.stopFetching() @@ -91,23 +91,31 @@ const UserProfile = { setFooterRef (el) { this.footerRef = el }, - 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 }) + onRouteChange (previousTab, nextTab) { + const timelineTabMap = { + statuses: 'user', + replies: 'replies', + media: 'media' } + // 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) => { this.userId = userId - startFetchingTimeline('user', userId) - startFetchingTimeline('replies', userId) - startFetchingTimeline('media', userId) - if (this.isUs) { - startFetchingTimeline('favorites', userId) - } + const timelines = ['user', 'favorites', 'replies', 'media'] + timelines.forEach((timeline) => { + this.$store.commit('clearTimeline', { timeline: timeline }) + }) + this.onRouteChange(null, this.tab) // Fetch all pinned statuses immediately this.$store.dispatch('fetchPinnedStatuses', userId) } @@ -182,7 +190,9 @@ const UserProfile = { } }, '$route.hash': function (newVal) { + const oldTab = this.tab this.tab = newVal.replace(/^#/, '') || defaultTabKey + this.onRouteChange(oldTab, this.tab) } }, components: { diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index 760f104c..d16483e2 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -121,7 +121,6 @@ Date: Wed, 31 Aug 2022 16:41:10 +0100 Subject: [PATCH 2/2] ensure default tab loads --- src/components/user_profile/user_profile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index 3e3f3445..89cd95fd 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -48,7 +48,8 @@ const UserProfile = { }, created () { const routeParams = this.$route.params - this.tab = get(this.$route, 'hash', defaultTabKey).replace(/^#/, '') + const hash = get(this.$route, 'hash', defaultTabKey).replace(/^#/, '') + if (hash !== '') this.tab = hash this.load(routeParams.name || routeParams.id) }, unmounted () { -- 2.34.1