From 4250fbc53f3dcb78a07b17e5239f07ff78c601cd Mon Sep 17 00:00:00 2001 From: Hafiz Date: Wed, 6 Aug 2025 13:24:31 -0500 Subject: [PATCH] Fix inconsistent profile URL format between own and other users' profiles - Update profile tab navigation to use consistent URL format for all users - Redirect old /user/* routes to new format for backward compatibility - Update all navigation points (dropdown menu, notifications) to use new URLs --- .../achievements/onboardingComplete.vue | 2 +- .../header/notifications/onboardingComplete.vue | 2 +- .../notifications/unallocatedStatsPoints.vue | 2 +- .../client/src/components/header/userDropdown.vue | 7 ++++++- .../client/src/components/userMenu/profile.vue | 15 ++++----------- website/client/src/router/index.js | 11 +++++++++-- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/website/client/src/components/achievements/onboardingComplete.vue b/website/client/src/components/achievements/onboardingComplete.vue index b7fb595191..6b8ccedaf4 100644 --- a/website/client/src/components/achievements/onboardingComplete.vue +++ b/website/client/src/components/achievements/onboardingComplete.vue @@ -117,7 +117,7 @@ export default { closeWithAction () { this.close(); setTimeout(() => { - this.$router.push({ name: 'achievements' }); + this.$router.push(`/profile/${this.$store.state.user.data._id}#achievements`); }, 200); }, }, diff --git a/website/client/src/components/header/notifications/onboardingComplete.vue b/website/client/src/components/header/notifications/onboardingComplete.vue index 9ad68ba316..b30dacf152 100644 --- a/website/client/src/components/header/notifications/onboardingComplete.vue +++ b/website/client/src/components/header/notifications/onboardingComplete.vue @@ -71,7 +71,7 @@ export default { props: ['notification', 'canRemove'], methods: { action () { - this.$router.push({ name: 'achievements' }); + this.$router.push(`/profile/${this.$store.state.user.data._id}#achievements`); }, }, }; diff --git a/website/client/src/components/header/notifications/unallocatedStatsPoints.vue b/website/client/src/components/header/notifications/unallocatedStatsPoints.vue index 1fd8964fff..b15dc35c1c 100644 --- a/website/client/src/components/header/notifications/unallocatedStatsPoints.vue +++ b/website/client/src/components/header/notifications/unallocatedStatsPoints.vue @@ -43,7 +43,7 @@ export default { }, methods: { action () { - this.$router.push({ name: 'stats' }); + this.$router.push(`/profile/${this.$store.state.user.data._id}#stats`); }, }, }; diff --git a/website/client/src/components/header/userDropdown.vue b/website/client/src/components/header/userDropdown.vue index efaec0a534..ea565996f3 100644 --- a/website/client/src/components/header/userDropdown.vue +++ b/website/client/src/components/header/userDropdown.vue @@ -176,7 +176,12 @@ export default { } }, showProfile (startingPage) { - this.$router.push({ name: startingPage }); + const userId = this.$store.state.user.data._id; + let path = `/profile/${userId}`; + if (startingPage !== 'profile') { + path += `#${startingPage}`; + } + this.$router.push(path); }, toLearnMore () { this.$router.push({ name: 'subscription' }); diff --git a/website/client/src/components/userMenu/profile.vue b/website/client/src/components/userMenu/profile.vue index 09fd792e07..d42713d4a0 100644 --- a/website/client/src/components/userMenu/profile.vue +++ b/website/client/src/components/userMenu/profile.vue @@ -1216,17 +1216,10 @@ export default { }, selectPage (page) { this.selectedPage = page || 'profile'; - // Update URL based on whether viewing own profile or another user's profile - let newPath; - if (this.userId === this.userLoggedIn._id) { - // Own profile - use /user/profile, /user/stats, /user/achievements - newPath = `/user/${page}`; - } else { - // Other user's profile - use /profile/:userId#stats, /profile/:userId#achievements - newPath = `/profile/${this.userId}`; - if (page !== 'profile') { - newPath += `#${page}`; - } + const profileUserId = this.userId || this.userLoggedIn._id; + let newPath = `/profile/${profileUserId}`; + if (page !== 'profile') { + newPath += `#${page}`; } window.history.replaceState(null, null, newPath); this.$store.dispatch('common:setTitle', { diff --git a/website/client/src/router/index.js b/website/client/src/router/index.js index 4a262e625e..87e52aeb9e 100644 --- a/website/client/src/router/index.js +++ b/website/client/src/router/index.js @@ -359,11 +359,18 @@ router.beforeEach(async (to, from, next) => { } if ((to.name === 'stats' || to.name === 'achievements' || to.name === 'profile') && from.name !== null) { + const userId = store.state.user.data._id; + let redirectPath = `/profile/${userId}`; + if (to.name === 'stats') { + redirectPath += '#stats'; + } else if (to.name === 'achievements') { + redirectPath += '#achievements'; + } router.app.$emit('habitica:show-profile', { - userId: store.state.user.data._id, + userId, startingPage: to.name, fromPath: from.path, - toPath: to.path, + toPath: redirectPath, }); return null; }