Improve sidebar playlist resize performance

This commit is contained in:
jeffvli 2023-03-29 14:27:25 -07:00
parent ccfe0bfd9d
commit 4332a9ea3a

View file

@ -1,5 +1,6 @@
import { useCallback, useMemo } from 'react'; import { useCallback, useMemo, useState } from 'react';
import { Flex, Group } from '@mantine/core'; import { Flex, Group } from '@mantine/core';
import { useDebouncedValue } from '@mantine/hooks';
import { RiAddBoxFill, RiAddCircleFill, RiPlayFill } from 'react-icons/ri'; import { RiAddBoxFill, RiAddCircleFill, RiPlayFill } from 'react-icons/ri';
import { generatePath } from 'react-router'; import { generatePath } from 'react-router';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
@ -110,6 +111,13 @@ export const SidebarPlaylistList = ({ data }: SidebarPlaylistListProps) => {
const { isScrollbarHidden, hideScrollbarElementProps } = useHideScrollbar(0); const { isScrollbarHidden, hideScrollbarElementProps } = useHideScrollbar(0);
const handlePlayQueueAdd = usePlayQueueAdd(); const handlePlayQueueAdd = usePlayQueueAdd();
const [rect, setRect] = useState({
height: 0,
width: 0,
});
const [debounced] = useDebouncedValue(rect, 25);
const handlePlayPlaylist = useCallback( const handlePlayPlaylist = useCallback(
(id: string, play: Play) => { (id: string, play: Play) => {
handlePlayQueueAdd?.({ handlePlayQueueAdd?.({
@ -135,16 +143,16 @@ export const SidebarPlaylistList = ({ data }: SidebarPlaylistListProps) => {
h="100%" h="100%"
{...hideScrollbarElementProps} {...hideScrollbarElementProps}
> >
<AutoSizer> <AutoSizer onResize={(e) => setRect(e)}>
{({ height, width }) => ( {() => (
<FixedSizeList <FixedSizeList
className={isScrollbarHidden ? 'hide-scrollbar overlay-scrollbar' : 'overlay-scrollbar'} className={isScrollbarHidden ? 'hide-scrollbar overlay-scrollbar' : 'overlay-scrollbar'}
height={height} height={debounced.height}
itemCount={data?.items?.length || 0} itemCount={data?.items?.length || 0}
itemData={memoizedItemData} itemData={memoizedItemData}
itemSize={25} itemSize={25}
overscanCount={20} overscanCount={20}
width={width} width={debounced.width}
> >
{PlaylistRow} {PlaylistRow}
</FixedSizeList> </FixedSizeList>