diff --git a/packages/core/dev-test/index.js b/packages/core/dev-test/index.js index 791dd74f..fa798116 100644 --- a/packages/core/dev-test/index.js +++ b/packages/core/dev-test/index.js @@ -11,13 +11,14 @@ const PostPreview = ({ entry, widgetFor }) => { ); }; -const PostPreviewCard = ({ entry, theme, hasLocalBackup, widgetFor }) => { +const PostPreviewCard = ({ entry, theme, hasLocalBackup, collection }) => { const date = new Date(entry.data.date); const month = date.getMonth() + 1; const day = date.getDate(); - const image = entry.data.image; + const imageField = useMemo(() => collection.fields.find((f) => f.name === 'image'), []); + const image = useMediaAsset(entry.data.image, collection, imageField, entry); return h( 'div', diff --git a/packages/core/src/components/collections/entries/EntryCard.tsx b/packages/core/src/components/collections/entries/EntryCard.tsx index 1b8be2fb..c69f589d 100644 --- a/packages/core/src/components/collections/entries/EntryCard.tsx +++ b/packages/core/src/components/collections/entries/EntryCard.tsx @@ -130,12 +130,20 @@ const EntryCard: FC> = ({ } return ( - + - {image && imageField ? : null} + {image && imageField ? ( + + ) : null}
-
{summary}
+
{summary}
{hasLocalBackup ? ( { }} src={image} alt={alt} + collection={collection} + field={field} + entry={entry} /> ); }; diff --git a/packages/core/src/components/common/image/Image.tsx b/packages/core/src/components/common/image/Image.tsx index 33b5366c..315d5698 100644 --- a/packages/core/src/components/common/image/Image.tsx +++ b/packages/core/src/components/common/image/Image.tsx @@ -7,7 +7,13 @@ import { selectEditingDraft } from '@staticcms/core/reducers/selectors/entryDraf import { useAppSelector } from '@staticcms/core/store/hooks'; import { isEmpty } from '@staticcms/core/lib/util/string.util'; -import type { BaseField, Collection, MediaField, UnknownField } from '@staticcms/core/interface'; +import type { + BaseField, + Collection, + Entry, + MediaField, + UnknownField, +} from '@staticcms/core/interface'; import type { CSSProperties } from 'react'; export interface ImageProps { @@ -17,6 +23,7 @@ export interface ImageProps { style?: CSSProperties; collection?: Collection; field?: MediaField; + entry?: Entry; 'data-testid'?: string; } @@ -27,11 +34,12 @@ const Image = ({ style, collection, field, + entry, 'data-testid': dataTestId, }: ImageProps) => { - const entry = useAppSelector(selectEditingDraft); + const editingDraft = useAppSelector(selectEditingDraft); - const assetSource = useMediaAsset(src, collection, field, entry); + const assetSource = useMediaAsset(src, collection, field, entry ?? editingDraft); if (isEmpty(src)) { return (