@@ -2,46 +2,62 @@ import React from 'react'
22import { useTranslation } from 'react-i18next'
33
44import { ConfigContext } from '~/contexts/config'
5- import { getApiNetworkFirst } from '~/utils/api'
5+ import { getApiCacheFirst } from '~/utils/api'
66import { playSong } from '~/utils/player'
77import { SongDispatchContext } from '~/contexts/song'
88import 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 ] }
0 commit comments