Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock post saving during image uploads #41120

Merged
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7811840
Lock post saving during image uploads
adamsilverstein May 18, 2022
abc168f
Lock post saving during image uploads - take 2
adamsilverstein May 18, 2022
a68a343
Improve key naming
adamsilverstein May 18, 2022
cdeb791
Merge branch 'trunk' into issue/39223-save-while-uploading-incomplete
adamsilverstein Sep 11, 2022
885ffb4
Avoid double declaring noop
adamsilverstein Sep 11, 2022
70fcc2a
Merge branch 'issue/39223-save-while-uploading-incomplete' of github.…
adamsilverstein Sep 11, 2022
fd57c01
Ensure post saving, autosaving and publish panel are properly disable…
adamsilverstein Sep 13, 2022
f172b0c
clean up locking
adamsilverstein Sep 14, 2022
dc92caa
revert package.json from trunk to update
adamsilverstein Jul 13, 2023
d2177e2
restore packages/editor/package.json
adamsilverstein Jul 13, 2023
9f2d0df
Merge branch 'trunk' into issue/39223-save-while-uploading-incomplete
adamsilverstein Jul 13, 2023
e505854
Merge branch 'trunk' into issue/39223-save-while-uploading-incomplete
adamsilverstein Jul 17, 2023
f59e050
Merge branch 'trunk'
adamsilverstein Jul 2, 2024
42d8599
Merge branch 'trunk' into issue/39223-save-while-uploading-incomplete
adamsilverstein Jul 8, 2024
b9ce6f1
rename uploadLock -> saveLock
adamsilverstein Jul 8, 2024
326f2dc
add uuid to editor package.json
adamsilverstein Jul 9, 2024
6b04c18
Merge branch 'trunk' into issue/39223-save-while-uploading-incomplete
adamsilverstein Jul 9, 2024
7ac01ca
match uuid version
adamsilverstein Jul 19, 2024
19f7ab9
npm install
adamsilverstein Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions packages/editor/src/utils/media-upload/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* External dependencies
*/
import { noop, uniqueId } from 'lodash';
adamsilverstein marked this conversation as resolved.
Show resolved Hide resolved

/**
* WordPress dependencies
*/
import { select } from '@wordpress/data';
import { select, dispatch } from '@wordpress/data';
adamsilverstein marked this conversation as resolved.
Show resolved Hide resolved
import { uploadMedia } from '@wordpress/media-utils';

/**
Expand Down Expand Up @@ -32,20 +37,38 @@ export default function mediaUpload( {
onFileChange,
} ) {
const { getCurrentPostId, getEditorSettings } = select( editorStore );
const { lockPostSaving, unlockPostSaving } = dispatch( editorStore );
adamsilverstein marked this conversation as resolved.
Show resolved Hide resolved
const wpAllowedMimeTypes = getEditorSettings().allowedMimeTypes;
const locakKeyID = uniqueId();
const lockKey = `image-upload-${ locakKeyID }`;
let postSaveLocked = false;
maxUploadFileSize =
maxUploadFileSize || getEditorSettings().maxUploadFileSize;

uploadMedia( {
allowedTypes,
filesList,
onFileChange,
onFileChange: ( file ) => {
const remainingUploads = file.filter( ( f ) => ! f.id );
if ( ! postSaveLocked && remainingUploads ) {
lockPostSaving( lockKey );
postSaveLocked = true;
} else {
unlockPostSaving( lockKey );
postSaveLocked = false;
}
onFileChange( file );
},
additionalData: {
post: getCurrentPostId(),
...additionalData,
},
maxUploadFileSize,
onError: ( { message } ) => onError( message ),
onError: ( { message } ) => {
unlockPostSaving( lockKey );
postSaveLocked = false;
onError( message );
},
wpAllowedMimeTypes,
} );
}