From 9d3b9f50f375216cb9fb10759d89a3722b7a5734 Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Fri, 12 May 2023 11:47:44 -0400 Subject: [PATCH] fix: style tweaks to card view --- .../collections/CollectionSearch.tsx | 4 +- .../collections/entries/Entries.tsx | 4 ++ .../collections/entries/EntriesCollection.tsx | 2 + .../collections/entries/EntryListing.tsx | 4 +- .../entries/EntryListingCardGrid.tsx | 48 ++++++++++++++++--- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/packages/core/src/components/collections/CollectionSearch.tsx b/packages/core/src/components/collections/CollectionSearch.tsx index da530d61..907c14b8 100644 --- a/packages/core/src/components/collections/CollectionSearch.tsx +++ b/packages/core/src/components/collections/CollectionSearch.tsx @@ -9,14 +9,14 @@ import type { ChangeEvent, FocusEvent, KeyboardEvent, MouseEvent } from 'react'; interface CollectionSearchProps { collections: Collections; collection?: Collection; - searchTerm: string; + searchTerm: string | undefined; onSubmit: (query: string, collection?: string) => void; } const CollectionSearch = ({ collections: collectionsMap, collection, - searchTerm, + searchTerm = '', onSubmit, t, }: TranslatedProps) => { diff --git a/packages/core/src/components/collections/entries/Entries.tsx b/packages/core/src/components/collections/entries/Entries.tsx index 92318cba..c1600b7e 100644 --- a/packages/core/src/components/collections/entries/Entries.tsx +++ b/packages/core/src/components/collections/entries/Entries.tsx @@ -14,6 +14,7 @@ export interface BaseEntriesProps { isFetching: boolean; viewStyle: ViewStyle; cursor: Cursor; + filterTerm: string; handleCursorActions?: (action: string) => void; } @@ -32,6 +33,7 @@ const Entries = ({ isFetching, viewStyle, cursor, + filterTerm, handleCursorActions, t, page, @@ -62,6 +64,7 @@ const Entries = ({ handleCursorActions={handleCursorActions} page={page} isLoadingEntries={isFetching && page !== undefined && entries.length > 0} + filterTerm={filterTerm} /> ) : ( 0} + filterTerm={filterTerm} /> ); } diff --git a/packages/core/src/components/collections/entries/EntriesCollection.tsx b/packages/core/src/components/collections/entries/EntriesCollection.tsx index d20ae325..f5309d36 100644 --- a/packages/core/src/components/collections/entries/EntriesCollection.tsx +++ b/packages/core/src/components/collections/entries/EntriesCollection.tsx @@ -132,6 +132,7 @@ const EntriesCollection = ({ cursor={cursor} handleCursorActions={handleCursorActions} page={page} + filterTerm={filterTerm} /> ); @@ -151,6 +152,7 @@ const EntriesCollection = ({ cursor={cursor} handleCursorActions={handleCursorActions} page={page} + filterTerm={filterTerm} /> ); }; diff --git a/packages/core/src/components/collections/entries/EntryListing.tsx b/packages/core/src/components/collections/entries/EntryListing.tsx index e9da3b8c..692f81bf 100644 --- a/packages/core/src/components/collections/entries/EntryListing.tsx +++ b/packages/core/src/components/collections/entries/EntryListing.tsx @@ -24,6 +24,7 @@ export interface BaseEntryListingProps { viewStyle: ViewStyle; cursor?: Cursor; isLoadingEntries: boolean; + filterTerm: string; handleCursorActions?: (action: string) => void; page?: number; } @@ -45,6 +46,7 @@ const EntryListing: FC> = ({ cursor, viewStyle, isLoadingEntries, + filterTerm, handleCursorActions, t, ...otherProps @@ -169,7 +171,7 @@ const EntryListing: FC> = ({ return ( ) => { const left = useMemo( () => @@ -60,6 +61,8 @@ const CardWrapper = ({ return null; } const data = entryData[index]; + const cardHeight = + index < cardHeights.length ? cardHeights[index] + COLLECTION_CARD_MARGIN : style.height; return (
= ({ }, []); const getDefaultHeight = useCallback((data?: CollectionEntryData) => { + console.log( + 'DEFAULT HEIGHT', + data, + isNotNullish(data?.imageFieldName) + ? COLLECTION_CARD_HEIGHT + : COLLECTION_CARD_HEIGHT_WITHOUT_IMAGE, + ); return isNotNullish(data?.imageFieldName) ? COLLECTION_CARD_HEIGHT : COLLECTION_CARD_HEIGHT_WITHOUT_IMAGE; @@ -166,15 +176,41 @@ const EntryListingCardGrid: FC = ({ : width * columnWidth + COLLECTION_CARD_MARGIN } rowCount={rowCount} - rowHeight={index => - (cardHeights.length > index ? cardHeights[index] : getDefaultHeight()) + - COLLECTION_CARD_MARGIN - } + rowHeight={index => { + const rowStart = index * columnCount; + const rowEnd = (index + 1) * columnCount - 1; + let rowHeight = 0; + for (let i = rowStart; i <= rowEnd; i++) { + if (cardHeights.length <= i) { + break; + } + + if (cardHeights[i] > rowHeight && cardHeights[i]) { + rowHeight = cardHeights[i] + COLLECTION_CARD_MARGIN; + + console.log( + 'HEIGHT @index', + i, + cardHeights[i], + cardHeights[i] + COLLECTION_CARD_MARGIN, + ); + } + } + + if (rowHeight === 0) { + rowHeight = getDefaultHeight() + COLLECTION_CARD_MARGIN; + } + + console.log('HEIGHT', index, rowHeight); + + return rowHeight; + }} width={width} height={height} itemData={ { entryData, + cardHeights, columnCount, t, } as CardGridItemData