Compare commits

...

3 Commits

Author SHA1 Message Date
Hafiz
4250fbc53f 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
2025-08-06 13:24:31 -05:00
Hafiz
0c0dc20dcc Fix undefined userId 2025-08-05 12:53:28 -05:00
Hafiz
c0508a2f22 Fix profile modal tab navigation URLs for both own and other users profiles
- Add routes for /user/profile, /user/stats, and /user/achievements
- Update selectPage() to properly update URLs when switching tabs
- Own profile uses /user/{tab} format
- Other users' profiles use /profile/{userId}#{tab} format
- Parse hash fragments when navigating to other users' profile tabs
- Ensure direct navigation to tab URLs opens correct tab
2025-08-05 11:59:11 -05:00
6 changed files with 38 additions and 8 deletions

View File

@@ -117,7 +117,7 @@ export default {
closeWithAction () { closeWithAction () {
this.close(); this.close();
setTimeout(() => { setTimeout(() => {
this.$router.push({ name: 'achievements' }); this.$router.push(`/profile/${this.$store.state.user.data._id}#achievements`);
}, 200); }, 200);
}, },
}, },

View File

@@ -71,7 +71,7 @@ export default {
props: ['notification', 'canRemove'], props: ['notification', 'canRemove'],
methods: { methods: {
action () { action () {
this.$router.push({ name: 'achievements' }); this.$router.push(`/profile/${this.$store.state.user.data._id}#achievements`);
}, },
}, },
}; };

View File

@@ -43,7 +43,7 @@ export default {
}, },
methods: { methods: {
action () { action () {
this.$router.push({ name: 'stats' }); this.$router.push(`/profile/${this.$store.state.user.data._id}#stats`);
}, },
}, },
}; };

View File

@@ -176,7 +176,12 @@ export default {
} }
}, },
showProfile (startingPage) { 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 () { toLearnMore () {
this.$router.push({ name: 'subscription' }); this.$router.push({ name: 'subscription' });

View File

@@ -1126,7 +1126,12 @@ export default {
this.loadUser(); this.loadUser();
this.oldTitle = this.$store.state.title; this.oldTitle = this.$store.state.title;
this.handleExternalLinks(); this.handleExternalLinks();
this.selectPage(this.startingPage); // Check if there's a hash in the URL to determine the starting page
let pageToSelect = this.startingPage;
if (window.location.hash && (window.location.hash === '#stats' || window.location.hash === '#achievements')) {
pageToSelect = window.location.hash.substring(1);
}
this.selectPage(pageToSelect);
this.$root.$on('habitica:report-profile-result', () => { this.$root.$on('habitica:report-profile-result', () => {
this.loadUser(); this.loadUser();
}); });
@@ -1211,10 +1216,15 @@ export default {
}, },
selectPage (page) { selectPage (page) {
this.selectedPage = page || 'profile'; this.selectedPage = page || 'profile';
window.history.replaceState(null, null, ''); 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', { this.$store.dispatch('common:setTitle', {
section: this.$t('user'), section: this.$t('user'),
subSection: this.$t(this.startingPage), subSection: this.$t(page),
}); });
}, },
getNextIncentive () { getNextIncentive () {

View File

@@ -98,6 +98,9 @@ const router = new VueRouter({
path: '/profile/:userId', path: '/profile/:userId',
props: true, props: true,
}, },
{ name: 'profile', path: '/user/profile' },
{ name: 'stats', path: '/user/stats' },
{ name: 'achievements', path: '/user/achievements' },
{ {
path: '/inventory', path: '/inventory',
component: InventoryContainer, component: InventoryContainer,
@@ -332,6 +335,10 @@ router.beforeEach(async (to, from, next) => {
if (to.params.startingPage !== undefined) { if (to.params.startingPage !== undefined) {
startingPage = to.params.startingPage; startingPage = to.params.startingPage;
} }
// Check if there's a hash in the URL for stats or achievements
if (to.hash === '#stats' || to.hash === '#achievements') {
startingPage = to.hash.substring(1);
}
if (from.name === null) { if (from.name === null) {
store.state.postLoadModal = `profile/${to.params.userId}`; store.state.postLoadModal = `profile/${to.params.userId}`;
return next({ name: 'tasks' }); return next({ name: 'tasks' });
@@ -352,10 +359,18 @@ router.beforeEach(async (to, from, next) => {
} }
if ((to.name === 'stats' || to.name === 'achievements' || to.name === 'profile') && from.name !== null) { 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', { router.app.$emit('habitica:show-profile', {
userId,
startingPage: to.name, startingPage: to.name,
fromPath: from.path, fromPath: from.path,
toPath: to.path, toPath: redirectPath,
}); });
return null; return null;
} }