-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Add Cards Gallery button add block and then try to load images #404
- Loading branch information
Showing
3 changed files
with
36 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 16 additions & 11 deletions
27
packages/block-editor/src/components/normalize-images/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
import apiFetch from '@wordpress/api-fetch'; | ||
|
||
const normalizeImages = ( images ) => { | ||
const promises = images.map( image => { | ||
return apiFetch( { | ||
path: `/wp/v2/media/${ image.id }`, | ||
} ).then( data => { | ||
return Object.assign( {}, image, { | ||
description: data?.description?.raw | ||
} ); | ||
} ) | ||
} ); | ||
const promises = images.map( normalizeImage ); | ||
|
||
return Promise.all( promises ); | ||
return Promise.all( promises ); | ||
}; | ||
|
||
export default normalizeImages; | ||
const normalizeImage = image => { | ||
return apiFetch( { | ||
path: `/wp/v2/media/${ image.id }`, | ||
} ).then( data => { | ||
return Object.assign( {}, image, { | ||
description: data?.description?.raw | ||
} ); | ||
} ) | ||
} | ||
|
||
export { | ||
normalizeImage, | ||
normalizeImages, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters