Skip to content

Commit

Permalink
fix VList
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Apr 8, 2024
1 parent 12446b7 commit 16a26b0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {usePreview} from '../../usePreview';
import {tagListSx} from '../../../Media/Asset/Widgets/AssetTagList';
import {collectionListSx} from '../../../Media/Asset/Widgets/AssetCollectionList';
import LoadMoreButton from "../../LoadMoreButton.tsx";
import {useScrollTopPages} from "../../useScrollTopPages.ts";

export default function GridLayout<Item extends AssetOrAssetContainer>({
toolbarHeight,
Expand All @@ -29,6 +30,9 @@ export default function GridLayout<Item extends AssetOrAssetContainer>({
const collLineHeight = 32;
const tagLineHeight = 32;
const d = useContext(DisplayContext)!;
const listRef = React.useRef<HTMLDivElement | null>(null);

useScrollTopPages(listRef.current?.closest(`.${assetClasses.scrollable}`), pages);

const gridSx = React.useCallback(
(theme: Theme) => {
Expand Down Expand Up @@ -145,7 +149,12 @@ export default function GridLayout<Item extends AssetOrAssetContainer>({

return (
<>
<Grid container spacing={1} sx={gridSx}>
<Grid
container
spacing={1}
sx={gridSx}
ref={listRef}
>
{pages.map((page, i) => (
<GridPage
key={i}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {menuHeight} from "../../../Layout/MainAppBar.tsx";
import {useWindowSize} from '@alchemy/react-hooks/src/useWindowSize.ts'
import {CellMeasurerCache} from "react-virtualized/dist/es/CellMeasurer";
import LoadMoreButton from "../../LoadMoreButton.tsx";
import {useScrollTopPages} from "../../useScrollTopPages.ts";
import SectionDivider from "../../SectionDivider.tsx";

export default function ListLayout<Item extends AssetOrAssetContainer>({
Expand All @@ -34,18 +33,20 @@ export default function ListLayout<Item extends AssetOrAssetContainer>({
itemToAsset,
}: LayoutProps<Item>) {
const {previewAnchorEl, onPreviewToggle} = usePreview([pages]);
const listRef = React.useRef<HTMLDivElement>();
const listRef = React.useRef<List | null>(null);
const d = React.useContext(DisplayContext)!;
const {innerHeight} = useWindowSize();
const height = innerHeight - toolbarHeight - menuHeight;

useScrollTopPages(listRef.current?.querySelector(`.${assetClasses.scrollable}`), pages);
React.useLayoutEffect(() => {
listRef.current?.scrollToRow(0);
}, [pages[0], listRef]);

const cellMeasurer = React.useMemo(() => {
return new CellMeasurerCache({
fixedWidth: true,
minHeight: d.thumbSize + 20,
defaultHeight: 500
defaultHeight: 400
})
}, [pages[0], d.thumbSize]);

Expand Down Expand Up @@ -165,7 +166,16 @@ export default function ListLayout<Item extends AssetOrAssetContainer>({
onPreviewToggle={onPreviewToggle}
/>
{loadMore && index === rowCount - 1 ? <LoadMoreButton
onClick={loadMore}
onClick={() => {
loadMore!().then(() => {
cellMeasurer.clear(index, 0);
parent.recomputeGridSize!({
rowIndex: index,
columnIndex: 0,
});
parent.forceUpdate();
});
}}
pages={pages}
/> : ''}
</div>
Expand All @@ -176,11 +186,11 @@ export default function ListLayout<Item extends AssetOrAssetContainer>({
return (
<Box
sx={layoutSx}
ref={listRef}
>
<AutoSizer disableHeight>
{({width}) => (
<List
ref={listRef}
className={assetClasses.scrollable}
deferredMeasurementCache={cellMeasurer}
height={height}
Expand Down

0 comments on commit 16a26b0

Please sign in to comment.