Skip to content

Commit 30dc438

Browse files
committed
Add: option in Artist Screen
1 parent a2d3550 commit 30dc438

12 files changed

Lines changed: 199 additions & 94 deletions

File tree

app/components/PresHeader.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
import React from 'react';
22
import { Text, View, Pressable } from 'react-native';
33
import { ThemeContext } from '~/contexts/theme';
4+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
45

56
import BackButton from '~/components/button/BackButton';
67
import mainStyles from '~/styles/main';
78
import presStyles from '~/styles/pres';
89
import ImageError from '~/components/ImageError';
10+
import IconButton from '~/components/button/IconButton';
911

10-
const PresHeader = ({ title, subTitle, imgSrc, onPressTitle = null, children = null }) => {
12+
const PresHeader = ({ title, subTitle, imgSrc, onPressTitle = null, onPressOption = null, children = null }) => {
1113
const theme = React.useContext(ThemeContext);
14+
const insets = useSafeAreaInsets();
1215

1316
return (
1417
<>
1518
<BackButton />
19+
{
20+
onPressOption ?
21+
<IconButton
22+
icon="ellipsis-h"
23+
onPress={onPressOption}
24+
color={'white'}
25+
style={{
26+
position: 'absolute',
27+
padding: 20,
28+
top: insets.top,
29+
right: insets.left,
30+
zIndex: 1
31+
}}
32+
/> : null
33+
}
1634
<ImageError
1735
style={[presStyles.cover, { backgroundColor: theme.secondaryBack }]}
1836
source={{ uri: imgSrc }}

app/components/lists/HorizontalArtists.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { urlCover } from '~/utils/api';
88
import CustomFlat from '~/components/lists/CustomFlat';
99
import ImageError from '~/components/ImageError';
1010
import mainStyles from '~/styles/main';
11-
import OptionsArtist from '~/components/options/OptionsArtist';
11+
import OptionsArtists from '~/components/options/OptionsArtists';
1212
import size from '~/styles/size';
1313

1414
const HorizontalArtists = ({ artists, onPress = () => { } }) => {
@@ -48,7 +48,7 @@ const HorizontalArtists = ({ artists, onPress = () => { } }) => {
4848
widthItem={size.image.medium + 10}
4949
/>
5050

51-
<OptionsArtist
51+
<OptionsArtists
5252
artists={artists}
5353
indexOptions={indexOptions}
5454
setIndexOptions={setIndexOptions}

app/components/options/OptionsArtist.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,62 @@ import React from 'react'
22
import { useTranslation } from 'react-i18next'
33

44
import { ConfigContext } from '~/contexts/config'
5-
import { getApiNetworkFirst } from '~/utils/api'
5+
import { getApiCacheFirst } from '~/utils/api'
66
import { playSong } from '~/utils/player'
77
import { SongDispatchContext } from '~/contexts/song'
88
import OptionsPopup from '~/components/popup/OptionsPopup'
99

10-
const OptionsArtist = ({ artists, indexOptions, setIndexOptions }) => {
10+
const OptionsArtist = ({ artist, isOption, setIsOption }) => {
1111
const songDispatch = React.useContext(SongDispatchContext)
1212
const config = React.useContext(ConfigContext)
1313
const { t } = useTranslation()
1414
const refOption = React.useRef()
1515

16-
const playSimilarSongs = () => {
17-
getApiNetworkFirst(config, 'getSimilarSongs', `id=${artists[indexOptions].id}&count=50`)
18-
.then((json) => {
19-
if (json.similarSongs?.song) {
20-
playSong(config, songDispatch, json.similarSongs.song, 0)
21-
}
22-
})
23-
.catch(() => { })
24-
refOption.current.close()
25-
}
16+
const playSimilarSongs = () => {
17+
getApiCacheFirst(config, 'getSimilarSongs', `id=${artist.id}&count=50`)
18+
.then((json) => {
19+
if (json.similarSongs?.song) {
20+
playSong(config, songDispatch, json.similarSongs.song, 0)
21+
}
22+
})
23+
.catch(() => { })
24+
refOption.current.close()
25+
}
26+
27+
const playTopSongs = () => {
28+
getApiCacheFirst(config, 'getTopSongs', { artist: artist.name, count: 50 })
29+
.then((json) => {
30+
if (json.topSongs?.song) {
31+
playSong(config, songDispatch, json.topSongs.song, 0)
32+
}
33+
})
34+
.catch(() => { })
35+
refOption.current.close()
36+
}
2637

2738
return (
2839
<OptionsPopup
2940
ref={refOption}
30-
visible={indexOptions >= 0}
31-
close={() => { setIndexOptions(-1) }}
32-
item={indexOptions >= 0 ? artists[indexOptions] : null}
41+
visible={isOption}
42+
close={() => { setIsOption(false) }}
43+
item={isOption ? artist : null}
3344
options={[
3445
{
3546
name: t('Play similar songs'),
36-
icon: 'play',
37-
onPress: playSimilarSongs
47+
icon: 'play',
48+
onPress: playSimilarSongs
49+
},
50+
{
51+
name: t('Play top songs'),
52+
icon: 'arrow-up',
53+
onPress: playTopSongs
3854
},
3955
{
4056
name: t('Info'),
4157
icon: 'info',
4258
onPress: () => {
43-
refOption.current.showInfo(artists[indexOptions])
44-
setIndexOptions(-1)
59+
refOption.current.showInfo(artist)
60+
refOption.current.close()
4561
}
4662
}
4763
]}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react'
2+
import { useTranslation } from 'react-i18next'
3+
4+
import { ConfigContext } from '~/contexts/config'
5+
import { getApiNetworkFirst } from '~/utils/api'
6+
import { playSong } from '~/utils/player'
7+
import { SongDispatchContext } from '~/contexts/song'
8+
import OptionsPopup from '~/components/popup/OptionsPopup'
9+
10+
const OptionsArtists = ({ artists, indexOptions, setIndexOptions }) => {
11+
const songDispatch = React.useContext(SongDispatchContext)
12+
const config = React.useContext(ConfigContext)
13+
const { t } = useTranslation()
14+
const refOption = React.useRef()
15+
16+
const playSimilarSongs = () => {
17+
getApiNetworkFirst(config, 'getSimilarSongs', `id=${artists[indexOptions].id}&count=50`)
18+
.then((json) => {
19+
if (json.similarSongs?.song) {
20+
playSong(config, songDispatch, json.similarSongs.song, 0)
21+
}
22+
})
23+
.catch(() => { })
24+
refOption.current.close()
25+
}
26+
27+
return (
28+
<OptionsPopup
29+
ref={refOption}
30+
visible={indexOptions >= 0}
31+
close={() => { setIndexOptions(-1) }}
32+
item={indexOptions >= 0 ? artists[indexOptions] : null}
33+
options={[
34+
{
35+
name: t('Play similar songs'),
36+
icon: 'play',
37+
onPress: playSimilarSongs
38+
},
39+
{
40+
name: t('Info'),
41+
icon: 'info',
42+
onPress: () => {
43+
refOption.current.showInfo(artists[indexOptions])
44+
refOption.current.close()
45+
}
46+
}
47+
]}
48+
/>
49+
)
50+
}
51+
52+
export default OptionsArtists

app/i18next/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"Pin playlist": "Wiedergabeliste anheften",
149149
"Play next": "Nächstes abspielen",
150150
"Play similar songs": "Ähnliche Songs abspielen",
151+
"Play top songs": "Top Songs abspielen",
151152
"Player": "Player",
152153
"Playlist": "Wiedergabeliste",
153154
"Playlists": "Wiedergabelisten",

app/i18next/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"Pin playlist": "Pin playlist",
149149
"Play next": "Play next",
150150
"Play similar songs": "Play similar songs",
151+
"Play top songs": "Play top songs",
151152
"Player": "Player",
152153
"Playlist": "Playlist",
153154
"Playlists": "Playlists",

app/i18next/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"Pin playlist": "Épingler la playlist",
149149
"Play next": "Lire ensuite",
150150
"Play similar songs": "Jouer des titres similaires",
151+
"Play top songs": "Jouer les meilleurs titres",
151152
"Player": "Lecteur",
152153
"Playlist": "Playlist",
153154
"Playlists": "Playlists",

app/i18next/it.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"Pin playlist": "Fissa playlist",
149149
"Play next": "Riproduci successivo",
150150
"Play similar songs": "Riproduci brani simili",
151+
"Play top songs": "Riproduci i brani migliori",
151152
"Player": "Lettore",
152153
"Playlist": "Playlist",
153154
"Playlists": "Playlist",

app/i18next/ru.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"Pin playlist": "Закрепить плейлист",
149149
"Play next": "Следующий трек",
150150
"Play similar songs": "Похожие",
151+
"Play top songs": "Лучшие треки",
151152
"Player": "Плеер",
152153
"Playlist": "Плейлист",
153154
"Playlists": "Плейлисты",

app/i18next/zh-Hans.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"Pin playlist": "固定歌单",
149149
"Play next": "下一首",
150150
"Play similar songs": "播放相似歌曲",
151+
"Play top songs": "播放热门歌曲",
151152
"Player": "播放器",
152153
"Playlist": "歌单",
153154
"Playlists": "歌单",

0 commit comments

Comments
 (0)