mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
Added image upload progress to Koenig-Lexical-Editor (#15852)
ref https://github.com/TryGhost/Team/issues/2237 - Adds an upload progress function, to be used with Koenig-Lexical.
This commit is contained in:
parent
0c2a62f47c
commit
c70a1f262d
@ -109,21 +109,24 @@ export default class KoenigLexicalEditor extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReactComponent = () => {
|
ReactComponent = () => {
|
||||||
const [uploadProgressPercentage] = React.useState(0); // not in use right now, but will need to decide how to handle the percentage state and pass to the Image Cards
|
const [uploadProgress, setUploadProgress] = React.useState(0);
|
||||||
|
|
||||||
// const uploadProgress = (event) => {
|
const uploadProgressHandler = (event) => {
|
||||||
// const percentComplete = (event.loaded / event.total) * 100;
|
const percentComplete = (event.loaded / event.total) * 100;
|
||||||
// setUploadProgressPercentage(percentComplete);
|
setUploadProgress(percentComplete);
|
||||||
// };
|
if (percentComplete === 100) {
|
||||||
|
setUploadProgress(0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
async function imageUploader(files) {
|
async function imageUploader(files) {
|
||||||
function uploadToUrl(formData, url) {
|
function uploadToUrl(formData, url) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open('POST', url);
|
xhr.open('POST', url);
|
||||||
// xhr.upload.onprogress = (event) => {
|
xhr.upload.onprogress = (event) => {
|
||||||
// uploadProgress(event);
|
uploadProgressHandler(event);
|
||||||
// };
|
};
|
||||||
xhr.onload = () => resolve(xhr.response);
|
xhr.onload = () => resolve(xhr.response);
|
||||||
xhr.onerror = () => reject(xhr.statusText);
|
xhr.onerror = () => reject(xhr.statusText);
|
||||||
xhr.send(formData);
|
xhr.send(formData);
|
||||||
@ -146,7 +149,7 @@ export default class KoenigLexicalEditor extends Component {
|
|||||||
<KoenigComposer
|
<KoenigComposer
|
||||||
initialEditorState={this.args.lexical}
|
initialEditorState={this.args.lexical}
|
||||||
onError={this.onError}
|
onError={this.onError}
|
||||||
imageUploadFunction={{imageUploader, uploadProgressPercentage}} >
|
imageUploadFunction={{imageUploader, uploadProgress}} >
|
||||||
<KoenigEditor onChange={this.args.onChange} />
|
<KoenigEditor onChange={this.args.onChange} />
|
||||||
</KoenigComposer>
|
</KoenigComposer>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
Loading…
Reference in New Issue
Block a user