From 642757393b98f5456dc7416e2ccb27b47b15e427 Mon Sep 17 00:00:00 2001 From: Kemal Zebari Date: Sat, 22 Jun 2024 11:52:20 -0700 Subject: [PATCH 1/3] Disable issue/PR comment button given empty input --- templates/repo/issue/view_content.tmpl | 2 +- web_src/js/features/repo-issue.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 3088c605104f1..86868c339ea3d 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -106,7 +106,7 @@ {{end}} {{end}} - diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index fb5b3b191d11a..b5871487d8bb6 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -679,10 +679,17 @@ export function initSingleCommentEditor($commentForm) { // * issue/pr view page, with comment form, has status-button const opts = {}; const statusButton = document.querySelector('#status-button'); - if (statusButton) { + const commentButton = document.querySelector('#comment-button'); + if (statusButton || commentButton) { opts.onContentChanged = (editor) => { - const statusText = statusButton.getAttribute(editor.value().trim() ? 'data-status-and-comment' : 'data-status'); - statusButton.textContent = statusText; + const editorText = editor.value().trim(); + if (statusButton) { + const statusText = statusButton.getAttribute(editorText ? 'data-status-and-comment' : 'data-status'); + statusButton.textContent = statusText; + } + if (commentButton) { + commentButton.disabled = !editorText; + } }; } initComboMarkdownEditor($commentForm.find('.combo-markdown-editor'), opts); From 90a6716bbe9812ca96b6e37df8645c3a518565d3 Mon Sep 17 00:00:00 2001 From: Kemal Zebari Date: Sun, 23 Jun 2024 09:48:22 -0700 Subject: [PATCH 2/3] Use opts.onContentChanged() explicitly --- templates/repo/issue/view_content.tmpl | 2 +- web_src/js/features/repo-issue.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 86868c339ea3d..e4213b8fcd6b3 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -106,7 +106,7 @@ {{end}} {{end}} - diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index b5871487d8bb6..caf7cad75d44f 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -673,7 +673,7 @@ export function initRepoIssueBranchSelect() { }); } -export function initSingleCommentEditor($commentForm) { +export async function initSingleCommentEditor($commentForm) { // pages: // * normal new issue/pr page, no status-button // * issue/pr view page, with comment form, has status-button @@ -692,7 +692,9 @@ export function initSingleCommentEditor($commentForm) { } }; } - initComboMarkdownEditor($commentForm.find('.combo-markdown-editor'), opts); + const editor = await initComboMarkdownEditor($commentForm.find('.combo-markdown-editor'), opts); + // initialize comment button + opts.onContentChanged(editor); } export function initIssueTemplateCommentEditors($commentForm) { From cdf2798680bdf74016231a2747a420b5b069171f Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 24 Jun 2024 01:24:58 +0800 Subject: [PATCH 3/3] fix initSingleCommentEditor and add comment --- web_src/js/features/repo-issue.js | 32 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index caf7cad75d44f..a754e2ae9a5ed 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -1,12 +1,12 @@ import $ from 'jquery'; import {htmlEscape} from 'escape-goat'; -import {showTemporaryTooltip, createTippy} from '../modules/tippy.js'; +import {createTippy, showTemporaryTooltip} from '../modules/tippy.js'; import {hideElem, showElem, toggleElem} from '../utils/dom.js'; import {setFileFolding} from './file-fold.js'; import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js'; import {toAbsoluteUrl} from '../utils.js'; import {initDropzone} from './dropzone.js'; -import {POST, GET} from '../modules/fetch.js'; +import {GET, POST} from '../modules/fetch.js'; import {showErrorToast} from '../modules/toast.js'; const {appSubUrl} = window.config; @@ -675,26 +675,22 @@ export function initRepoIssueBranchSelect() { export async function initSingleCommentEditor($commentForm) { // pages: - // * normal new issue/pr page, no status-button - // * issue/pr view page, with comment form, has status-button + // * normal new issue/pr page: no status-button, no comment-button (there is only a normal submit button which can submit empty content) + // * issue/pr view page: with comment form, has status-button and comment-button const opts = {}; const statusButton = document.querySelector('#status-button'); const commentButton = document.querySelector('#comment-button'); - if (statusButton || commentButton) { - opts.onContentChanged = (editor) => { - const editorText = editor.value().trim(); - if (statusButton) { - const statusText = statusButton.getAttribute(editorText ? 'data-status-and-comment' : 'data-status'); - statusButton.textContent = statusText; - } - if (commentButton) { - commentButton.disabled = !editorText; - } - }; - } + opts.onContentChanged = (editor) => { + const editorText = editor.value().trim(); + if (statusButton) { + statusButton.textContent = statusButton.getAttribute(editorText ? 'data-status-and-comment' : 'data-status'); + } + if (commentButton) { + commentButton.disabled = !editorText; + } + }; const editor = await initComboMarkdownEditor($commentForm.find('.combo-markdown-editor'), opts); - // initialize comment button - opts.onContentChanged(editor); + opts.onContentChanged(editor); // sync state of buttons with the initial content } export function initIssueTemplateCommentEditors($commentForm) {