Skip to content

Commit f3c7c26

Browse files
committed
prevent upload button on uploading with callback
1 parent 34cfdaf commit f3c7c26

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

web_src/js/features/comp/ComboMarkdownEditor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ class ComboMarkdownEditor {
138138
}
139139

140140
isUploading() {
141-
if (!this.dropzone) return false;
142-
return this.attachedDropzoneInst.getUploadingFiles().length != 0;
141+
if (!this.dropzone) return false;
142+
return this.attachedDropzoneInst.getUploadingFiles().length !== 0;
143143
}
144-
144+
145145
setupTab() {
146146
const tabs = this.container.querySelectorAll('.tabular.menu > .item');
147147

web_src/js/features/comp/EditorUpload.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
let uploadIdCounter = 0;
1212

13-
function uploadFile(dropzoneEl, file) {
13+
function uploadFile(dropzoneEl, file, placeholderCallback) {
1414
return new Promise((resolve) => {
1515
const curUploadId = uploadIdCounter++;
1616
file._giteaUploadId = curUploadId;
@@ -23,6 +23,8 @@ function uploadFile(dropzoneEl, file) {
2323
};
2424
dropzoneInst.on(DropzoneCustomEventUploadDone, onUploadDone);
2525
dropzoneInst.handleFiles([file]);
26+
// if there is no setTimeout, then ComboMarkdownEditor.isUploading() does not working correctly
27+
setTimeout(() => placeholderCallback(), 0);
2628
});
2729
}
2830

@@ -99,17 +101,8 @@ async function handleUploadFiles(editor, dropzoneEl, files, e) {
99101
const {width, dppx} = await imageInfo(file);
100102
const placeholder = `[${name}](uploading ...)`;
101103

102-
// Placeholders should be inserted on uploading the thumnail.
103-
// If not, the check upload process may fail
104-
const handleInsertPlaceholder = () => editor.insertPlaceholder(placeholder);
105-
dropzoneEl.dropzone.on('thumbnail', handleInsertPlaceholder);
106-
try {
107-
await uploadFile(dropzoneEl, file); // the "file" will get its "uuid" during the upload
108-
} catch (err) {
109-
throw err;
110-
} finally {
111-
dropzoneEl.dropzone.off('thumbnail', handleInsertPlaceholder);
112-
}
104+
// the "file" will get its "uuid" during the upload
105+
await uploadFile(dropzoneEl, file, () => editor.insertPlaceholder(placeholder));
113106
editor.replacePlaceholder(placeholder, generateMarkdownLinkForAttachment(file, {width, dppx}));
114107
}
115108
}

web_src/js/features/repo-issue-edit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async function onEditContent(event) {
8989

9090
editContentZone.innerHTML = document.querySelector('#issue-comment-editor-template').innerHTML;
9191
comboMarkdownEditor = await initComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor'), opts);
92-
92+
9393
editContentZone.querySelector('.ui.cancel.button').addEventListener('click', cancelAndReset);
9494
editContentZone.querySelector('.ui.primary.button').addEventListener('click', saveAndRefresh);
9595
opts.onContentChanged(comboMarkdownEditor);

0 commit comments

Comments
 (0)