mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 04:27:37 +03:00
* feat: create vite project * feat: it's alive! * feat: `make dev` working! * feat: replace custom serviceWorker with vite plugin * test: replace Jest with Vitest * fix: run prettier * fix: skip eslint for now. * chore: remove ui.old folder * refactor: replace lodash.pick with simple destructuring * fix: eslint errors (wip) * fix: eslint errors (wip) * fix: display-name eslint errors (wip) * fix: no-console eslint errors (wip) * fix: react-refresh/only-export-components eslint errors (wip) * fix: react-refresh/only-export-components eslint errors (wip) * fix: react-refresh/only-export-components eslint errors (wip) * fix: react-refresh/only-export-components eslint errors (wip) * fix: build * fix: pwa manifest * refactor: pwa manifest * refactor: simplify PORT configuration * refactor: rename simple JS files * test: cover playlistUtils * fix: react-image-lightbox * feat(ui): add sourcemaps to help debug issues
36 lines
989 B
JavaScript
36 lines
989 B
JavaScript
import { useSelector } from 'react-redux'
|
|
import { useState } from 'react'
|
|
import { useRefresh, useDataProvider } from 'react-admin'
|
|
|
|
export const useResourceRefresh = (...visibleResources) => {
|
|
const [lastTime, setLastTime] = useState(Date.now())
|
|
const refresh = useRefresh()
|
|
const dataProvider = useDataProvider()
|
|
const refreshData = useSelector(
|
|
(state) => state.activity?.refresh || { lastReceived: lastTime },
|
|
)
|
|
const { resources, lastReceived } = refreshData
|
|
|
|
if (lastReceived <= lastTime) {
|
|
return
|
|
}
|
|
setLastTime(lastReceived)
|
|
|
|
if (
|
|
resources &&
|
|
(resources['*'] === '*' ||
|
|
Object.values(resources).find((v) => v.find((v2) => v2 === '*')))
|
|
) {
|
|
refresh()
|
|
return
|
|
}
|
|
if (resources) {
|
|
Object.keys(resources).forEach((r) => {
|
|
if (visibleResources.length === 0 || visibleResources?.includes(r)) {
|
|
if (resources[r]?.length > 0) {
|
|
dataProvider.getMany(r, { ids: resources[r] })
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|