import { atom , selectorFamily } from 'recoil' ; import helper from '../utils/helper' ; import { bufferTimeState } from './audio' ; import getLyric from '/@/api/lyrics' ; const namespace = 'lyrics' ; export const scrollLyricState = atom ( { key : `${ namespace }:scroll` , default : 0 , } ) ; export const fetchLyricState = selectorFamily ( { key : `${ namespace }:fetchLyric` , get : ( id ) => async ( { } ) => { if ( ! id ) { return { list : [ ] , } ; } const data = await getLyric ( id ) ; return { list : data , } ; } , } ) ; export const lyricScrollTimeState = selectorFamily ( { key : `${ namespace }:scrollTime` , get : ( lyrics ) => ( { get } ) => { const bufferTime = get ( bufferTimeState ) ; return helper . getLyricsKey ( bufferTime * 1000 , ( lyrics as unknown ) as string [ ] ) ; } , } ) ;