Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ const ProfilePage = ({ containerRef }: ProfilePageProps) => {
isMobile: false,
tabs: headers,
tabRecalculator,
initialTab: activeTab || undefined,
selectedTabLabel: activeTab ?? undefined,
elements,
pathname: profilePage(handle)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ const ProfilePage = ({ containerRef }: ProfilePageProps) => {
didChangeTabsFrom,
tabs: profileTabs,
elements: profileElements,
initialTab: activeTab || undefined,
selectedTabLabel: activeTab ?? undefined,
pathname: profilePage(handle)
})

Expand Down
4 changes: 3 additions & 1 deletion packages/web/src/pages/profile-page/useProfilePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export const useProfilePage = (

// Reset state when profile changes
useEffect(() => {
setActiveTab(null)
setActiveTab(params?.tab ? getTabForRoute(params.tab) : null)
setEditMode(false)
setUpdatedName(null)
setUpdatedCoverPhoto(null)
Expand All @@ -243,6 +243,8 @@ export const useProfilePage = (
setUpdatedWebsite(null)
setUpdatedArtistCoinBadge(null)
setAreArtistRecommendationsVisible(false)
// We intentionally only reset when switching profiles, not when changing tabs.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [profile?.handle])

// Check if owner changed from visitor to owner
Expand Down
25 changes: 25 additions & 0 deletions packages/web/src/utils/route/userRouteParser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'

import { parseUserRoute } from './userRouteParser'

describe('parseUserRoute', () => {
it('parses profile tab routes', () => {
expect(parseUserRoute('/test-user/albums')).toEqual({
handle: 'test-user',
userId: null,
tab: 'albums'
})
})

it('parses base profile routes', () => {
expect(parseUserRoute('/test-user')).toEqual({
handle: 'test-user',
userId: null,
tab: null
})
})

it('does not parse static routes as user profiles', () => {
expect(parseUserRoute('/search/albums')).toBeNull()
})
})
12 changes: 9 additions & 3 deletions packages/web/src/utils/route/userRouteParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const parseUserRoute = (
return { userId, handle: null, tab: null }
}

const profilePageMatch = matchPath(PROFILE_PAGE, route)
const profilePageMatch = matchPath({ path: PROFILE_PAGE, end: true }, route)
if (profilePageMatch?.params?.handle) {
const { handle } = profilePageMatch.params
// Decode handle to prevent double-encoding when used in API calls
Expand All @@ -58,7 +58,10 @@ export const parseUserRoute = (
}
}

const commentHistoryMatch = matchPath(PROFILE_PAGE_COMMENTS, route)
const commentHistoryMatch = matchPath(
{ path: PROFILE_PAGE_COMMENTS, end: true },
route
)
if (commentHistoryMatch?.params?.handle) {
const { handle } = commentHistoryMatch.params
// Decode handle to prevent double-encoding when used in API calls
Expand All @@ -68,7 +71,10 @@ export const parseUserRoute = (
}
}

const profilePageTabMatch = matchPath(`${PROFILE_PAGE}/:tab`, route)
const profilePageTabMatch = matchPath(
{ path: `${PROFILE_PAGE}/:tab`, end: true },
route
)
if (profilePageTabMatch?.params) {
const { handle, tab } = profilePageTabMatch.params as {
handle?: string
Expand Down
Loading