mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 05:38:04 +00:00
feat: updates (#1530)
* feat: 支持repeat mode切换 * feat: 歌单页面的播放按钮可以暂停 * fix: 专辑页面播放按钮 考虑私人FM的情况 解决按钮闪烁问题 * fix: SvgName报错 * update
This commit is contained in:
parent
13281d3f08
commit
24af937e70
5 changed files with 96 additions and 30 deletions
|
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue