Skip to content

Commit

Permalink
Wait until animation ends before activating button
Browse files Browse the repository at this point in the history
  • Loading branch information
sgomes committed Aug 26, 2024
1 parent 117ef31 commit aa2188e
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function Image( block ) {

export default function PostFormatPanel() {
const [ isUploading, setIsUploading ] = useState( false );
const [ isAnimating, setIsAnimating ] = useState( false );
const { editorBlocks, mediaUpload } = useSelect(
( select ) => ( {
editorBlocks: select( blockEditorStore ).getBlocks(),
Expand Down Expand Up @@ -97,27 +98,26 @@ export default function PostFormatPanel() {
: image.attributes.url + '?'
)
.then( ( response ) => response.blob() )
.then(
( blob ) =>
new Promise( ( resolve, reject ) => {
mediaUpload( {
filesList: [ blob ],
onFileChange: ( [ media ] ) => {
if ( isBlobURL( media.url ) ) {
return;
}
.then( ( blob ) =>
new Promise( ( resolve, reject ) => {
mediaUpload( {
filesList: [ blob ],
onFileChange: ( [ media ] ) => {
if ( isBlobURL( media.url ) ) {
return;
}

updateBlockAttributes( image.clientId, {
id: media.id,
url: media.url,
} );
resolve();
},
onError() {
reject();
},
} );
} )
updateBlockAttributes( image.clientId, {
id: media.id,
url: media.url,
} );
resolve();
},
onError() {
reject();
},
} );
} ).then( () => setIsAnimating( true ) )
)
)
).finally( () => {
Expand All @@ -139,12 +139,14 @@ export default function PostFormatPanel() {
gap: '8px',
} }
>
<AnimatePresence>
<AnimatePresence
onExitComplete={ () => setIsAnimating( false ) }
>
{ externalImages.map( ( image ) => {
return <Image key={ image.clientId } { ...image } />;
} ) }
</AnimatePresence>
{ isUploading ? (
{ isUploading || isAnimating ? (
<Spinner />
) : (
<Button variant="primary" onClick={ uploadImages }>
Expand Down

0 comments on commit aa2188e

Please sign in to comment.