Skip to content

Commit 206a4ab

Browse files
committed
Add: Top songs in Artist screen
1 parent a986f02 commit 206a4ab

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

app/screens/Pres/Artist.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const Artist = ({ navigation, route: { params } }) => {
3838
setSortAlbum(json.artist?.album?.sort((a, b) => (b.year || 0) - (a.year || 0)))
3939
}, [params.id])
4040

41+
const [topSongs] = useCachedAndApi([], 'getTopSongs', { artist: params.name, count: 50 }, (json, setData) => {
42+
setData(json.topSongs?.song || [])
43+
}, [params.name])
44+
4145
const [favorited] = useCachedAndApi([], 'getStarred2', null, (json, setData) => {
4246
setData(json.starred2.song.filter(song => song.artistId === params.id))
4347
}, [params.id])
@@ -123,6 +127,27 @@ const Artist = ({ navigation, route: { params } }) => {
123127
</>
124128
) : null
125129
}
130+
{
131+
topSongs?.length ? (
132+
<>
133+
<Pressable onPress={() => navigation.navigate('Songs', { title: t('Top songs'), songs: topSongs })} style={{
134+
flexDirection: 'row',
135+
justifyContent: 'space-between',
136+
alignItems: 'center',
137+
width: '100%',
138+
}}>
139+
<Text style={[mainStyles.titleSection(theme)]}>{t('Top songs')}</Text>
140+
<Icon
141+
name='angle-right'
142+
color={theme.secondaryText}
143+
size={size.icon.medium}
144+
style={[mainStyles.titleSection(theme), { marginTop: 25, marginBottom: 12, marginEnd: 20 }]}
145+
/>
146+
</Pressable>
147+
<SongsList songs={topSongs.slice(0, 3)} listToPlay={topSongs} />
148+
</>
149+
) : null
150+
}
126151
{
127152
favorited?.length ? (
128153
<>

app/screens/Pres/Songs.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
3+
import { LegendList } from "@legendapp/list"
4+
5+
import { ThemeContext } from '~/contexts/theme';
6+
import mainStyles from '~/styles/main';
7+
import OptionsSongsList from '~/components/options/OptionsSongsList';
8+
import Header from '~/components/Header';
9+
import SongItem from '~/components/item/SongItem';
10+
11+
const Songs = ({ route: { params } }) => {
12+
const insets = useSafeAreaInsets();
13+
const theme = React.useContext(ThemeContext)
14+
const [indexOptions, setIndexOptions] = React.useState(-1);
15+
16+
const renderItem = React.useCallback(({ item, index }) => (
17+
<SongItem
18+
song={item}
19+
queue={params.songs || []}
20+
index={index}
21+
setIndexOptions={setIndexOptions}
22+
style={{
23+
paddingHorizontal: 20,
24+
}}
25+
/>
26+
), [params.songs]);
27+
28+
return (
29+
<>
30+
<LegendList
31+
data={params.songs || []}
32+
keyExtractor={(item, index) => index}
33+
style={mainStyles.mainContainer(theme)}
34+
contentContainerStyle={mainStyles.contentMainContainer(insets, false)}
35+
waitForInitialLayout={false}
36+
recycleItems={true}
37+
estimatedItemSize={60}
38+
ListHeaderComponent={<Header title={params.title} />}
39+
renderItem={renderItem}
40+
/>
41+
<OptionsSongsList
42+
songs={params.songs || []}
43+
indexOptions={indexOptions}
44+
setIndexOptions={setIndexOptions}
45+
/>
46+
</>
47+
)
48+
}
49+
50+
export default Songs;

app/screens/Stacks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ArtistAlbums from '~/screens/Pres/ArtistAlbums';
1212
import Favorited from '~/screens/Pres/Favorited';
1313
import Genre from '~/screens/Pres/Genre';
1414
import Playlist from '~/screens/Pres/Playlist';
15+
import Songs from '~/screens/Pres/Songs';
1516

1617
import EditPlaylist from '~/screens/EditPlaylist';
1718
import UpdateRadio from '~/screens/UpdateRadio';
@@ -56,6 +57,7 @@ export const HomeStack = () => {
5657
<Stack.Screen name="Album" component={Album} />
5758
<Stack.Screen name="Artist" component={Artist} />
5859
<Stack.Screen name="ArtistAlbums" component={ArtistAlbums} />
60+
<Stack.Screen name="Songs" component={Songs} />
5961
<Stack.Screen name="Genre" component={Genre} />
6062
<Stack.Screen name="UpdateRadio" component={UpdateRadio} />
6163
<Stack.Screen name="ShowAll" component={ShowAll} />
@@ -84,6 +86,7 @@ export const SearchStack = () => {
8486
<Stack.Screen name="Album" component={Album} />
8587
<Stack.Screen name="Artist" component={Artist} />
8688
<Stack.Screen name="ArtistAlbums" component={ArtistAlbums} />
89+
<Stack.Screen name="Songs" component={Songs} />
8790
<Stack.Screen name="ArtistExplorer" component={ArtistExplorer} />
8891
<Stack.Screen name="AlbumExplorer" component={AlbumExplorer} />
8992
<Stack.Screen name="SongExplorer" component={SongExplorer} />
@@ -112,6 +115,7 @@ export const PlaylistsStack = () => {
112115
<Stack.Screen name="Album" component={Album} />
113116
<Stack.Screen name="Artist" component={Artist} />
114117
<Stack.Screen name="ArtistAlbums" component={ArtistAlbums} />
118+
<Stack.Screen name="Songs" component={Songs} />
115119
<Stack.Screen name="EditPlaylist" component={EditPlaylist} />
116120
<Stack.Screen name="Info" component={Info} />
117121
</Stack.Navigator>

0 commit comments

Comments
 (0)