fix: media not displaying with local backend (#324)
This commit is contained in:
committed by
GitHub
parent
a9e0770fd0
commit
9dba066ca4
@ -127,7 +127,7 @@ export function summaryFormatter(summaryTemplate: string, entry: Entry, collecti
|
||||
|
||||
export function folderFormatter(
|
||||
folderTemplate: string,
|
||||
entry: Entry | undefined,
|
||||
entry: Entry | null | undefined,
|
||||
collection: Collection,
|
||||
defaultFolder: string,
|
||||
folderKey: string,
|
||||
|
@ -4,18 +4,22 @@ import { getAsset } from '@staticcms/core/actions/media';
|
||||
import { useAppDispatch } from '@staticcms/core/store/hooks';
|
||||
import { isNotEmpty } from '../util/string.util';
|
||||
|
||||
import type { Collection, Entry, FileOrImageField, MarkdownField } from '@staticcms/core/interface';
|
||||
import type { Field, Collection, Entry } from '@staticcms/core/interface';
|
||||
|
||||
export default function useMediaAsset<T extends FileOrImageField | MarkdownField>(
|
||||
url: string,
|
||||
collection: Collection<T>,
|
||||
field: T,
|
||||
entry: Entry,
|
||||
export default function useMediaAsset<T extends Field>(
|
||||
url: string | undefined,
|
||||
collection?: Collection<T>,
|
||||
field?: T,
|
||||
entry?: Entry,
|
||||
): string {
|
||||
const dispatch = useAppDispatch();
|
||||
const [assetSource, setAssetSource] = useState(url);
|
||||
|
||||
useEffect(() => {
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fetchMedia = async () => {
|
||||
const asset = (await dispatch(getAsset<T>(collection, entry, url, field)))?.toString() ?? '';
|
||||
setAssetSource(asset);
|
||||
@ -24,5 +28,5 @@ export default function useMediaAsset<T extends FileOrImageField | MarkdownField
|
||||
fetchMedia();
|
||||
}, [collection, dispatch, entry, field, url]);
|
||||
|
||||
return isNotEmpty(assetSource) ? assetSource : url;
|
||||
return isNotEmpty(assetSource) ? assetSource : url ?? '';
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ function evaluateFolder(
|
||||
folderKey: 'media_folder' | 'public_folder',
|
||||
config: Config,
|
||||
c: Collection,
|
||||
entryMap: Entry | undefined,
|
||||
entryMap: Entry | null | undefined,
|
||||
field: FileOrImageField | MarkdownField,
|
||||
) {
|
||||
let currentFolder = config[folderKey]!;
|
||||
@ -158,7 +158,7 @@ function traverseFields(
|
||||
folderKey: 'media_folder' | 'public_folder',
|
||||
config: Config,
|
||||
collection: Collection,
|
||||
entryMap: Entry | undefined,
|
||||
entryMap: Entry | null | undefined,
|
||||
field: FileOrImageField | MarkdownField | ListField | ObjectField,
|
||||
fields: Field[],
|
||||
currentFolder: string,
|
||||
@ -227,7 +227,7 @@ function traverseFields(
|
||||
export function selectMediaFolder(
|
||||
config: Config,
|
||||
collection: Collection | undefined | null,
|
||||
entryMap: Entry | undefined,
|
||||
entryMap: Entry | null | undefined,
|
||||
field: Field | undefined,
|
||||
) {
|
||||
const name = 'media_folder';
|
||||
@ -279,7 +279,7 @@ export function selectMediaFilePublicPath(
|
||||
export function selectMediaFilePath(
|
||||
config: Config,
|
||||
collection: Collection | null,
|
||||
entryMap: Entry | undefined,
|
||||
entryMap: Entry | null | undefined,
|
||||
mediaPath: string,
|
||||
field: Field | undefined,
|
||||
) {
|
||||
|
Reference in New Issue
Block a user