Merge branch 'fix-loading-state' into 'develop'

Fix loading animation for Carousel

See merge request soapbox-pub/soapbox!2383
develop^2
Chewbacca 2023-03-28 15:52:56 +00:00
commit 966fcc617a
4 zmienionych plików z 11 dodań i 6 usunięć

Wyświetl plik

@ -13,16 +13,19 @@ interface ICarousel {
itemCount: number itemCount: number
/** The minimum width per item */ /** The minimum width per item */
itemWidth: number itemWidth: number
/** Should the controls be disabled? */
isDisabled?: boolean
} }
/** /**
* Carousel * Carousel
*/ */
const Carousel: React.FC<ICarousel> = (props): JSX.Element => { const Carousel: React.FC<ICarousel> = (props): JSX.Element => {
const { children, controlsHeight, itemCount, itemWidth } = props; const { children, controlsHeight, isDisabled, itemCount, itemWidth } = props;
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_ref, setContainerRef, { width: containerWidth }] = useDimensions(); const [ref, setContainerRef, { width: finalContainerWidth }] = useDimensions();
const containerWidth = finalContainerWidth || ref?.clientWidth;
const [pageSize, setPageSize] = useState<number>(0); const [pageSize, setPageSize] = useState<number>(0);
const [currentPage, setCurrentPage] = useState<number>(1); const [currentPage, setCurrentPage] = useState<number>(1);
@ -62,7 +65,7 @@ const Carousel: React.FC<ICarousel> = (props): JSX.Element => {
data-testid='prev-page' data-testid='prev-page'
onClick={handlePrevPage} onClick={handlePrevPage}
className='flex h-full w-7 items-center justify-center transition-opacity duration-500 disabled:opacity-25' className='flex h-full w-7 items-center justify-center transition-opacity duration-500 disabled:opacity-25'
disabled={!hasPrevPage} disabled={!hasPrevPage || isDisabled}
> >
<Icon <Icon
src={require('@tabler/icons/chevron-left.svg')} src={require('@tabler/icons/chevron-left.svg')}
@ -94,7 +97,7 @@ const Carousel: React.FC<ICarousel> = (props): JSX.Element => {
data-testid='next-page' data-testid='next-page'
onClick={handleNextPage} onClick={handleNextPage}
className='flex h-full w-7 items-center justify-center transition-opacity duration-500 disabled:opacity-25' className='flex h-full w-7 items-center justify-center transition-opacity duration-500 disabled:opacity-25'
disabled={!hasNextPage} disabled={!hasNextPage || isDisabled}
> >
<Icon <Icon
src={require('@tabler/icons/chevron-right.svg')} src={require('@tabler/icons/chevron-right.svg')}

Wyświetl plik

@ -46,11 +46,12 @@ const PopularGroups = () => {
itemWidth={250} itemWidth={250}
itemCount={groups.length} itemCount={groups.length}
controlsHeight={groupCover?.clientHeight} controlsHeight={groupCover?.clientHeight}
isDisabled={isFetching}
> >
{({ width }: { width: number }) => ( {({ width }: { width: number }) => (
<> <>
{isFetching ? ( {isFetching ? (
new Array(20).fill(0).map((_, idx) => ( new Array(4).fill(0).map((_, idx) => (
<div <div
className='relative flex shrink-0 flex-col space-y-2 px-0.5' className='relative flex shrink-0 flex-col space-y-2 px-0.5'
style={{ width: width || 'auto' }} style={{ width: width || 'auto' }}

Wyświetl plik

@ -46,6 +46,7 @@ const SuggestedGroups = () => {
itemWidth={250} itemWidth={250}
itemCount={groups.length} itemCount={groups.length}
controlsHeight={groupCover?.clientHeight} controlsHeight={groupCover?.clientHeight}
isDisabled={isFetching}
> >
{({ width }: { width: number }) => ( {({ width }: { width: number }) => (
<> <>

Wyświetl plik

@ -23,7 +23,7 @@ const useDimensions = (): UseDimensionsResult => {
[], [],
); );
useEffect((): any => { useEffect(() => {
if (!element) return; if (!element) return;
observer.observe(element); observer.observe(element);