From b1dd3bfb00585a578869d2ee7209dbf54388e2f5 Mon Sep 17 00:00:00 2001 From: JD Francis Date: Tue, 8 Jul 2025 11:05:22 -0500 Subject: [PATCH 1/3] Fix mobile profile navving to reposts tab for artists sometimes --- .../src/api/tan-query/users/useUserByParams.ts | 2 +- packages/common/src/hooks/useIsArtist.ts | 12 +++++++----- .../ProfileTabs/ProfileTabNavigator.tsx | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/common/src/api/tan-query/users/useUserByParams.ts b/packages/common/src/api/tan-query/users/useUserByParams.ts index da45225f9ce..261173cb00d 100644 --- a/packages/common/src/api/tan-query/users/useUserByParams.ts +++ b/packages/common/src/api/tan-query/users/useUserByParams.ts @@ -16,7 +16,7 @@ type UserParams = { id?: ID } | { handle?: string | null } * @returns The user data or null if not found */ export const useUserByParams = < - TResult extends { user_id: number; handle: string } = UserMetadata + TResult extends Partial = UserMetadata >( params: UserParams, options?: SelectableQueryOptions diff --git a/packages/common/src/hooks/useIsArtist.ts b/packages/common/src/hooks/useIsArtist.ts index f5a0a8f8e3b..2416cf39cd4 100644 --- a/packages/common/src/hooks/useIsArtist.ts +++ b/packages/common/src/hooks/useIsArtist.ts @@ -2,20 +2,22 @@ import { useEffect } from 'react' import { useDispatch } from 'react-redux' +import { useUserByParams } from '~/api' import { useCurrentAccount } from '~/api/tan-query/users/account/useCurrentAccount' -import { useProfileUser } from '~/api/tan-query/users/useProfileUser' +import { ID } from '~/models' import { accountActions } from '~/store/account' const { fetchHasTracks } = accountActions -export const useIsArtist = () => { - const { user_id, track_count } = - useProfileUser({ +export const useIsArtist = (params: { id?: ID; handle?: string }) => { + const { data: user } = + useUserByParams(params, { select: (user) => ({ user_id: user.user_id, track_count: user.track_count }) - }).user ?? {} + }) ?? {} + const { user_id, track_count } = user ?? {} const { data: account } = useCurrentAccount() const currentUserId = account?.userId diff --git a/packages/mobile/src/screens/profile-screen/ProfileTabs/ProfileTabNavigator.tsx b/packages/mobile/src/screens/profile-screen/ProfileTabs/ProfileTabNavigator.tsx index 71060b87224..cbf92d5e03b 100644 --- a/packages/mobile/src/screens/profile-screen/ProfileTabs/ProfileTabNavigator.tsx +++ b/packages/mobile/src/screens/profile-screen/ProfileTabs/ProfileTabNavigator.tsx @@ -49,7 +49,7 @@ export const ProfileTabNavigator = ({ const { params } = useRoute<'Profile'>() const initialParams = { id: user_id, handle: params.handle } - const isArtist = useIsArtist() + const isArtist = useIsArtist(params) const showCollectiblesTab = useShouldShowCollectiblesTab() From b51dc5f7d9f9a07c8bd8fb8c3b628f878194495d Mon Sep 17 00:00:00 2001 From: JD Francis Date: Tue, 8 Jul 2025 15:15:03 -0500 Subject: [PATCH 2/3] Update the other usage of useIsArtist --- .../src/pages/profile-page/ProfilePageProvider.tsx | 2 +- .../desktop/TransactionHistoryPage.tsx | 5 ++++- .../mobile/TransactionHistoryPage.tsx | 12 +++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/web/src/pages/profile-page/ProfilePageProvider.tsx b/packages/web/src/pages/profile-page/ProfilePageProvider.tsx index 58a38d61a7f..26a16bfa073 100644 --- a/packages/web/src/pages/profile-page/ProfilePageProvider.tsx +++ b/packages/web/src/pages/profile-page/ProfilePageProvider.tsx @@ -1129,7 +1129,7 @@ type HookStateProps = { } const hookStateToProps = (Component: typeof ProfilePage) => { return (props: ProfilePageProps) => { - const isArtist = useIsArtist() + const isArtist = useIsArtist({ id: props.profile?.profile?.user_id }) const { data: accountData } = useCurrentAccountUser({ select: (user) => ({ accountUserId: user?.user_id diff --git a/packages/web/src/pages/transaction-history-page/desktop/TransactionHistoryPage.tsx b/packages/web/src/pages/transaction-history-page/desktop/TransactionHistoryPage.tsx index d9daff21fca..cde02f2e655 100644 --- a/packages/web/src/pages/transaction-history-page/desktop/TransactionHistoryPage.tsx +++ b/packages/web/src/pages/transaction-history-page/desktop/TransactionHistoryPage.tsx @@ -1,5 +1,6 @@ import { useCallback, useState } from 'react' +import { useCurrentAccount } from '@audius/common/api' import { useFeatureFlag, useIsArtist } from '@audius/common/hooks' import { FeatureFlags } from '@audius/common/services' import { @@ -41,7 +42,9 @@ type TableMetadata = { export const TransactionHistoryPage = ({ tableView }: TransactionHistoryPageProps) => { - const isArtist = useIsArtist() + const { data: isArtist } = useCurrentAccount({ + select: (account) => account?.hasTracks + }) const [tableOptions, setTableOptions] = useState(null) const [selectedTable, setSelectedTable] = useState(null) diff --git a/packages/web/src/pages/transaction-history-page/mobile/TransactionHistoryPage.tsx b/packages/web/src/pages/transaction-history-page/mobile/TransactionHistoryPage.tsx index b5d29f9da66..e3b60dc9f0a 100644 --- a/packages/web/src/pages/transaction-history-page/mobile/TransactionHistoryPage.tsx +++ b/packages/web/src/pages/transaction-history-page/mobile/TransactionHistoryPage.tsx @@ -1,7 +1,11 @@ import { useCallback, useState } from 'react' -import { selectIsGuestAccount, useCurrentAccountUser } from '@audius/common/api' -import { useFeatureFlag, useIsArtist } from '@audius/common/hooks' +import { + selectIsGuestAccount, + useCurrentAccount, + useCurrentAccountUser +} from '@audius/common/api' +import { useFeatureFlag } from '@audius/common/hooks' import { FeatureFlags } from '@audius/common/services' import { route } from '@audius/common/utils' import { @@ -47,7 +51,9 @@ export const TransactionHistoryPage = ({ tableView }: TransactionHistoryPageProps) => { const dispatch = useDispatch() - const isArtist = useIsArtist() + const { data: isArtist } = useCurrentAccount({ + select: (account) => account?.hasTracks + }) const { data: accountData } = useCurrentAccountUser({ select: (user) => ({ handle: user?.handle, From 88df77faf202dc64c221320fbf7a5d53320995e3 Mon Sep 17 00:00:00 2001 From: JD Francis Date: Tue, 8 Jul 2025 15:21:20 -0500 Subject: [PATCH 3/3] unused import --- .../transaction-history-page/desktop/TransactionHistoryPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web/src/pages/transaction-history-page/desktop/TransactionHistoryPage.tsx b/packages/web/src/pages/transaction-history-page/desktop/TransactionHistoryPage.tsx index cde02f2e655..4a0fde3c1c8 100644 --- a/packages/web/src/pages/transaction-history-page/desktop/TransactionHistoryPage.tsx +++ b/packages/web/src/pages/transaction-history-page/desktop/TransactionHistoryPage.tsx @@ -1,7 +1,7 @@ import { useCallback, useState } from 'react' import { useCurrentAccount } from '@audius/common/api' -import { useFeatureFlag, useIsArtist } from '@audius/common/hooks' +import { useFeatureFlag } from '@audius/common/hooks' import { FeatureFlags } from '@audius/common/services' import { Button,