fix: style tweaks to card view

This commit is contained in:
Daniel Lautzenheiser
2023-05-12 11:47:44 -04:00
parent 8ba2ff15fc
commit 9d3b9f50f3
5 changed files with 53 additions and 9 deletions

View File

@ -9,14 +9,14 @@ import type { ChangeEvent, FocusEvent, KeyboardEvent, MouseEvent } from 'react';
interface CollectionSearchProps { interface CollectionSearchProps {
collections: Collections; collections: Collections;
collection?: Collection; collection?: Collection;
searchTerm: string; searchTerm: string | undefined;
onSubmit: (query: string, collection?: string) => void; onSubmit: (query: string, collection?: string) => void;
} }
const CollectionSearch = ({ const CollectionSearch = ({
collections: collectionsMap, collections: collectionsMap,
collection, collection,
searchTerm, searchTerm = '',
onSubmit, onSubmit,
t, t,
}: TranslatedProps<CollectionSearchProps>) => { }: TranslatedProps<CollectionSearchProps>) => {

View File

@ -14,6 +14,7 @@ export interface BaseEntriesProps {
isFetching: boolean; isFetching: boolean;
viewStyle: ViewStyle; viewStyle: ViewStyle;
cursor: Cursor; cursor: Cursor;
filterTerm: string;
handleCursorActions?: (action: string) => void; handleCursorActions?: (action: string) => void;
} }
@ -32,6 +33,7 @@ const Entries = ({
isFetching, isFetching,
viewStyle, viewStyle,
cursor, cursor,
filterTerm,
handleCursorActions, handleCursorActions,
t, t,
page, page,
@ -62,6 +64,7 @@ const Entries = ({
handleCursorActions={handleCursorActions} handleCursorActions={handleCursorActions}
page={page} page={page}
isLoadingEntries={isFetching && page !== undefined && entries.length > 0} isLoadingEntries={isFetching && page !== undefined && entries.length > 0}
filterTerm={filterTerm}
/> />
) : ( ) : (
<EntryListing <EntryListing
@ -73,6 +76,7 @@ const Entries = ({
handleCursorActions={handleCursorActions} handleCursorActions={handleCursorActions}
page={page} page={page}
isLoadingEntries={isFetching && page !== undefined && entries.length > 0} isLoadingEntries={isFetching && page !== undefined && entries.length > 0}
filterTerm={filterTerm}
/> />
); );
} }

View File

@ -132,6 +132,7 @@ const EntriesCollection = ({
cursor={cursor} cursor={cursor}
handleCursorActions={handleCursorActions} handleCursorActions={handleCursorActions}
page={page} page={page}
filterTerm={filterTerm}
/> />
</div> </div>
); );
@ -151,6 +152,7 @@ const EntriesCollection = ({
cursor={cursor} cursor={cursor}
handleCursorActions={handleCursorActions} handleCursorActions={handleCursorActions}
page={page} page={page}
filterTerm={filterTerm}
/> />
); );
}; };

View File

@ -24,6 +24,7 @@ export interface BaseEntryListingProps {
viewStyle: ViewStyle; viewStyle: ViewStyle;
cursor?: Cursor; cursor?: Cursor;
isLoadingEntries: boolean; isLoadingEntries: boolean;
filterTerm: string;
handleCursorActions?: (action: string) => void; handleCursorActions?: (action: string) => void;
page?: number; page?: number;
} }
@ -45,6 +46,7 @@ const EntryListing: FC<TranslatedProps<EntryListingProps>> = ({
cursor, cursor,
viewStyle, viewStyle,
isLoadingEntries, isLoadingEntries,
filterTerm,
handleCursorActions, handleCursorActions,
t, t,
...otherProps ...otherProps
@ -169,7 +171,7 @@ const EntryListing: FC<TranslatedProps<EntryListingProps>> = ({
return ( return (
<EntryListingGrid <EntryListingGrid
key="grid" key={'collection' in otherProps ? otherProps.collection.name : `search-grid-${filterTerm}`}
entryData={entryData} entryData={entryData}
onLoadMore={handleLoadMore} onLoadMore={handleLoadMore}
canLoadMore={Boolean(hasMore && handleLoadMore)} canLoadMore={Boolean(hasMore && handleLoadMore)}

View File

@ -28,6 +28,7 @@ export interface EntryListingCardGridProps {
export interface CardGridItemData { export interface CardGridItemData {
columnCount: number; columnCount: number;
cardHeights: number[];
entryData: CollectionEntryData[]; entryData: CollectionEntryData[];
t: t; t: t;
} }
@ -36,7 +37,7 @@ const CardWrapper = ({
rowIndex, rowIndex,
columnIndex, columnIndex,
style, style,
data: { columnCount, entryData, t }, data: { columnCount, cardHeights, entryData, t },
}: GridChildComponentProps<CardGridItemData>) => { }: GridChildComponentProps<CardGridItemData>) => {
const left = useMemo( const left = useMemo(
() => () =>
@ -60,6 +61,8 @@ const CardWrapper = ({
return null; return null;
} }
const data = entryData[index]; const data = entryData[index];
const cardHeight =
index < cardHeights.length ? cardHeights[index] + COLLECTION_CARD_MARGIN : style.height;
return ( return (
<div <div
@ -68,7 +71,7 @@ const CardWrapper = ({
left, left,
top, top,
width: style.width, width: style.width,
height: style.height, height: cardHeight,
paddingRight: `${columnIndex + 1 === columnCount ? 0 : COLLECTION_CARD_MARGIN}px`, paddingRight: `${columnIndex + 1 === columnCount ? 0 : COLLECTION_CARD_MARGIN}px`,
paddingBottom: `${COLLECTION_CARD_MARGIN}px`, paddingBottom: `${COLLECTION_CARD_MARGIN}px`,
}} }}
@ -103,6 +106,13 @@ const EntryListingCardGrid: FC<EntryListingCardGridProps> = ({
}, []); }, []);
const getDefaultHeight = useCallback((data?: CollectionEntryData) => { 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) return isNotNullish(data?.imageFieldName)
? COLLECTION_CARD_HEIGHT ? COLLECTION_CARD_HEIGHT
: COLLECTION_CARD_HEIGHT_WITHOUT_IMAGE; : COLLECTION_CARD_HEIGHT_WITHOUT_IMAGE;
@ -166,15 +176,41 @@ const EntryListingCardGrid: FC<EntryListingCardGridProps> = ({
: width * columnWidth + COLLECTION_CARD_MARGIN : width * columnWidth + COLLECTION_CARD_MARGIN
} }
rowCount={rowCount} rowCount={rowCount}
rowHeight={index => rowHeight={index => {
(cardHeights.length > index ? cardHeights[index] : getDefaultHeight()) + const rowStart = index * columnCount;
COLLECTION_CARD_MARGIN 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} width={width}
height={height} height={height}
itemData={ itemData={
{ {
entryData, entryData,
cardHeights,
columnCount, columnCount,
t, t,
} as CardGridItemData } as CardGridItemData