aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/features/repo-issue-edit.ts
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-11-07 04:21:53 +0800
committerGitHub <noreply@github.com>2024-11-07 04:21:53 +0800
commitb573512312d82e894db7aac89f4938a6b61e1e70 (patch)
treec80b6965a6a3831c64fce979c0dfe12f850c6acb /web_src/js/features/repo-issue-edit.ts
parent41b4ef825dba14f11b2e9454692b999f92ee1a42 (diff)
downloadgitea-b573512312d82e894db7aac89f4938a6b61e1e70.tar.gz
gitea-b573512312d82e894db7aac89f4938a6b61e1e70.zip
Correctly query the primary button in a form (#32438)
The "primary button" is used at many places, but sometimes they might conflict (due to button switch, hidden panel, dropdown menu, etc). Sometimes we could add a special CSS class for the buttons, but sometimes not (see the comment of QuickSubmit) This PR introduces `querySingleVisibleElem` to help to get the correct primary button (the only visible one), and prevent from querying the wrong buttons. Fix #32437 --------- Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'web_src/js/features/repo-issue-edit.ts')
-rw-r--r--web_src/js/features/repo-issue-edit.ts14
1 files changed, 8 insertions, 6 deletions
diff --git a/web_src/js/features/repo-issue-edit.ts b/web_src/js/features/repo-issue-edit.ts
index 77a76ad3ca..af97ee4eab 100644
--- a/web_src/js/features/repo-issue-edit.ts
+++ b/web_src/js/features/repo-issue-edit.ts
@@ -3,7 +3,7 @@ import {handleReply} from './repo-issue.ts';
import {getComboMarkdownEditor, initComboMarkdownEditor, ComboMarkdownEditor} from './comp/ComboMarkdownEditor.ts';
import {POST} from '../modules/fetch.ts';
import {showErrorToast} from '../modules/toast.ts';
-import {hideElem, showElem} from '../utils/dom.ts';
+import {hideElem, querySingleVisibleElem, showElem} from '../utils/dom.ts';
import {attachRefIssueContextPopup} from './contextpopup.ts';
import {initCommentContent, initMarkupContent} from '../markup/content.ts';
import {triggerUploadStateChanged} from './comp/EditorUpload.ts';
@@ -77,20 +77,22 @@ async function onEditContent(event) {
}
};
+ // Show write/preview tab and copy raw content as needed
+ showElem(editContentZone);
+ hideElem(renderContent);
+
comboMarkdownEditor = getComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor'));
if (!comboMarkdownEditor) {
editContentZone.innerHTML = document.querySelector('#issue-comment-editor-template').innerHTML;
- const saveButton = editContentZone.querySelector('.ui.primary.button');
+ const saveButton = querySingleVisibleElem<HTMLButtonElement>(editContentZone, '.ui.primary.button');
+ const cancelButton = querySingleVisibleElem<HTMLButtonElement>(editContentZone, '.ui.cancel.button');
comboMarkdownEditor = await initComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor'));
const syncUiState = () => saveButton.disabled = comboMarkdownEditor.isUploading();
comboMarkdownEditor.container.addEventListener(ComboMarkdownEditor.EventUploadStateChanged, syncUiState);
- editContentZone.querySelector('.ui.cancel.button').addEventListener('click', cancelAndReset);
+ cancelButton.addEventListener('click', cancelAndReset);
saveButton.addEventListener('click', saveAndRefresh);
}
- // Show write/preview tab and copy raw content as needed
- showElem(editContentZone);
- hideElem(renderContent);
// FIXME: ideally here should reload content and attachment list from backend for existing editor, to avoid losing data
if (!comboMarkdownEditor.value()) {
comboMarkdownEditor.value(rawContent.textContent);