mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 13:48:02 +00:00
feat: updates
This commit is contained in:
parent
9a52681687
commit
840a5b8e9b
104 changed files with 1645 additions and 13494 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import useBreakpoint from './useBreakpoint'
|
||||
|
||||
const useIsMobile = () => {
|
||||
const breakpoint = useBreakpoint()
|
||||
return ['sm', 'md'].includes(breakpoint)
|
||||
// const breakpoint = useBreakpoint()
|
||||
// return ['sm', 'md'].includes(breakpoint)
|
||||
return false
|
||||
}
|
||||
|
||||
export default useIsMobile
|
||||
|
|
|
|||
9
packages/web/hooks/useSettings.ts
Normal file
9
packages/web/hooks/useSettings.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { useSnapshot } from 'valtio'
|
||||
import settings from '../states/settings'
|
||||
|
||||
function useSettings() {
|
||||
const settingsState = useSnapshot(settings)
|
||||
return settingsState
|
||||
}
|
||||
|
||||
export default useSettings
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import axios from 'axios'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { appName } from '../utils/const'
|
||||
import useSettings from './useSettings'
|
||||
|
||||
export default function useVideoCover(props: {
|
||||
id?: number
|
||||
|
|
@ -8,24 +9,22 @@ export default function useVideoCover(props: {
|
|||
artist?: string
|
||||
enabled?: boolean
|
||||
}) {
|
||||
const { playAnimatedArtworkFromApple } = useSettings()
|
||||
const { id, name, artist, enabled = true } = props
|
||||
return useQuery(
|
||||
['useVideoCover', props],
|
||||
async () => {
|
||||
if (!id || !name || !artist) return
|
||||
|
||||
const fromRemote = await axios.get(
|
||||
`/${appName.toLowerCase()}/video-cover`,
|
||||
{
|
||||
params: props,
|
||||
}
|
||||
)
|
||||
const fromRemote = await axios.get(`/${appName.toLowerCase()}/video-cover`, {
|
||||
params: props,
|
||||
})
|
||||
if (fromRemote?.data?.url) {
|
||||
return fromRemote.data.url
|
||||
}
|
||||
},
|
||||
{
|
||||
enabled: !!id && !!name && !!artist && enabled,
|
||||
enabled: !!id && !!name && !!artist && enabled && !!playAnimatedArtworkFromApple,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchInterval: false,
|
||||
}
|
||||
|
|
|
|||
26
packages/web/hooks/useWindowFocus.ts
Normal file
26
packages/web/hooks/useWindowFocus.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { useState, useEffect } from 'react'
|
||||
|
||||
const hasFocus = () => typeof document !== 'undefined' && document.hasFocus()
|
||||
|
||||
const useWindowFocus = () => {
|
||||
const [focused, setFocused] = useState(hasFocus)
|
||||
|
||||
useEffect(() => {
|
||||
setFocused(hasFocus())
|
||||
|
||||
const onFocus = () => setFocused(true)
|
||||
const onBlur = () => setFocused(false)
|
||||
|
||||
window.addEventListener('focus', onFocus)
|
||||
window.addEventListener('blur', onBlur)
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('focus', onFocus)
|
||||
window.removeEventListener('blur', onBlur)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return focused
|
||||
}
|
||||
|
||||
export default useWindowFocus
|
||||
Loading…
Add table
Add a link
Reference in a new issue