diff --git a/src/renderer/api/track.ts b/src/renderer/api/track.ts index 6a08b3a..cceee5b 100644 --- a/src/renderer/api/track.ts +++ b/src/renderer/api/track.ts @@ -120,3 +120,23 @@ export function fetchLyric( params, }) } + +export interface LikeATrackParams { + id: number + like: boolean +} +export interface LikeATrackResponse { + code: number + playlistId: number + songs: Track[] +} +export function likeATrack(params: LikeATrackParams) { + return request({ + url: '/like', + method: 'post', + params: { + ...params, + timestamp: Date.now(), + }, + }) +} diff --git a/src/renderer/api/user.ts b/src/renderer/api/user.ts index e4dca67..9187caa 100644 --- a/src/renderer/api/user.ts +++ b/src/renderer/api/user.ts @@ -2,7 +2,7 @@ import request from '@/utils/request' export enum UserApiNames { FETCH_USER_ACCOUNT = 'fetchUserAccount', - FETCH_USER_LIKED_SONGS_IDS = 'fetchUserLikedSongsIDs', + FETCH_USER_LIKED_TRACKS_IDS = 'fetchUserLikedTracksIDs', FETCH_USER_PLAYLISTS = 'fetchUserPlaylists', } @@ -113,17 +113,17 @@ export function fetchUserPlaylists( }) } -export interface FetchUserLikedSongsIDsParams { +export interface FetchUserLikedTracksIDsParams { uid: number } -export interface FetchUserLikedSongsIDsResponse { +export interface FetchUserLikedTracksIDsResponse { code: number checkPoint: number ids: number[] } -export function fetchUserLikedSongsIDs( - params: FetchUserLikedSongsIDsParams -): Promise { +export function fetchUserLikedTracksIDs( + params: FetchUserLikedTracksIDsParams +): Promise { return request({ url: '/likelist', method: 'get', diff --git a/src/renderer/components/Player.tsx b/src/renderer/components/Player.tsx index 84b25dc..f6f49e1 100644 --- a/src/renderer/components/Player.tsx +++ b/src/renderer/components/Player.tsx @@ -2,8 +2,9 @@ import ArtistInline from '@/components/ArtistsInline' import IconButton from '@/components/IconButton' import Slider from '@/components/Slider' import SvgIcon from '@/components/SvgIcon' -import useUser from '@/hooks/useUser' -import useUserLikedSongsIDs from '@/hooks/useUserLikedSongsIDs' +import useUserLikedTracksIDs, { + useMutationLikeATrack, +} from '@/hooks/useUserLikedTracksIDs' import { player } from '@/store' import { resizeImage } from '@/utils/common' import { State as PlayerState, Mode as PlayerMode } from '@/utils/player' @@ -18,10 +19,8 @@ const PlayingTrack = () => { ) // Liked songs ids - const { data: user } = useUser() - const { data: userLikedSongs } = useUserLikedSongsIDs({ - uid: user?.account?.id ?? 0, - }) + const { data: userLikedSongs } = useUserLikedTracksIDs() + const mutationLikeATrack = useMutationLikeATrack() const toAlbum = () => { const id = track?.al?.id @@ -65,7 +64,9 @@ const PlayingTrack = () => { - toast('施工中...')}> + track?.id && mutationLikeATrack.mutate(track.id)} + > onClick(e, track.id)} @@ -163,6 +166,7 @@ const Track = memo( {/* Like button */} {!isSkeleton && (