mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
Fix scroll to top behaviour (#5228)
This commit is contained in:
parent
ca970b9706
commit
0a98296642
2 changed files with 15 additions and 5 deletions
|
|
@ -92,6 +92,9 @@ export const ItemList = <T extends QueryResult, E extends IHasID>(
|
|||
onSelectNone,
|
||||
} = useListContext<E>();
|
||||
|
||||
// scroll to the top of the page when the page changes
|
||||
useScrollToTopOnPageChange(filter.currentPage, result.loading);
|
||||
|
||||
const { modal, showModal, closeModal } = useModal();
|
||||
|
||||
const metadataByline = useMemo(() => {
|
||||
|
|
@ -320,9 +323,6 @@ export const ItemListContext = <T extends QueryResult, E extends IHasID>(
|
|||
view
|
||||
);
|
||||
|
||||
// scroll to the top of the page when the page changes
|
||||
useScrollToTopOnPageChange(filter.currentPage);
|
||||
|
||||
if (defaultFilterLoading) return null;
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -338,9 +338,19 @@ export function useCachedQueryResult<T extends QueryResult>(
|
|||
return cachedResult;
|
||||
}
|
||||
|
||||
export function useScrollToTopOnPageChange(currentPage: number) {
|
||||
export function useScrollToTopOnPageChange(
|
||||
currentPage: number,
|
||||
loading: boolean
|
||||
) {
|
||||
const prevPage = usePrevious(currentPage);
|
||||
|
||||
// scroll to the top of the page when the page changes
|
||||
// only scroll to top if the page has changed and is not loading
|
||||
useEffect(() => {
|
||||
if (loading || currentPage === prevPage || prevPage === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if the current page has a detail-header, then
|
||||
// scroll up relative to that rather than 0, 0
|
||||
const detailHeader = document.querySelector(".detail-header");
|
||||
|
|
@ -349,7 +359,7 @@ export function useScrollToTopOnPageChange(currentPage: number) {
|
|||
} else {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}, [currentPage]);
|
||||
}, [prevPage, currentPage, loading]);
|
||||
}
|
||||
|
||||
// handle case where page is more than there are pages
|
||||
|
|
|
|||
Loading…
Reference in a new issue