mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
simplify persistence of page and scroll
This commit is contained in:
parent
1d4e2821ee
commit
ff26593b17
@ -18,7 +18,6 @@ import {
|
||||
import FavoriteIcon from '@material-ui/icons/Favorite'
|
||||
import { withWidth } from '@material-ui/core'
|
||||
import {
|
||||
InfinitePagination,
|
||||
InfiniteScrollWrapper,
|
||||
List,
|
||||
QuickFilter,
|
||||
@ -241,7 +240,7 @@ const AlbumList = (props) => {
|
||||
perPage={perPage}
|
||||
pagination={
|
||||
infiniteScrollEnabled ? (
|
||||
<InfinitePagination />
|
||||
false
|
||||
) : (
|
||||
<Pagination rowsPerPageOptions={perPageOptions} />
|
||||
)
|
||||
|
||||
@ -1 +0,0 @@
|
||||
export const InfinitePagination = () => null
|
||||
@ -42,5 +42,4 @@ export * from './playlistUtils.js'
|
||||
export * from './PathField.jsx'
|
||||
export * from './ParticipantsInfo'
|
||||
export * from './useInfiniteScroll.jsx'
|
||||
export * from './InfinitePagination'
|
||||
export * from './InfiniteScrollWrapper'
|
||||
|
||||
@ -12,32 +12,26 @@ import { useHistory, useLocation } from 'react-router-dom'
|
||||
|
||||
const InfiniteScrollContext = createContext(null)
|
||||
|
||||
const scrollStateCache = new Map()
|
||||
|
||||
const getStorageKey = (pathname, filterValues) => {
|
||||
const filterKey = JSON.stringify(filterValues || {})
|
||||
return `infiniteScroll:${pathname}:${filterKey}`
|
||||
return `${pathname}:${filterKey}`
|
||||
}
|
||||
|
||||
const saveScrollState = (pathname, filterValues, pagesLoaded, scrollY) => {
|
||||
const key = getStorageKey(pathname, filterValues)
|
||||
sessionStorage.setItem(key, JSON.stringify({ pagesLoaded, scrollY }))
|
||||
scrollStateCache.set(key, { pagesLoaded, scrollY })
|
||||
}
|
||||
|
||||
const getScrollState = (pathname, filterValues) => {
|
||||
const key = getStorageKey(pathname, filterValues)
|
||||
const saved = sessionStorage.getItem(key)
|
||||
if (saved) {
|
||||
try {
|
||||
return JSON.parse(saved)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null
|
||||
return scrollStateCache.get(key) || null
|
||||
}
|
||||
|
||||
const clearScrollState = (pathname, filterValues) => {
|
||||
const key = getStorageKey(pathname, filterValues)
|
||||
sessionStorage.removeItem(key)
|
||||
scrollStateCache.delete(key)
|
||||
}
|
||||
|
||||
export const InfiniteScrollProvider = ({ children }) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user