import React, { ReactElement, useEffect, useLayoutEffect } from 'react'; import { observer } from 'mobx-react-lite'; import { FiltersMap } from '@wix/bex-core'; import { GridBaseState, LayoutType } from '../../state'; import { InitialSkeletonLoader } from '../InitialLoader/InitialSkeletonLoader'; import { PageGridInfiniteScrollLoader } from '../PageGridInfiniteScrollLoader'; import { AddItemProps, Box } from '@wix/design-system'; import { useGridBaseSyncProps } from './useGridBaseSyncProps'; import { useRenderItem } from './useRenderItem'; import { VirtualGridRepeater } from '../VirtualGridRepeater/VirtualGridRepeater'; import { SupportedCardGalleryItemProps } from './SupportedCardGalleryItemProps'; import { DragAndDropCancel, DragAndDropSubmit } from '../DragAndDrop'; import { ActionCell } from '../ActionCell'; import { GridDragAndDrop } from '../GridDragAndDropDndKit/GridDragAndDrop'; import type { Preset } from './Grid.types'; export interface GridContentBaseProps { preset?: Preset; imagePlacement?: 'side' | 'top'; renderItem?: ( item: T, index: number, ) => Partial; actionCell?: ActionCell; renderAddItem?: () => ReactElement; dragAndDrop?: typeof GridDragAndDrop; dragAndDropSubmit?: DragAndDropSubmit; dragAndDropCancel?: DragAndDropCancel; layoutType?: LayoutType; } export interface GridContentProps extends GridContentBaseProps { state: GridBaseState; range?: { start: number; length: number }; withInfiniteScrollLoader?: boolean; paddingTop?: string; paddingBottom?: string; } function _GridContent( props: GridContentProps, ) { const { state, withInfiniteScrollLoader, dragAndDrop, dragAndDropSubmit, paddingTop, paddingBottom, } = props; const { toolbar: { contentPaddingPx, showInitialLoader, multi: { showRefreshLoader }, }, } = state; useGridBaseSyncProps(props); useEffect(() => state.init(), []); const renderItem = useRenderItem(props); let child = ; if (dragAndDrop) { const { DraggableCardOverlay, SortableContext } = dragAndDrop; child = ( {child} ); } if (showRefreshLoader || showInitialLoader) { child = ( ); } else { child = ( <> {child} {withInfiniteScrollLoader && ( )} ); } useLayoutEffect(() => { state._containerRectState._syncThrottled(); }, []); useEffect(() => state._containerRectState.init(), []); return (
{ state._containerRectState.element = el; }} > {child}
); } export const GridContent = observer(_GridContent);