Skip to content
5 changes: 5 additions & 0 deletions web_src/js/features/comp/ComboMarkdownEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ class ComboMarkdownEditor {
this.attachedDropzoneInst.emit(DropzoneCustomEventReloadFiles);
}

isUploading() {
if (!this.dropzone) return false;
return this.attachedDropzoneInst.getUploadingFiles().length !== 0;
}

setupTab() {
const tabs = this.container.querySelectorAll('.tabular.menu > .item');

Expand Down
8 changes: 5 additions & 3 deletions web_src/js/features/comp/EditorUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

let uploadIdCounter = 0;

function uploadFile(dropzoneEl, file) {
function uploadFile(dropzoneEl, file, placeholderCallback) {
return new Promise((resolve) => {
const curUploadId = uploadIdCounter++;
file._giteaUploadId = curUploadId;
Expand All @@ -23,6 +23,8 @@ function uploadFile(dropzoneEl, file) {
};
dropzoneInst.on(DropzoneCustomEventUploadDone, onUploadDone);
dropzoneInst.handleFiles([file]);
// if there is no setTimeout, then ComboMarkdownEditor.isUploading() does not working correctly
setTimeout(() => placeholderCallback(), 0);
});
}

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

editor.insertPlaceholder(placeholder);
await uploadFile(dropzoneEl, file); // the "file" will get its "uuid" during the upload
// the "file" will get its "uuid" during the upload
await uploadFile(dropzoneEl, file, () => editor.insertPlaceholder(placeholder));
editor.replacePlaceholder(placeholder, generateMarkdownLinkForAttachment(file, {width, dppx}));
}
}
Expand Down
13 changes: 12 additions & 1 deletion web_src/js/features/repo-issue-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,21 @@ async function onEditContent(event) {

comboMarkdownEditor = getComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor'));
if (!comboMarkdownEditor) {
const opts = {};
opts.onContentChanged = (editor) => {
const saveButton = editContentZone.querySelector('.ui.primary.button');
const isUploading = editor.isUploading();
if (saveButton) {
saveButton.disabled = isUploading;
}
};

editContentZone.innerHTML = document.querySelector('#issue-comment-editor-template').innerHTML;
comboMarkdownEditor = await initComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor'));
comboMarkdownEditor = await initComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor'), opts);

editContentZone.querySelector('.ui.cancel.button').addEventListener('click', cancelAndReset);
editContentZone.querySelector('.ui.primary.button').addEventListener('click', saveAndRefresh);
opts.onContentChanged(comboMarkdownEditor);
}

// Show write/preview tab and copy raw content as needed
Expand Down
5 changes: 4 additions & 1 deletion web_src/js/features/repo-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,14 @@ export async function initSingleCommentEditor($commentForm) {
const commentButton = document.querySelector('#comment-button');
opts.onContentChanged = (editor) => {
const editorText = editor.value().trim();
const isUploading = editor.isUploading();

if (statusButton) {
statusButton.textContent = statusButton.getAttribute(editorText ? 'data-status-and-comment' : 'data-status');
statusButton.disabled = isUploading;
}
if (commentButton) {
commentButton.disabled = !editorText;
commentButton.disabled = !editorText || isUploading;
}
};
const editor = await initComboMarkdownEditor($commentForm.find('.combo-markdown-editor'), opts);
Expand Down