feat: updates (#1530)

* feat: 支持repeat mode切换

* feat: 歌单页面的播放按钮可以暂停

* fix: 专辑页面播放按钮

考虑私人FM的情况
解决按钮闪烁问题

* fix: SvgName报错

* update
This commit is contained in:
memorydream 2022-04-15 00:34:07 +08:00 committed by GitHub
parent 13281d3f08
commit 24af937e70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 30 deletions

View file

@ -8,7 +8,11 @@ import TracksAlbum from '@/renderer/components/TracksAlbum'
import useAlbum from '@/renderer/hooks/useAlbum'
import useArtistAlbums from '@/renderer/hooks/useArtistAlbums'
import { player } from '@/renderer/store'
import { State as PlayerState } from '@/renderer/utils/player'
import {
Mode as PlayerMode,
State as PlayerState,
TrackListSourceType,
} from '@/renderer/utils/player'
import {
formatDate,
formatDuration,
@ -27,40 +31,37 @@ const PlayButton = ({
isLoading,
}: {
album: Album | undefined
isLoading: boolean
handlePlay: () => void
isLoading: boolean
}) => {
const playerSnapshot = useSnapshot(player)
const isPlaying = useMemo(
() => playerSnapshot.state === PlayerState.PLAYING,
[playerSnapshot.state]
)
const isThisAlbumPlaying = useMemo(
() =>
playerSnapshot.trackListSource?.type === 'album' &&
playerSnapshot.mode === PlayerMode.PLAYLIST &&
playerSnapshot.trackListSource?.type === TrackListSourceType.ALBUM &&
playerSnapshot.trackListSource?.id === album?.id,
[playerSnapshot.trackListSource, album?.id]
)
const isPlaying =
isThisAlbumPlaying &&
[PlayerState.PLAYING, PlayerState.LOADING].includes(playerSnapshot.state)
const wrappedHandlePlay = () => {
if (isPlaying && isThisAlbumPlaying) {
player.pause()
return
if (isThisAlbumPlaying) {
player.playOrPause()
} else {
handlePlay()
}
if (!isPlaying && isThisAlbumPlaying) {
player.play()
return
}
handlePlay()
}
return (
<Button onClick={wrappedHandlePlay} isSkelton={isLoading}>
<SvgIcon
name={isPlaying && isThisAlbumPlaying ? 'pause' : 'play'}
name={isPlaying ? 'pause' : 'play'}
className='mr-1 -ml-1 h-6 w-6'
/>
{isPlaying && isThisAlbumPlaying ? '暂停' : '播放'}
{isPlaying ? '暂停' : '播放'}
</Button>
)
}