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