Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
fix: card height with date field
Browse files Browse the repository at this point in the history
  • Loading branch information
KaneFreeman committed Apr 26, 2024
1 parent e655745 commit be142f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AutoSizer from 'react-virtualized-auto-sizer';
import { VariableSizeGrid as Grid } from 'react-window';

import {
COLLECTION_CARD_DATE_HEIGHT,
COLLECTION_CARD_HEIGHT,
COLLECTION_CARD_HEIGHT_WITHOUT_IMAGE,
COLLECTION_CARD_MARGIN,
Expand Down Expand Up @@ -64,7 +65,7 @@ const CardWrapper: FC<GridChildComponentProps<CardGridItemData>> = ({
}
const data = entryData[index];
const cardHeight =
index < cardHeights.length ? cardHeights[index] + COLLECTION_CARD_MARGIN : style.height;
index < cardHeights.length ? cardHeights[index] + COLLECTION_CARD_MARGIN * 2 : style.height;

return (
<div
Expand Down Expand Up @@ -114,9 +115,15 @@ const EntryListingCardGrid: FC<EntryListingCardGridProps> = ({
}, []);

const getDefaultHeight = useCallback((data?: CollectionEntryData) => {
return isNotNullish(data?.imageFieldName)
const base = isNotNullish(data?.imageFieldName)
? COLLECTION_CARD_HEIGHT
: COLLECTION_CARD_HEIGHT_WITHOUT_IMAGE;

if (isNotNullish(data?.dateFieldName)) {
return base + COLLECTION_CARD_DATE_HEIGHT;
}

return base;
}, []);

const [prevCardHeights, setPrevCardHeight] = useState<number[]>([]);
Expand Down Expand Up @@ -185,12 +192,12 @@ const EntryListingCardGrid: FC<EntryListingCardGridProps> = ({
}

if (cardHeights[i] > rowHeight && cardHeights[i]) {
rowHeight = cardHeights[i] + COLLECTION_CARD_MARGIN;
rowHeight = cardHeights[i] + COLLECTION_CARD_MARGIN * 2;
}
}

if (rowHeight === 0) {
rowHeight = getDefaultHeight() + COLLECTION_CARD_MARGIN;
rowHeight = getDefaultHeight() + COLLECTION_CARD_MARGIN * 2;
}

return rowHeight;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/constants/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const COLLECTION_CARD_WIDTH = 240;
export const COLLECTION_CARD_HEIGHT = 204;
export const COLLECTION_CARD_IMAGE_HEIGHT = 140;
export const COLLECTION_CARD_HEIGHT_WITHOUT_IMAGE = 56;
export const COLLECTION_CARD_DATE_HEIGHT = 24;
export const COLLECTION_CARD_MARGIN = 10;

export const EDITOR_SIZE_COMPACT = 'compact';
Expand Down

0 comments on commit be142f8

Please sign in to comment.