From 068590d09edd5a7b33aed5c9edab78d7f6e84f11 Mon Sep 17 00:00:00 2001 From: nukeop <12746779+nukeop@users.noreply.github.com> Date: Mon, 16 Sep 2024 01:37:52 +0200 Subject: [PATCH] Simplify artist view --- .../app/app/components/ArtistView/index.tsx | 7 +- .../ArtistViewContainer.test.tsx | 1 - .../ArtistViewContainer.test.tsx.snap | 76 +++++++++++++++++-- .../containers/ArtistViewContainer/hooks.ts | 17 +++-- .../containers/ArtistViewContainer/index.tsx | 19 +---- packages/app/test/storeBuilders.ts | 3 +- 6 files changed, 89 insertions(+), 34 deletions(-) diff --git a/packages/app/app/components/ArtistView/index.tsx b/packages/app/app/components/ArtistView/index.tsx index ae4a2125a0..4a8e9159b0 100644 --- a/packages/app/app/components/ArtistView/index.tsx +++ b/packages/app/app/components/ArtistView/index.tsx @@ -1,11 +1,10 @@ import React from 'react'; import cx from 'classnames'; import { get, isEmpty, take } from 'lodash'; -import { Dimmer, Loader, Icon } from 'semantic-ui-react'; +import { Dimmer, Loader } from 'semantic-ui-react'; import { useTranslation } from 'react-i18next'; import { useHistory } from 'react-router'; -import AlbumList from '../AlbumList'; import SimilarArtists from './SimilarArtists'; import PopularTracks from './PopularTracks'; @@ -111,8 +110,8 @@ const ArtistView: React.FC = ({ } { - (areReleasesLoading() || artist.releases?.length > 0) && - 0) && + { beforeAll(() => { diff --git a/packages/app/app/containers/ArtistViewContainer/__snapshots__/ArtistViewContainer.test.tsx.snap b/packages/app/app/containers/ArtistViewContainer/__snapshots__/ArtistViewContainer.test.tsx.snap index 4afeab63a4..52ef8994fa 100644 --- a/packages/app/app/containers/ArtistViewContainer/__snapshots__/ArtistViewContainer.test.tsx.snap +++ b/packages/app/app/containers/ArtistViewContainer/__snapshots__/ArtistViewContainer.test.tsx.snap @@ -199,10 +199,6 @@ exports[`Artist view container should display an artist 1`] = ` -
+ > +
+
+
+
+
+
+

+ First test album +

+
+
+
+
+
+
+
+
+
+

+ Test album 2 +

+
+
+
+
+
+
+
+
+
+

+ Test album 1 +

+
+
+
+
diff --git a/packages/app/app/containers/ArtistViewContainer/hooks.ts b/packages/app/app/containers/ArtistViewContainer/hooks.ts index d24d8c1c77..5f1cad9e38 100644 --- a/packages/app/app/containers/ArtistViewContainer/hooks.ts +++ b/packages/app/app/containers/ArtistViewContainer/hooks.ts @@ -1,10 +1,10 @@ -import { useCallback } from 'react'; +import { useCallback, useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useHistory, useParams } from 'react-router'; -import _ from 'lodash'; +import { find, isEmpty } from 'lodash'; import * as QueueActions from '../../actions/queue'; -import { artistInfoSearchByName, albumInfoSearch } from '../../actions/search'; +import { artistInfoSearchByName, albumInfoSearch, artistReleasesSearch } from '../../actions/search'; import * as FavoritesActions from '../../actions/favorites'; import { searchSelectors } from '../../selectors/search'; import { favoritesSelectors } from '../../selectors/favorites'; @@ -16,7 +16,8 @@ export const useArtistViewProps = () => { const { artistId } = useParams<{ artistId: string }>(); const artistDetails = useSelector(searchSelectors.artistDetails); const artist = artistDetails[artistId]; - + const source = artist?.source; + const addTrackToQueue = useCallback(async (item) => { dispatch(QueueActions.addToQueue(item)); }, [dispatch]); @@ -32,7 +33,7 @@ export const useArtistViewProps = () => { const favoriteArtists: { id: string }[] = useSelector(favoritesSelectors.artists); const getIsFavorite = (currentArtist, favoriteArtists) => { - const favoriteArtist = _.find(favoriteArtists, { + const favoriteArtist = find(favoriteArtists, { id: currentArtist?.id }); return Boolean(favoriteArtist); @@ -48,6 +49,12 @@ export const useArtistViewProps = () => { dispatch(FavoritesActions.removeFavoriteArtist(artist)); }, [artist, dispatch]); + useEffect(() => { + if (artistId !== 'loading' && isEmpty(artist.releases)) { + dispatch(artistReleasesSearch(artistId, source)); + } + }, [artistId, source]); + return { artist, isFavorite, diff --git a/packages/app/app/containers/ArtistViewContainer/index.tsx b/packages/app/app/containers/ArtistViewContainer/index.tsx index b6db4da066..7415db5d5d 100644 --- a/packages/app/app/containers/ArtistViewContainer/index.tsx +++ b/packages/app/app/containers/ArtistViewContainer/index.tsx @@ -1,27 +1,10 @@ -import React, { useEffect, useCallback } from 'react'; -import { useParams } from 'react-router'; -import { useDispatch } from 'react-redux'; +import React from 'react'; import ArtistView from '../../components/ArtistView'; -import { artistReleasesSearch } from '../../actions/search'; import { useArtistViewProps } from './hooks'; -import { SearchResultsSource } from '@nuclear/core/src/plugins/plugins.types'; const ArtistViewContainer: React.FC = () => { const props = useArtistViewProps(); - const { artistId } = useParams<{ artistId: string }>(); - const source = props.artist?.source; - const dispatch = useDispatch(); - const artistReleasesSearchCallback = useCallback(async (artistId: string, source: SearchResultsSource) => { - dispatch(artistReleasesSearch(artistId, source)); - }, [dispatch]); - - useEffect(() => { - if (artistId !== 'loading') { - artistReleasesSearchCallback(artistId, source); - } - }, [artistId, source, artistReleasesSearchCallback]); - return ; diff --git a/packages/app/test/storeBuilders.ts b/packages/app/test/storeBuilders.ts index cf887d5369..525187f304 100644 --- a/packages/app/test/storeBuilders.ts +++ b/packages/app/test/storeBuilders.ts @@ -326,7 +326,8 @@ export const buildStoreState = () => { default: return { id: 'test-artist-id' }; } - }) + }), + fetchArtistAlbums: jest.fn() } as any as MetaProvider, { name: 'Another Meta Provider',