mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-02-28 19:46:26 +08:00
refactor: 将 enum key的格式改为 PascalCase
This commit is contained in:
parent
0061a66124
commit
7e892997bd
@ -1,7 +1,7 @@
|
|||||||
import request from '@/renderer/utils/request'
|
import request from '@/renderer/utils/request'
|
||||||
|
|
||||||
export enum PersonalFMApiNames {
|
export enum PersonalFMApiNames {
|
||||||
FETCH_PERSONAL_FM = 'fetchPersonalFM',
|
FetchPersonalFm = 'fetchPersonalFM',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PersonalMusic {
|
export interface PersonalMusic {
|
||||||
|
@ -14,7 +14,7 @@ export function search(params: SearchParams): Promise<SearchResponse> {
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
params: {
|
params: {
|
||||||
...params,
|
...params,
|
||||||
type: SearchTypes[params.type ?? SearchTypes.ALL],
|
type: SearchTypes[params.type ?? SearchTypes.All],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ import { prefetchPlaylist } from '@/renderer/hooks/usePlaylist'
|
|||||||
import { formatDate, resizeImage, scrollToTop } from '@/renderer/utils/common'
|
import { formatDate, resizeImage, scrollToTop } from '@/renderer/utils/common'
|
||||||
|
|
||||||
export enum Subtitle {
|
export enum Subtitle {
|
||||||
COPYWRITER = 'copywriter',
|
Copywriter = 'copywriter',
|
||||||
CREATOR = 'creator',
|
Creator = 'creator',
|
||||||
TYPE_RELEASE_YEAR = 'type+releaseYear',
|
TypeReleaseYear = 'type+releaseYear',
|
||||||
ARTIST = 'artist',
|
Artist = 'artist',
|
||||||
}
|
}
|
||||||
|
|
||||||
const Title = ({
|
const Title = ({
|
||||||
@ -62,10 +62,10 @@ const getSubtitleText = (
|
|||||||
}[('type' in item && typeof item.type !== 'number' && item.type) || 'unknown']
|
}[('type' in item && typeof item.type !== 'number' && item.type) || 'unknown']
|
||||||
|
|
||||||
const table = {
|
const table = {
|
||||||
[Subtitle.CREATOR]: `by ${nickname}`,
|
[Subtitle.Creator]: `by ${nickname}`,
|
||||||
[Subtitle.TYPE_RELEASE_YEAR]: `${type} · ${releaseYear}`,
|
[Subtitle.TypeReleaseYear]: `${type} · ${releaseYear}`,
|
||||||
[Subtitle.ARTIST]: artist,
|
[Subtitle.Artist]: artist,
|
||||||
[Subtitle.COPYWRITER]: copywriter,
|
[Subtitle.Copywriter]: copywriter,
|
||||||
}
|
}
|
||||||
|
|
||||||
return table[subtitle]
|
return table[subtitle]
|
||||||
@ -84,7 +84,7 @@ const CoverRow = ({
|
|||||||
albums,
|
albums,
|
||||||
artists,
|
artists,
|
||||||
playlists,
|
playlists,
|
||||||
subtitle = Subtitle.COPYWRITER,
|
subtitle = Subtitle.Copywriter,
|
||||||
seeMoreLink,
|
seeMoreLink,
|
||||||
isSkeleton,
|
isSkeleton,
|
||||||
className,
|
className,
|
||||||
|
@ -39,7 +39,7 @@ const MediaControls = () => {
|
|||||||
className='h-6 w-6'
|
className='h-6 w-6'
|
||||||
name={
|
name={
|
||||||
playerSnapshot.mode === PlayerMode.FM &&
|
playerSnapshot.mode === PlayerMode.FM &&
|
||||||
[PlayerState.PLAYING, PlayerState.LOADING].includes(state)
|
[PlayerState.Playing, PlayerState.Loading].includes(state)
|
||||||
? 'pause'
|
? 'pause'
|
||||||
: 'play'
|
: 'play'
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ const Controls = () => {
|
|||||||
<SvgIcon
|
<SvgIcon
|
||||||
className='h-7 w-7'
|
className='h-7 w-7'
|
||||||
name={
|
name={
|
||||||
[PlayerState.PLAYING, PlayerState.LOADING].includes(state)
|
[PlayerState.Playing, PlayerState.Loading].includes(state)
|
||||||
? 'pause'
|
? 'pause'
|
||||||
: 'play'
|
: 'play'
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ const MediaControls = () => {
|
|||||||
<SvgIcon
|
<SvgIcon
|
||||||
className='h-7 w-7'
|
className='h-7 w-7'
|
||||||
name={
|
name={
|
||||||
[PlayerState.PLAYING, PlayerState.LOADING].includes(state)
|
[PlayerState.Playing, PlayerState.Loading].includes(state)
|
||||||
? 'pause'
|
? 'pause'
|
||||||
: 'play'
|
: 'play'
|
||||||
}
|
}
|
||||||
@ -133,12 +133,12 @@ const Others = () => {
|
|||||||
const playerSnapshot = useSnapshot(player)
|
const playerSnapshot = useSnapshot(player)
|
||||||
|
|
||||||
const switchRepeatMode = () => {
|
const switchRepeatMode = () => {
|
||||||
if (playerSnapshot.repeatMode === PlayerRepeatMode.OFF) {
|
if (playerSnapshot.repeatMode === PlayerRepeatMode.Off) {
|
||||||
player.repeatMode = PlayerRepeatMode.ON
|
player.repeatMode = PlayerRepeatMode.On
|
||||||
} else if (playerSnapshot.repeatMode === PlayerRepeatMode.ON) {
|
} else if (playerSnapshot.repeatMode === PlayerRepeatMode.On) {
|
||||||
player.repeatMode = PlayerRepeatMode.ONE
|
player.repeatMode = PlayerRepeatMode.One
|
||||||
} else {
|
} else {
|
||||||
player.repeatMode = PlayerRepeatMode.OFF
|
player.repeatMode = PlayerRepeatMode.Off
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,11 +157,11 @@ const Others = () => {
|
|||||||
<SvgIcon
|
<SvgIcon
|
||||||
className={classNames(
|
className={classNames(
|
||||||
'h-6 w-6',
|
'h-6 w-6',
|
||||||
playerSnapshot.repeatMode !== PlayerRepeatMode.OFF &&
|
playerSnapshot.repeatMode !== PlayerRepeatMode.Off &&
|
||||||
'text-brand-500'
|
'text-brand-500'
|
||||||
)}
|
)}
|
||||||
name={
|
name={
|
||||||
playerSnapshot.repeatMode === PlayerRepeatMode.ONE
|
playerSnapshot.repeatMode === PlayerRepeatMode.One
|
||||||
? 'repeat-1'
|
? 'repeat-1'
|
||||||
: 'repeat'
|
: 'repeat'
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ const Progress = () => {
|
|||||||
min={0}
|
min={0}
|
||||||
max={(track.dt ?? 0) / 1000}
|
max={(track.dt ?? 0) / 1000}
|
||||||
value={
|
value={
|
||||||
state === PlayerState.PLAYING || state === PlayerState.PAUSED
|
state === PlayerState.Playing || state === PlayerState.Paused
|
||||||
? progress
|
? progress
|
||||||
: 0
|
: 0
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ const Playlists = () => {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<span className='line-clamp-1'>{playlist.name}</span>
|
<span className='line-clamp-1'>{playlist.name}</span>
|
||||||
{playlistMode === TrackListSourceType.PLAYLIST &&
|
{playlistMode === TrackListSourceType.Playlist &&
|
||||||
mode === Mode.TrackList &&
|
mode === Mode.TrackList &&
|
||||||
currentPlaylistID === playlist.id && (
|
currentPlaylistID === playlist.id && (
|
||||||
<SvgIcon className='h-5 w-5' name='volume-half' />
|
<SvgIcon className='h-5 w-5' name='volume-half' />
|
||||||
|
@ -6,16 +6,16 @@ import { resizeImage } from '@/renderer/utils/common'
|
|||||||
const NavigationButtons = () => {
|
const NavigationButtons = () => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
enum ACTION {
|
enum ACTION {
|
||||||
BACK = 'back',
|
Back = 'back',
|
||||||
FORWARD = 'forward',
|
Forward = 'forward',
|
||||||
}
|
}
|
||||||
const handleNavigate = (action: ACTION) => {
|
const handleNavigate = (action: ACTION) => {
|
||||||
if (action === ACTION.BACK) navigate(-1)
|
if (action === ACTION.Back) navigate(-1)
|
||||||
if (action === ACTION.FORWARD) navigate(1)
|
if (action === ACTION.Forward) navigate(1)
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className='flex gap-1'>
|
<div className='flex gap-1'>
|
||||||
{[ACTION.BACK, ACTION.FORWARD].map(action => (
|
{[ACTION.Back, ACTION.Forward].map(action => (
|
||||||
<div
|
<div
|
||||||
onClick={() => handleNavigate(action)}
|
onClick={() => handleNavigate(action)}
|
||||||
key={action}
|
key={action}
|
||||||
|
@ -18,7 +18,7 @@ const PlayOrPauseButtonInTrack = memo(
|
|||||||
|
|
||||||
const playerSnapshot = useSnapshot(player)
|
const playerSnapshot = useSnapshot(player)
|
||||||
const isPlaying = useMemo(
|
const isPlaying = useMemo(
|
||||||
() => playerSnapshot.state === PlayerState.PLAYING,
|
() => playerSnapshot.state === PlayerState.Playing,
|
||||||
[playerSnapshot.state]
|
[playerSnapshot.state]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ const fetch = async (params: FetchAlbumParams, noCache?: boolean) => {
|
|||||||
|
|
||||||
export default function useAlbum(params: FetchAlbumParams, noCache?: boolean) {
|
export default function useAlbum(params: FetchAlbumParams, noCache?: boolean) {
|
||||||
return useQuery(
|
return useQuery(
|
||||||
[AlbumApiNames.FETCH_ALBUM, params.id],
|
[AlbumApiNames.FetchAlbum, params.id],
|
||||||
() => fetch(params, noCache),
|
() => fetch(params, noCache),
|
||||||
{
|
{
|
||||||
enabled: !!params.id,
|
enabled: !!params.id,
|
||||||
@ -36,7 +36,7 @@ export default function useAlbum(params: FetchAlbumParams, noCache?: boolean) {
|
|||||||
|
|
||||||
export function fetchAlbumWithReactQuery(params: FetchAlbumParams) {
|
export function fetchAlbumWithReactQuery(params: FetchAlbumParams) {
|
||||||
return reactQueryClient.fetchQuery(
|
return reactQueryClient.fetchQuery(
|
||||||
[AlbumApiNames.FETCH_ALBUM, params.id],
|
[AlbumApiNames.FetchAlbum, params.id],
|
||||||
() => fetch(params),
|
() => fetch(params),
|
||||||
{
|
{
|
||||||
staleTime: Infinity,
|
staleTime: Infinity,
|
||||||
@ -46,7 +46,7 @@ export function fetchAlbumWithReactQuery(params: FetchAlbumParams) {
|
|||||||
|
|
||||||
export async function prefetchAlbum(params: FetchAlbumParams) {
|
export async function prefetchAlbum(params: FetchAlbumParams) {
|
||||||
await reactQueryClient.prefetchQuery(
|
await reactQueryClient.prefetchQuery(
|
||||||
[AlbumApiNames.FETCH_ALBUM, params.id],
|
[AlbumApiNames.FetchAlbum, params.id],
|
||||||
() => fetch(params),
|
() => fetch(params),
|
||||||
{
|
{
|
||||||
staleTime: Infinity,
|
staleTime: Infinity,
|
||||||
|
@ -12,7 +12,7 @@ export default function useArtist(
|
|||||||
noCache?: boolean
|
noCache?: boolean
|
||||||
) {
|
) {
|
||||||
return useQuery(
|
return useQuery(
|
||||||
[ArtistApiNames.FETCH_ARTIST, params],
|
[ArtistApiNames.FetchArtist, params],
|
||||||
() => fetchArtist(params, !!noCache),
|
() => fetchArtist(params, !!noCache),
|
||||||
{
|
{
|
||||||
enabled: !!params.id && params.id > 0 && !isNaN(Number(params.id)),
|
enabled: !!params.id && params.id > 0 && !isNaN(Number(params.id)),
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
|
|
||||||
export default function useUserAlbums(params: FetchArtistAlbumsParams) {
|
export default function useUserAlbums(params: FetchArtistAlbumsParams) {
|
||||||
return useQuery(
|
return useQuery(
|
||||||
[ArtistApiNames.FETCH_ARTIST_ALBUMS, params],
|
[ArtistApiNames.FetchArtistAlbums, params],
|
||||||
async () => {
|
async () => {
|
||||||
const data = await fetchArtistAlbums(params)
|
const data = await fetchArtistAlbums(params)
|
||||||
return data
|
return data
|
||||||
|
@ -10,7 +10,7 @@ import { IpcChannels } from '@/shared/IpcChannels'
|
|||||||
|
|
||||||
export default function useLyric(params: FetchLyricParams) {
|
export default function useLyric(params: FetchLyricParams) {
|
||||||
return useQuery(
|
return useQuery(
|
||||||
[TrackApiNames.FETCH_LYRIC, params],
|
[TrackApiNames.FetchLyric, params],
|
||||||
() => {
|
() => {
|
||||||
return fetchLyric(params)
|
return fetchLyric(params)
|
||||||
},
|
},
|
||||||
@ -31,7 +31,7 @@ export default function useLyric(params: FetchLyricParams) {
|
|||||||
|
|
||||||
export function fetchTracksWithReactQuery(params: FetchLyricParams) {
|
export function fetchTracksWithReactQuery(params: FetchLyricParams) {
|
||||||
return reactQueryClient.fetchQuery(
|
return reactQueryClient.fetchQuery(
|
||||||
[TrackApiNames.FETCH_LYRIC, params],
|
[TrackApiNames.FetchLyric, params],
|
||||||
() => {
|
() => {
|
||||||
return fetchLyric(params)
|
return fetchLyric(params)
|
||||||
},
|
},
|
||||||
|
@ -3,7 +3,7 @@ import reactQueryClient from '@/renderer/utils/reactQueryClient'
|
|||||||
|
|
||||||
export function fetchPersonalFMWithReactQuery() {
|
export function fetchPersonalFMWithReactQuery() {
|
||||||
return reactQueryClient.fetchQuery(
|
return reactQueryClient.fetchQuery(
|
||||||
PersonalFMApiNames.FETCH_PERSONAL_FM,
|
PersonalFMApiNames.FetchPersonalFm,
|
||||||
async () => {
|
async () => {
|
||||||
const data = await fetchPersonalFM()
|
const data = await fetchPersonalFM()
|
||||||
if (!data.data?.length) {
|
if (!data.data?.length) {
|
||||||
|
@ -17,7 +17,7 @@ export default function usePlaylist(
|
|||||||
noCache?: boolean
|
noCache?: boolean
|
||||||
) {
|
) {
|
||||||
return useQuery(
|
return useQuery(
|
||||||
[PlaylistApiNames.FETCH_PLAYLIST, params],
|
[PlaylistApiNames.FetchPlaylist, params],
|
||||||
() => fetch(params, noCache),
|
() => fetch(params, noCache),
|
||||||
{
|
{
|
||||||
enabled: !!(params.id && params.id > 0 && !isNaN(Number(params.id))),
|
enabled: !!(params.id && params.id > 0 && !isNaN(Number(params.id))),
|
||||||
@ -35,7 +35,7 @@ export default function usePlaylist(
|
|||||||
|
|
||||||
export function fetchPlaylistWithReactQuery(params: FetchPlaylistParams) {
|
export function fetchPlaylistWithReactQuery(params: FetchPlaylistParams) {
|
||||||
return reactQueryClient.fetchQuery(
|
return reactQueryClient.fetchQuery(
|
||||||
[PlaylistApiNames.FETCH_PLAYLIST, params],
|
[PlaylistApiNames.FetchPlaylist, params],
|
||||||
() => fetch(params),
|
() => fetch(params),
|
||||||
{
|
{
|
||||||
staleTime: 3600000,
|
staleTime: 3600000,
|
||||||
@ -45,7 +45,7 @@ export function fetchPlaylistWithReactQuery(params: FetchPlaylistParams) {
|
|||||||
|
|
||||||
export async function prefetchPlaylist(params: FetchPlaylistParams) {
|
export async function prefetchPlaylist(params: FetchPlaylistParams) {
|
||||||
await reactQueryClient.prefetchQuery(
|
await reactQueryClient.prefetchQuery(
|
||||||
[PlaylistApiNames.FETCH_PLAYLIST, params],
|
[PlaylistApiNames.FetchPlaylist, params],
|
||||||
() => fetch(params),
|
() => fetch(params),
|
||||||
{
|
{
|
||||||
staleTime: 3600000,
|
staleTime: 3600000,
|
||||||
|
@ -12,7 +12,7 @@ import { APIs } from '@/shared/CacheAPIs'
|
|||||||
|
|
||||||
export default function useTracks(params: FetchTracksParams) {
|
export default function useTracks(params: FetchTracksParams) {
|
||||||
return useQuery(
|
return useQuery(
|
||||||
[TrackApiNames.FETCH_TRACKS, params],
|
[TrackApiNames.FetchTracks, params],
|
||||||
() => {
|
() => {
|
||||||
return fetchTracks(params)
|
return fetchTracks(params)
|
||||||
},
|
},
|
||||||
@ -33,7 +33,7 @@ export default function useTracks(params: FetchTracksParams) {
|
|||||||
|
|
||||||
export function fetchTracksWithReactQuery(params: FetchTracksParams) {
|
export function fetchTracksWithReactQuery(params: FetchTracksParams) {
|
||||||
return reactQueryClient.fetchQuery(
|
return reactQueryClient.fetchQuery(
|
||||||
[TrackApiNames.FETCH_TRACKS, params],
|
[TrackApiNames.FetchTracks, params],
|
||||||
() => {
|
() => {
|
||||||
return fetchTracks(params)
|
return fetchTracks(params)
|
||||||
},
|
},
|
||||||
@ -49,7 +49,7 @@ export function fetchTracksWithReactQuery(params: FetchTracksParams) {
|
|||||||
|
|
||||||
export function fetchAudioSourceWithReactQuery(params: FetchAudioSourceParams) {
|
export function fetchAudioSourceWithReactQuery(params: FetchAudioSourceParams) {
|
||||||
return reactQueryClient.fetchQuery(
|
return reactQueryClient.fetchQuery(
|
||||||
[TrackApiNames.FETCH_AUDIO_SOURCE, params],
|
[TrackApiNames.FetchAudioSource, params],
|
||||||
() => {
|
() => {
|
||||||
return fetchAudioSource(params)
|
return fetchAudioSource(params)
|
||||||
},
|
},
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { FetchTracksParams, TrackApiNames } from '@/shared/api/Track'
|
import { FetchTracksParams, TrackApiNames } from '@/shared/api/Track'
|
||||||
import { fetchTracks } from 'api/track'
|
import { fetchTracks } from '../api/track'
|
||||||
|
|
||||||
// 100 tracks each page
|
// 100 tracks each page
|
||||||
const offset = 100
|
const offset = 100
|
||||||
|
|
||||||
export default function useTracksInfinite(params: FetchTracksParams) {
|
export default function useTracksInfinite(params: FetchTracksParams) {
|
||||||
return useInfiniteQuery(
|
return useInfiniteQuery(
|
||||||
[TrackApiNames.FETCH_TRACKS, params],
|
[TrackApiNames.FetchTracks, params],
|
||||||
({ pageParam = 0 }) => {
|
({ pageParam = 0 }) => {
|
||||||
const cursorStart = pageParam * offset
|
const cursorStart = pageParam * offset
|
||||||
const cursorEnd = cursorStart + offset
|
const cursorEnd = cursorStart + offset
|
||||||
|
@ -4,7 +4,7 @@ import { APIs } from '@/shared/CacheAPIs'
|
|||||||
import { IpcChannels } from '@/shared/IpcChannels'
|
import { IpcChannels } from '@/shared/IpcChannels'
|
||||||
|
|
||||||
export default function useUser() {
|
export default function useUser() {
|
||||||
return useQuery(UserApiNames.FETCH_USER_ACCOUNT, fetchUserAccount, {
|
return useQuery(UserApiNames.FetchUserAccount, fetchUserAccount, {
|
||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
placeholderData: (): FetchUserAccountResponse | undefined =>
|
placeholderData: (): FetchUserAccountResponse | undefined =>
|
||||||
window.ipcRenderer?.sendSync(IpcChannels.GetApiCacheSync, {
|
window.ipcRenderer?.sendSync(IpcChannels.GetApiCacheSync, {
|
||||||
|
@ -8,12 +8,12 @@ import {
|
|||||||
UserApiNames,
|
UserApiNames,
|
||||||
FetchUserAlbumsResponse,
|
FetchUserAlbumsResponse,
|
||||||
} from '@/shared/api/User'
|
} from '@/shared/api/User'
|
||||||
import { fetchUserAlbums } from 'api/user'
|
import { fetchUserAlbums } from '../api/user'
|
||||||
|
|
||||||
export default function useUserAlbums(params: FetchUserAlbumsParams = {}) {
|
export default function useUserAlbums(params: FetchUserAlbumsParams = {}) {
|
||||||
const { data: user } = useUser()
|
const { data: user } = useUser()
|
||||||
return useQuery(
|
return useQuery(
|
||||||
[UserApiNames.FETCH_USER_ALBUMS, user?.profile?.userId ?? 0],
|
[UserApiNames.FetchUserAlbums, user?.profile?.userId ?? 0],
|
||||||
() => fetchUserAlbums(params),
|
() => fetchUserAlbums(params),
|
||||||
{
|
{
|
||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
@ -31,7 +31,7 @@ export const useMutationLikeAAlbum = () => {
|
|||||||
const { data: user } = useUser()
|
const { data: user } = useUser()
|
||||||
const { data: userAlbums } = useUserAlbums({ limit: 2000 })
|
const { data: userAlbums } = useUserAlbums({ limit: 2000 })
|
||||||
const uid = user?.account?.id ?? 0
|
const uid = user?.account?.id ?? 0
|
||||||
const key = [UserApiNames.FETCH_USER_ALBUMS, uid]
|
const key = [UserApiNames.FetchUserAlbums, uid]
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (album: Album) => {
|
async (album: Album) => {
|
||||||
|
@ -4,7 +4,7 @@ import { APIs } from '@/shared/CacheAPIs'
|
|||||||
import { IpcChannels } from '@/shared/IpcChannels'
|
import { IpcChannels } from '@/shared/IpcChannels'
|
||||||
|
|
||||||
export default function useUserArtists() {
|
export default function useUserArtists() {
|
||||||
return useQuery([UserApiNames.FETCH_USER_ARTIST], fetchUserArtists, {
|
return useQuery([UserApiNames.FetchUserArtist], fetchUserArtists, {
|
||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
placeholderData: (): FetchUserArtistsResponse =>
|
placeholderData: (): FetchUserArtistsResponse =>
|
||||||
window.ipcRenderer?.sendSync(IpcChannels.GetApiCacheSync, {
|
window.ipcRenderer?.sendSync(IpcChannels.GetApiCacheSync, {
|
||||||
|
@ -3,7 +3,7 @@ import useUser from './useUser'
|
|||||||
import { useQueryClient } from 'react-query'
|
import { useQueryClient } from 'react-query'
|
||||||
import { IpcChannels } from '@/shared/IpcChannels'
|
import { IpcChannels } from '@/shared/IpcChannels'
|
||||||
import { APIs } from '@/shared/CacheAPIs'
|
import { APIs } from '@/shared/CacheAPIs'
|
||||||
import { fetchUserLikedTracksIDs } from 'api/user'
|
import { fetchUserLikedTracksIDs } from '../api/user'
|
||||||
import {
|
import {
|
||||||
FetchUserLikedTracksIDsResponse,
|
FetchUserLikedTracksIDsResponse,
|
||||||
UserApiNames,
|
UserApiNames,
|
||||||
@ -14,7 +14,7 @@ export default function useUserLikedTracksIDs() {
|
|||||||
const uid = user?.account?.id ?? 0
|
const uid = user?.account?.id ?? 0
|
||||||
|
|
||||||
return useQuery(
|
return useQuery(
|
||||||
[UserApiNames.FETCH_USER_LIKED_TRACKS_IDS, uid],
|
[UserApiNames.FetchUserLikedTracksIds, uid],
|
||||||
() => fetchUserLikedTracksIDs({ uid }),
|
() => fetchUserLikedTracksIDs({ uid }),
|
||||||
{
|
{
|
||||||
enabled: !!(uid && uid !== 0),
|
enabled: !!(uid && uid !== 0),
|
||||||
@ -35,7 +35,7 @@ export const useMutationLikeATrack = () => {
|
|||||||
const { data: user } = useUser()
|
const { data: user } = useUser()
|
||||||
const { data: userLikedSongs } = useUserLikedTracksIDs()
|
const { data: userLikedSongs } = useUserLikedTracksIDs()
|
||||||
const uid = user?.account?.id ?? 0
|
const uid = user?.account?.id ?? 0
|
||||||
const key = [UserApiNames.FETCH_USER_LIKED_TRACKS_IDS, uid]
|
const key = [UserApiNames.FetchUserLikedTracksIds, uid]
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (trackID: number) => {
|
async (trackID: number) => {
|
||||||
|
@ -3,7 +3,7 @@ import { useQueryClient } from 'react-query'
|
|||||||
import useUser from './useUser'
|
import useUser from './useUser'
|
||||||
import { IpcChannels } from '@/shared/IpcChannels'
|
import { IpcChannels } from '@/shared/IpcChannels'
|
||||||
import { APIs } from '@/shared/CacheAPIs'
|
import { APIs } from '@/shared/CacheAPIs'
|
||||||
import { fetchUserPlaylists } from 'api/user'
|
import { fetchUserPlaylists } from '@/renderer/api/user'
|
||||||
import { FetchUserPlaylistsResponse, UserApiNames } from '@/shared/api/User'
|
import { FetchUserPlaylistsResponse, UserApiNames } from '@/shared/api/User'
|
||||||
|
|
||||||
export default function useUserPlaylists() {
|
export default function useUserPlaylists() {
|
||||||
@ -17,7 +17,7 @@ export default function useUserPlaylists() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return useQuery(
|
return useQuery(
|
||||||
[UserApiNames.FETCH_USER_PLAYLISTS, uid],
|
[UserApiNames.FetchUserPlaylists, uid],
|
||||||
async () => {
|
async () => {
|
||||||
if (!params.uid) {
|
if (!params.uid) {
|
||||||
throw new Error('请登录后再请求用户收藏的歌单')
|
throw new Error('请登录后再请求用户收藏的歌单')
|
||||||
@ -48,7 +48,7 @@ export const useMutationLikeAPlaylist = () => {
|
|||||||
const { data: user } = useUser()
|
const { data: user } = useUser()
|
||||||
const { data: userPlaylists } = useUserPlaylists()
|
const { data: userPlaylists } = useUserPlaylists()
|
||||||
const uid = user?.account?.id ?? 0
|
const uid = user?.account?.id ?? 0
|
||||||
const key = [UserApiNames.FETCH_USER_PLAYLISTS, uid]
|
const key = [UserApiNames.FetchUserPlaylists, uid]
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (playlist: Playlist) => {
|
async (playlist: Playlist) => {
|
||||||
|
@ -23,7 +23,6 @@ import useTracks from '@/renderer/hooks/useTracks'
|
|||||||
import useUserAlbums, {
|
import useUserAlbums, {
|
||||||
useMutationLikeAAlbum,
|
useMutationLikeAAlbum,
|
||||||
} from '@/renderer/hooks/useUserAlbums'
|
} from '@/renderer/hooks/useUserAlbums'
|
||||||
import useUser from '@/renderer/hooks/useUser'
|
|
||||||
|
|
||||||
const PlayButton = ({
|
const PlayButton = ({
|
||||||
album,
|
album,
|
||||||
@ -38,7 +37,7 @@ const PlayButton = ({
|
|||||||
const isThisAlbumPlaying = useMemo(
|
const isThisAlbumPlaying = useMemo(
|
||||||
() =>
|
() =>
|
||||||
playerSnapshot.mode === PlayerMode.TrackList &&
|
playerSnapshot.mode === PlayerMode.TrackList &&
|
||||||
playerSnapshot.trackListSource?.type === TrackListSourceType.ALBUM &&
|
playerSnapshot.trackListSource?.type === TrackListSourceType.Album &&
|
||||||
playerSnapshot.trackListSource?.id === album?.id,
|
playerSnapshot.trackListSource?.id === album?.id,
|
||||||
[
|
[
|
||||||
playerSnapshot.mode,
|
playerSnapshot.mode,
|
||||||
@ -50,7 +49,7 @@ const PlayButton = ({
|
|||||||
|
|
||||||
const isPlaying =
|
const isPlaying =
|
||||||
isThisAlbumPlaying &&
|
isThisAlbumPlaying &&
|
||||||
[PlayerState.PLAYING, PlayerState.LOADING].includes(playerSnapshot.state)
|
[PlayerState.Playing, PlayerState.Loading].includes(playerSnapshot.state)
|
||||||
|
|
||||||
const wrappedHandlePlay = () => {
|
const wrappedHandlePlay = () => {
|
||||||
if (isThisAlbumPlaying) {
|
if (isThisAlbumPlaying) {
|
||||||
@ -301,7 +300,7 @@ const MoreAlbum = ({ album }: { album: Album | undefined }) => {
|
|||||||
albums={
|
albums={
|
||||||
filteredAlbums.length ? filteredAlbums : albums?.hotAlbums || []
|
filteredAlbums.length ? filteredAlbums : albums?.hotAlbums || []
|
||||||
}
|
}
|
||||||
subtitle={Subtitle.TYPE_RELEASE_YEAR}
|
subtitle={Subtitle.TypeReleaseYear}
|
||||||
isSkeleton={isLoading}
|
isSkeleton={isLoading}
|
||||||
rows={1}
|
rows={1}
|
||||||
navigateCallback={scrollToTop}
|
navigateCallback={scrollToTop}
|
||||||
|
@ -207,7 +207,7 @@ const Artist = () => {
|
|||||||
</div>
|
</div>
|
||||||
<CoverRow
|
<CoverRow
|
||||||
albums={albums.slice(0, 10)}
|
albums={albums.slice(0, 10)}
|
||||||
subtitle={Subtitle.TYPE_RELEASE_YEAR}
|
subtitle={Subtitle.TypeReleaseYear}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -220,7 +220,7 @@ const Artist = () => {
|
|||||||
</div>
|
</div>
|
||||||
<CoverRow
|
<CoverRow
|
||||||
albums={singles.slice(0, 5)}
|
albums={singles.slice(0, 5)}
|
||||||
subtitle={Subtitle.TYPE_RELEASE_YEAR}
|
subtitle={Subtitle.TypeReleaseYear}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -14,7 +14,7 @@ export default function Home() {
|
|||||||
data: dailyRecommendPlaylists,
|
data: dailyRecommendPlaylists,
|
||||||
isLoading: isLoadingDailyRecommendPlaylists,
|
isLoading: isLoadingDailyRecommendPlaylists,
|
||||||
} = useQuery(
|
} = useQuery(
|
||||||
PlaylistApiNames.FETCH_DAILY_RECOMMEND_PLAYLISTS,
|
PlaylistApiNames.FetchDailyRecommendPlaylists,
|
||||||
fetchDailyRecommendPlaylists,
|
fetchDailyRecommendPlaylists,
|
||||||
{
|
{
|
||||||
retry: false,
|
retry: false,
|
||||||
@ -29,7 +29,7 @@ export default function Home() {
|
|||||||
data: recommendedPlaylists,
|
data: recommendedPlaylists,
|
||||||
isLoading: isLoadingRecommendedPlaylists,
|
isLoading: isLoadingRecommendedPlaylists,
|
||||||
} = useQuery(
|
} = useQuery(
|
||||||
PlaylistApiNames.FETCH_RECOMMENDED_PLAYLISTS,
|
PlaylistApiNames.FetchRecommendedPlaylists,
|
||||||
() => {
|
() => {
|
||||||
return fetchRecommendedPlaylists({})
|
return fetchRecommendedPlaylists({})
|
||||||
},
|
},
|
||||||
|
@ -127,7 +127,7 @@ const Playlists = () => {
|
|||||||
<div>
|
<div>
|
||||||
<CoverRow
|
<CoverRow
|
||||||
playlists={playlists?.playlist?.slice(1) ?? []}
|
playlists={playlists?.playlist?.slice(1) ?? []}
|
||||||
subtitle={Subtitle.CREATOR}
|
subtitle={Subtitle.Creator}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@ -140,7 +140,7 @@ const Albums = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<CoverRow albums={albums?.data ?? []} subtitle={Subtitle.ARTIST} />
|
<CoverRow albums={albums?.data ?? []} subtitle={Subtitle.Artist} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ const Artists = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<CoverRow artists={artists?.data ?? []} subtitle={Subtitle.ARTIST} />
|
<CoverRow artists={artists?.data ?? []} subtitle={Subtitle.Artist} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,9 @@ import { setCookies } from '@/renderer/utils/cookie'
|
|||||||
import { useInterval } from 'react-use'
|
import { useInterval } from 'react-use'
|
||||||
|
|
||||||
enum Method {
|
enum Method {
|
||||||
QRCODE = 'qrcode',
|
QrCode = 'qrcode',
|
||||||
EMAIL = 'email',
|
Email = 'email',
|
||||||
PHONE = 'phone',
|
Phone = 'phone',
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shared components and methods
|
// Shared components and methods
|
||||||
@ -152,15 +152,15 @@ const OtherLoginMethods = ({
|
|||||||
name: string
|
name: string
|
||||||
}[] = [
|
}[] = [
|
||||||
{
|
{
|
||||||
id: Method.QRCODE,
|
id: Method.QrCode,
|
||||||
name: '二维码',
|
name: '二维码',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: Method.EMAIL,
|
id: Method.Email,
|
||||||
name: '邮箱',
|
name: '邮箱',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: Method.PHONE,
|
id: Method.Phone,
|
||||||
name: '手机',
|
name: '手机',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -393,14 +393,14 @@ const LoginWithQRCode = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const [method, setMethod] = useState<Method>(Method.PHONE)
|
const [method, setMethod] = useState<Method>(Method.Phone)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='grid h-full place-content-center'>
|
<div className='grid h-full place-content-center'>
|
||||||
<div className='w-80'>
|
<div className='w-80'>
|
||||||
{method === Method.EMAIL && <LoginWithEmail />}
|
{method === Method.Email && <LoginWithEmail />}
|
||||||
{method === Method.PHONE && <LoginWithPhone />}
|
{method === Method.Phone && <LoginWithPhone />}
|
||||||
{method === Method.QRCODE && <LoginWithQRCode />}
|
{method === Method.QrCode && <LoginWithQRCode />}
|
||||||
<OtherLoginMethods {...{ method, setMethod }} />
|
<OtherLoginMethods {...{ method, setMethod }} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -33,7 +33,7 @@ const PlayButton = ({
|
|||||||
const isThisPlaylistPlaying = useMemo(
|
const isThisPlaylistPlaying = useMemo(
|
||||||
() =>
|
() =>
|
||||||
playerSnapshot.mode === PlayerMode.TrackList &&
|
playerSnapshot.mode === PlayerMode.TrackList &&
|
||||||
playerSnapshot.trackListSource?.type === TrackListSourceType.PLAYLIST &&
|
playerSnapshot.trackListSource?.type === TrackListSourceType.Playlist &&
|
||||||
playerSnapshot.trackListSource?.id === playlist?.id,
|
playerSnapshot.trackListSource?.id === playlist?.id,
|
||||||
[
|
[
|
||||||
playerSnapshot.mode,
|
playerSnapshot.mode,
|
||||||
@ -53,7 +53,7 @@ const PlayButton = ({
|
|||||||
|
|
||||||
const isPlaying =
|
const isPlaying =
|
||||||
isThisPlaylistPlaying &&
|
isThisPlaylistPlaying &&
|
||||||
[PlayerState.PLAYING, PlayerState.LOADING].includes(playerSnapshot.state)
|
[PlayerState.Playing, PlayerState.Loading].includes(playerSnapshot.state)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button onClick={wrappedHandlePlay} isSkelton={isLoading}>
|
<Button onClick={wrappedHandlePlay} isSkelton={isLoading}>
|
||||||
|
@ -69,15 +69,15 @@ const Albums = ({ albums }: { albums: Album[] }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Search = () => {
|
const Search = () => {
|
||||||
const { keywords = '', type = 'ALL' } = useParams()
|
const { keywords = '', type = 'all' } = useParams()
|
||||||
|
|
||||||
const searchType: keyof typeof SearchTypes =
|
const searchType: keyof typeof SearchTypes =
|
||||||
type.toUpperCase() in SearchTypes
|
type.toUpperCase() in SearchTypes
|
||||||
? (type.toUpperCase() as keyof typeof SearchTypes)
|
? (type.toUpperCase() as keyof typeof SearchTypes)
|
||||||
: 'ALL'
|
: 'All'
|
||||||
|
|
||||||
const { data: bestMatchRaw, isLoading: isLoadingBestMatch } = useQuery(
|
const { data: bestMatchRaw, isLoading: isLoadingBestMatch } = useQuery(
|
||||||
[SearchApiNames.MULTI_MATCH_SEARCH, keywords],
|
[SearchApiNames.MultiMatchSearch, keywords],
|
||||||
() => multiMatchSearch({ keywords })
|
() => multiMatchSearch({ keywords })
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ const Search = () => {
|
|||||||
}, [bestMatchRaw?.result])
|
}, [bestMatchRaw?.result])
|
||||||
|
|
||||||
const { data: searchResult, isLoading: isLoadingSearchResult } = useQuery(
|
const { data: searchResult, isLoading: isLoadingSearchResult } = useQuery(
|
||||||
[SearchApiNames.SEARCH, keywords, searchType],
|
[SearchApiNames.Search, keywords, searchType],
|
||||||
() => search({ keywords, type: searchType })
|
() => search({ keywords, type: searchType })
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ import { fetchAlbumWithReactQuery } from '@/renderer/hooks/useAlbum'
|
|||||||
|
|
||||||
type TrackID = number
|
type TrackID = number
|
||||||
export enum TrackListSourceType {
|
export enum TrackListSourceType {
|
||||||
ALBUM = 'album',
|
Album = 'album',
|
||||||
PLAYLIST = 'playlist',
|
Playlist = 'playlist',
|
||||||
}
|
}
|
||||||
interface TrackListSource {
|
interface TrackListSource {
|
||||||
type: TrackListSourceType
|
type: TrackListSourceType
|
||||||
@ -26,16 +26,16 @@ export enum Mode {
|
|||||||
FM = 'fm',
|
FM = 'fm',
|
||||||
}
|
}
|
||||||
export enum State {
|
export enum State {
|
||||||
INITIALIZING = 'initializing',
|
Initializing = 'initializing',
|
||||||
READY = 'ready',
|
Ready = 'ready',
|
||||||
PLAYING = 'playing',
|
Playing = 'playing',
|
||||||
PAUSED = 'paused',
|
Paused = 'paused',
|
||||||
LOADING = 'loading',
|
Loading = 'loading',
|
||||||
}
|
}
|
||||||
export enum RepeatMode {
|
export enum RepeatMode {
|
||||||
OFF = 'off',
|
Off = 'off',
|
||||||
ON = 'on',
|
On = 'on',
|
||||||
ONE = 'one',
|
One = 'one',
|
||||||
}
|
}
|
||||||
|
|
||||||
const PLAY_PAUSE_FADE_DURATION = 200
|
const PLAY_PAUSE_FADE_DURATION = 200
|
||||||
@ -48,13 +48,13 @@ export class Player {
|
|||||||
private _progressInterval: ReturnType<typeof setInterval> | undefined
|
private _progressInterval: ReturnType<typeof setInterval> | undefined
|
||||||
private _volume: number = 1 // 0 to 1
|
private _volume: number = 1 // 0 to 1
|
||||||
|
|
||||||
state: State = State.INITIALIZING
|
state: State = State.Initializing
|
||||||
mode: Mode = Mode.TrackList
|
mode: Mode = Mode.TrackList
|
||||||
trackList: TrackID[] = []
|
trackList: TrackID[] = []
|
||||||
trackListSource: TrackListSource | null = null
|
trackListSource: TrackListSource | null = null
|
||||||
fmTrackList: TrackID[] = []
|
fmTrackList: TrackID[] = []
|
||||||
shuffle: boolean = false
|
shuffle: boolean = false
|
||||||
repeatMode: RepeatMode = RepeatMode.OFF
|
repeatMode: RepeatMode = RepeatMode.Off
|
||||||
fmTrack: Track | null = null
|
fmTrack: Track | null = null
|
||||||
|
|
||||||
init(params: { [key: string]: any }) {
|
init(params: { [key: string]: any }) {
|
||||||
@ -70,7 +70,7 @@ export class Player {
|
|||||||
if (params.repeatMode) this.repeatMode = params.repeatMode
|
if (params.repeatMode) this.repeatMode = params.repeatMode
|
||||||
if (params.fmTrack) this.fmTrack = params.fmTrack
|
if (params.fmTrack) this.fmTrack = params.fmTrack
|
||||||
|
|
||||||
this.state = State.READY
|
this.state = State.Ready
|
||||||
this._playAudio(false) // just load the audio, not play
|
this._playAudio(false) // just load the audio, not play
|
||||||
this._initFM()
|
this._initFM()
|
||||||
}
|
}
|
||||||
@ -84,12 +84,12 @@ export class Player {
|
|||||||
*/
|
*/
|
||||||
get _prevTrackIndex(): number | undefined {
|
get _prevTrackIndex(): number | undefined {
|
||||||
switch (this.repeatMode) {
|
switch (this.repeatMode) {
|
||||||
case RepeatMode.ONE:
|
case RepeatMode.One:
|
||||||
return this._trackIndex
|
return this._trackIndex
|
||||||
case RepeatMode.OFF:
|
case RepeatMode.Off:
|
||||||
if (this._trackIndex === 0) return 0
|
if (this._trackIndex === 0) return 0
|
||||||
return this._trackIndex - 1
|
return this._trackIndex - 1
|
||||||
case RepeatMode.ON:
|
case RepeatMode.On:
|
||||||
if (this._trackIndex - 1 < 0) return this.trackList.length - 1
|
if (this._trackIndex - 1 < 0) return this.trackList.length - 1
|
||||||
return this._trackIndex - 1
|
return this._trackIndex - 1
|
||||||
}
|
}
|
||||||
@ -100,12 +100,12 @@ export class Player {
|
|||||||
*/
|
*/
|
||||||
get _nextTrackIndex(): number | undefined {
|
get _nextTrackIndex(): number | undefined {
|
||||||
switch (this.repeatMode) {
|
switch (this.repeatMode) {
|
||||||
case RepeatMode.ONE:
|
case RepeatMode.One:
|
||||||
return this._trackIndex
|
return this._trackIndex
|
||||||
case RepeatMode.OFF:
|
case RepeatMode.Off:
|
||||||
if (this._trackIndex + 1 >= this.trackList.length) return
|
if (this._trackIndex + 1 >= this.trackList.length) return
|
||||||
return this._trackIndex + 1
|
return this._trackIndex + 1
|
||||||
case RepeatMode.ON:
|
case RepeatMode.On:
|
||||||
if (this._trackIndex + 1 >= this.trackList.length) return 0
|
if (this._trackIndex + 1 >= this.trackList.length) return 0
|
||||||
return this._trackIndex + 1
|
return this._trackIndex + 1
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ export class Player {
|
|||||||
* Get/Set progress of current track
|
* Get/Set progress of current track
|
||||||
*/
|
*/
|
||||||
get progress(): number {
|
get progress(): number {
|
||||||
return this.state === State.LOADING ? 0 : this._progress
|
return this.state === State.Loading ? 0 : this._progress
|
||||||
}
|
}
|
||||||
set progress(value) {
|
set progress(value) {
|
||||||
this._progress = value
|
this._progress = value
|
||||||
@ -163,7 +163,7 @@ export class Player {
|
|||||||
|
|
||||||
private _setupProgressInterval() {
|
private _setupProgressInterval() {
|
||||||
this._progressInterval = setInterval(() => {
|
this._progressInterval = setInterval(() => {
|
||||||
if (this.state === State.PLAYING) this._progress = _howler.seek()
|
if (this.state === State.Playing) this._progress = _howler.seek()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ export class Player {
|
|||||||
private async _playTrack() {
|
private async _playTrack() {
|
||||||
const id = this.trackID
|
const id = this.trackID
|
||||||
if (!id) return
|
if (!id) return
|
||||||
this.state = State.LOADING
|
this.state = State.Loading
|
||||||
const track = await this._fetchTrack(id)
|
const track = await this._fetchTrack(id)
|
||||||
if (!track) {
|
if (!track) {
|
||||||
toast('加载歌曲信息失败')
|
toast('加载歌曲信息失败')
|
||||||
@ -228,7 +228,7 @@ export class Player {
|
|||||||
_howler = howler
|
_howler = howler
|
||||||
if (autoplay) {
|
if (autoplay) {
|
||||||
this.play()
|
this.play()
|
||||||
this.state = State.PLAYING
|
this.state = State.Playing
|
||||||
}
|
}
|
||||||
_howler.once('load', () => {
|
_howler.once('load', () => {
|
||||||
this._cacheAudio((_howler as any)._src)
|
this._cacheAudio((_howler as any)._src)
|
||||||
@ -240,7 +240,7 @@ export class Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _howlerOnEndCallback() {
|
private _howlerOnEndCallback() {
|
||||||
if (this.mode !== Mode.FM && this.repeatMode === RepeatMode.ONE) {
|
if (this.mode !== Mode.FM && this.repeatMode === RepeatMode.One) {
|
||||||
_howler.seek(0)
|
_howler.seek(0)
|
||||||
_howler.play()
|
_howler.play()
|
||||||
} else {
|
} else {
|
||||||
@ -288,18 +288,18 @@ export class Player {
|
|||||||
*/
|
*/
|
||||||
play(fade: boolean = false) {
|
play(fade: boolean = false) {
|
||||||
if (_howler.playing()) {
|
if (_howler.playing()) {
|
||||||
this.state = State.PLAYING
|
this.state = State.Playing
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_howler.play()
|
_howler.play()
|
||||||
if (fade) {
|
if (fade) {
|
||||||
this.state = State.PLAYING
|
this.state = State.Playing
|
||||||
_howler.once('play', () => {
|
_howler.once('play', () => {
|
||||||
_howler.fade(0, this._volume, PLAY_PAUSE_FADE_DURATION)
|
_howler.fade(0, this._volume, PLAY_PAUSE_FADE_DURATION)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.state = State.PLAYING
|
this.state = State.Playing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,12 +310,12 @@ export class Player {
|
|||||||
pause(fade: boolean = false) {
|
pause(fade: boolean = false) {
|
||||||
if (fade) {
|
if (fade) {
|
||||||
_howler.fade(this._volume, 0, PLAY_PAUSE_FADE_DURATION)
|
_howler.fade(this._volume, 0, PLAY_PAUSE_FADE_DURATION)
|
||||||
this.state = State.PAUSED
|
this.state = State.Paused
|
||||||
_howler.once('fade', () => {
|
_howler.once('fade', () => {
|
||||||
_howler.pause()
|
_howler.pause()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.state = State.PAUSED
|
this.state = State.Paused
|
||||||
_howler.pause()
|
_howler.pause()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -325,7 +325,7 @@ export class Player {
|
|||||||
* @param {boolean} fade fade in-out
|
* @param {boolean} fade fade in-out
|
||||||
*/
|
*/
|
||||||
playOrPause(fade: boolean = true) {
|
playOrPause(fade: boolean = true) {
|
||||||
this.state === State.PLAYING ? this.pause(fade) : this.play(fade)
|
this.state === State.Playing ? this.pause(fade) : this.play(fade)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -387,7 +387,7 @@ export class Player {
|
|||||||
const playlist = await fetchPlaylistWithReactQuery({ id: playlistID })
|
const playlist = await fetchPlaylistWithReactQuery({ id: playlistID })
|
||||||
if (!playlist?.playlist?.trackIds?.length) return
|
if (!playlist?.playlist?.trackIds?.length) return
|
||||||
this.trackListSource = {
|
this.trackListSource = {
|
||||||
type: TrackListSourceType.PLAYLIST,
|
type: TrackListSourceType.Playlist,
|
||||||
id: playlistID,
|
id: playlistID,
|
||||||
}
|
}
|
||||||
this.playAList(
|
this.playAList(
|
||||||
@ -405,7 +405,7 @@ export class Player {
|
|||||||
const album = await fetchAlbumWithReactQuery({ id: albumID })
|
const album = await fetchAlbumWithReactQuery({ id: albumID })
|
||||||
if (!album?.songs?.length) return
|
if (!album?.songs?.length) return
|
||||||
this.trackListSource = {
|
this.trackListSource = {
|
||||||
type: TrackListSourceType.ALBUM,
|
type: TrackListSourceType.Album,
|
||||||
id: albumID,
|
id: albumID,
|
||||||
}
|
}
|
||||||
this._playTrack()
|
this._playTrack()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export enum AlbumApiNames {
|
export enum AlbumApiNames {
|
||||||
FETCH_ALBUM = 'fetchAlbum',
|
FetchAlbum = 'fetchAlbum',
|
||||||
}
|
}
|
||||||
|
|
||||||
// 专辑详情
|
// 专辑详情
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export enum ArtistApiNames {
|
export enum ArtistApiNames {
|
||||||
FETCH_ARTIST = 'fetchArtist',
|
FetchArtist = 'fetchArtist',
|
||||||
FETCH_ARTIST_ALBUMS = 'fetchArtistAlbums',
|
FetchArtistAlbums = 'fetchArtistAlbums',
|
||||||
}
|
}
|
||||||
|
|
||||||
// 歌手详情
|
// 歌手详情
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
export enum PlaylistApiNames {
|
export enum PlaylistApiNames {
|
||||||
FETCH_PLAYLIST = 'fetchPlaylist',
|
FetchPlaylist = 'fetchPlaylist',
|
||||||
FETCH_RECOMMENDED_PLAYLISTS = 'fetchRecommendedPlaylists',
|
FetchRecommendedPlaylists = 'fetchRecommendedPlaylists',
|
||||||
FETCH_DAILY_RECOMMEND_PLAYLISTS = 'fetchDailyRecommendPlaylists',
|
FetchDailyRecommendPlaylists = 'fetchDailyRecommendPlaylists',
|
||||||
LIKE_A_PLAYLIST = 'likeAPlaylist',
|
LikeAPlaylist = 'likeAPlaylist',
|
||||||
}
|
}
|
||||||
|
|
||||||
// 歌单详情
|
// 歌单详情
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
export enum SearchApiNames {
|
export enum SearchApiNames {
|
||||||
SEARCH = 'search',
|
Search = 'search',
|
||||||
MULTI_MATCH_SEARCH = 'multiMatchSearch',
|
MultiMatchSearch = 'multiMatchSearch',
|
||||||
}
|
}
|
||||||
|
|
||||||
// 搜索
|
// 搜索
|
||||||
export enum SearchTypes {
|
export enum SearchTypes {
|
||||||
SINGLE = '1',
|
Single = '1',
|
||||||
ALBUM = '10',
|
Album = '10',
|
||||||
ARTIST = '100',
|
Artist = '100',
|
||||||
PLAYLIST = '1000',
|
Playlist = '1000',
|
||||||
USER = '1002',
|
User = '1002',
|
||||||
MV = '1004',
|
Mv = '1004',
|
||||||
LYRICS = '1006',
|
Lyrics = '1006',
|
||||||
RADIO = '1009',
|
Radio = '1009',
|
||||||
VIDEO = '1014',
|
Video = '1014',
|
||||||
ALL = '1018',
|
All = '1018',
|
||||||
}
|
}
|
||||||
export interface SearchParams {
|
export interface SearchParams {
|
||||||
keywords: string
|
keywords: string
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
export enum TrackApiNames {
|
export enum TrackApiNames {
|
||||||
FETCH_TRACKS = 'fetchTracks',
|
FetchTracks = 'fetchTracks',
|
||||||
FETCH_AUDIO_SOURCE = 'fetchAudioSource',
|
FetchAudioSource = 'fetchAudioSource',
|
||||||
FETCH_LYRIC = 'fetchLyric',
|
FetchLyric = 'fetchLyric',
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取歌曲详情
|
// 获取歌曲详情
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
export enum UserApiNames {
|
export enum UserApiNames {
|
||||||
FETCH_USER_ACCOUNT = 'fetchUserAccount',
|
FetchUserAccount = 'fetchUserAccount',
|
||||||
FETCH_USER_LIKED_TRACKS_IDS = 'fetchUserLikedTracksIDs',
|
FetchUserLikedTracksIds = 'fetchUserLikedTracksIDs',
|
||||||
FETCH_USER_PLAYLISTS = 'fetchUserPlaylists',
|
FetchUserPlaylists = 'fetchUserPlaylists',
|
||||||
FETCH_USER_ALBUMS = 'fetchUserAlbums',
|
FetchUserAlbums = 'fetchUserAlbums',
|
||||||
FETCH_USER_ARTIST = 'fetchUserArtists',
|
FetchUserArtist = 'fetchUserArtists',
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取账号详情
|
// 获取账号详情
|
||||||
|
Loading…
x
Reference in New Issue
Block a user