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

Commit

Permalink
Fix user profile always showing artist tabs (#3648)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Jun 24, 2023
1 parent bc34b6f commit 820e79e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
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

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 } 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
}

0 comments on commit 820e79e

Please sign in to comment.