mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-18 06:07:48 +00:00
feat: updates
This commit is contained in:
parent
884f3df41a
commit
c6c59b2cd9
84 changed files with 3531 additions and 2616 deletions
|
|
@ -6,12 +6,10 @@ import { useQuery } from '@tanstack/react-query'
|
|||
import useUser from './useUser'
|
||||
import reactQueryClient from '@/web/utils/reactQueryClient'
|
||||
|
||||
export default function useUserListenedRecords(params: {
|
||||
type: 'week' | 'all'
|
||||
}) {
|
||||
export default function useUserListenedRecords(params: { type: 'week' | 'all' }) {
|
||||
const { data: user } = useUser()
|
||||
const uid = user?.account?.id || 0
|
||||
const key = [UserApiNames.FetchListenedRecords]
|
||||
const key = [UserApiNames.FetchListenedRecords, uid]
|
||||
|
||||
return useQuery(
|
||||
key,
|
||||
|
|
|
|||
71
packages/web/api/hooks/useUserVideos.ts
Normal file
71
packages/web/api/hooks/useUserVideos.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import {
|
||||
UserApiNames,
|
||||
FetchListenedRecordsResponse,
|
||||
FetchUserVideosResponse,
|
||||
} from '@/shared/api/User'
|
||||
import { APIs } from '@/shared/CacheAPIs'
|
||||
import { IpcChannels } from '@/shared/IpcChannels'
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import useUser from './useUser'
|
||||
import reactQueryClient from '@/web/utils/reactQueryClient'
|
||||
import { fetchUserVideos } from '../user'
|
||||
import { likeAVideo } from '../mv'
|
||||
import toast from 'react-hot-toast'
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
|
||||
export default function useUserVideos() {
|
||||
const { data: user } = useUser()
|
||||
const uid = user?.account?.id ?? 0
|
||||
const key = [UserApiNames.FetchUserVideos, uid]
|
||||
|
||||
return useQuery(
|
||||
key,
|
||||
() => {
|
||||
// const existsQueryData = reactQueryClient.getQueryData(key)
|
||||
// if (!existsQueryData) {
|
||||
// window.ipcRenderer
|
||||
// ?.invoke(IpcChannels.GetApiCache, {
|
||||
// api: APIs.Likelist,
|
||||
// query: {
|
||||
// uid,
|
||||
// },
|
||||
// })
|
||||
// .then(cache => {
|
||||
// if (cache) reactQueryClient.setQueryData(key, cache)
|
||||
// })
|
||||
// }
|
||||
|
||||
return fetchUserVideos()
|
||||
},
|
||||
{
|
||||
enabled: !!(uid && uid !== 0),
|
||||
refetchOnWindowFocus: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export const useMutationLikeAVideo = () => {
|
||||
const { data: user } = useUser()
|
||||
const { data: userVideos, refetch } = useUserVideos()
|
||||
const uid = user?.account?.id ?? 0
|
||||
const key = [UserApiNames.FetchUserVideos, uid]
|
||||
|
||||
return useMutation(
|
||||
async (videoID: string | number) => {
|
||||
if (!videoID || userVideos?.data === undefined) {
|
||||
throw new Error('playlist id is required or userPlaylists is undefined')
|
||||
}
|
||||
const response = await likeAVideo({
|
||||
id: videoID,
|
||||
t: userVideos.data.find(v => String(v.vid) === String(videoID)) ? 2 : 1,
|
||||
})
|
||||
if (response.code !== 200) throw new Error((response as any).msg)
|
||||
return response
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
refetch()
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue