Skip to content

Commit

Permalink
fix: ensure that no empty virtuoso views are rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
robinpyon committed Sep 21, 2021
1 parent 94465a5 commit 04904e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/components/AssetGridVirtualized/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const AssetGridVirtualized = (props: Props) => {
const selectedIds = (selectedAssets && selectedAssets.map(asset => asset._id)) || []
const totalCount = items?.length

if (totalCount === 0) {
return null
}

return (
<VirtuosoGrid
className="media__custom-scrollbar"
Expand Down
7 changes: 6 additions & 1 deletion src/components/AssetTableVirtualized/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const AssetTableVirtualized = (props: Props) => {
const selectedAssets = useTypedSelector(state => state.selected.assets)

const selectedIds = (selectedAssets && selectedAssets.map(asset => asset._id)) || []
const totalCount = items?.length

if (totalCount === 0) {
return null
}

return (
<GroupedVirtuoso
Expand All @@ -50,7 +55,7 @@ const AssetTableVirtualized = (props: Props) => {
return item?.id || index
}}
endReached={onLoadMore}
groupCounts={Array(1).fill(items.length)}
groupCounts={Array(1).fill(totalCount)}
groupContent={() => {
return <TableHeader />
}}
Expand Down
18 changes: 10 additions & 8 deletions src/components/Items/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,22 @@ const Items: FC = () => {

return (
<Box flex={1} style={{width: '100%'}}>
{isEmpty && (
{isEmpty ? (
<Box padding={4}>
<Text size={1} weight="semibold">
No results for the current query
</Text>
</Box>
)}

{!isEmpty && view === 'grid' && (
<AssetGridVirtualized items={combinedItems} onLoadMore={handleLoadMoreItems} />
)}
) : (
<>
{view === 'grid' && (
<AssetGridVirtualized items={combinedItems} onLoadMore={handleLoadMoreItems} />
)}

{!isEmpty && view === 'table' && (
<AssetTableVirtualized items={combinedItems} onLoadMore={handleLoadMoreItems} />
{view === 'table' && (
<AssetTableVirtualized items={combinedItems} onLoadMore={handleLoadMoreItems} />
)}
</>
)}
</Box>
)
Expand Down

0 comments on commit 04904e5

Please sign in to comment.