Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Fix user profile always showing artist tabs #3648

Merged
merged 2 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 3 additions & 28 deletions packages/mobile/src/screens/profile-screen/ProfileTabNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { ReactNode } from 'react'
import { useEffect } from 'react'

import { accountActions, accountSelectors } from '@audius/common'
import type { Animated } from 'react-native'
import { useDispatch, useSelector } from 'react-redux'

import IconAlbum from 'app/assets/images/iconAlbum.svg'
import IconCollectibles from 'app/assets/images/iconCollectibles.svg'
Expand All @@ -22,11 +19,9 @@ import { PlaylistsTab } from './PlaylistsTab'
import { RepostsTab } from './RepostsTab'
import { TracksTab } from './TracksTab'
import { useSelectProfile } from './selectors'
import { useIsArtist } from './useIsArtist'
import { useShouldShowCollectiblesTab } from './utils'

const { fetchHasTracks } = accountActions
const { getUserId, getUserHandle, getAccountHasTracks } = accountSelectors

// Height of a typical profile header
const INITIAL_PROFILE_HEADER_HEIGHT = 1081

Expand All @@ -52,31 +47,11 @@ export const ProfileTabNavigator = ({
refreshing,
onRefresh
}: ProfileTabNavigatorProps) => {
const { user_id, track_count } = useSelectProfile(['user_id', 'track_count'])
const { user_id } = useSelectProfile(['user_id'])
const { params } = useRoute<'Profile'>()

const initialParams = { id: user_id, handle: params.handle }

const accountHasTracks = useSelector(getAccountHasTracks)
const isArtist = accountHasTracks || track_count > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH NO 🤦


const currentUserId = useSelector(getUserId)
const currentUserHandle = useSelector(getUserHandle)
const dispatch = useDispatch()
useEffect(() => {
if (
currentUserId === initialParams.id ||
currentUserHandle === initialParams.handle
) {
dispatch(fetchHasTracks())
}
}, [
currentUserHandle,
currentUserId,
dispatch,
initialParams.handle,
initialParams.id
])
const isArtist = useIsArtist()

const showCollectiblesTab = useShouldShowCollectiblesTab()

Expand Down
24 changes: 24 additions & 0 deletions packages/mobile/src/screens/profile-screen/useIsArtist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useEffect } from 'react'

import { accountActions, accountSelectors, type ID } from '@audius/common'
import { useDispatch, useSelector } from 'react-redux'

import { useSelectProfile } from './selectors'

const { fetchHasTracks } = accountActions
const { getUserId, getAccountHasTracks } = accountSelectors

export const useIsArtist = () => {
const { user_id, track_count } = useSelectProfile(['user_id', 'track_count'])
const accountHasTracks = useSelector(getAccountHasTracks)
const currentUserId = useSelector(getUserId)
const dispatch = useDispatch()

useEffect(() => {
if (accountHasTracks === null && currentUserId === user_id) {
dispatch(fetchHasTracks())
}
}, [accountHasTracks, currentUserId, user_id, dispatch])

return (user_id === currentUserId && accountHasTracks) || track_count > 0
}