| 
1 | 1 | import $ from 'jquery';  | 
2 | 2 | import {htmlEscape} from 'escape-goat';  | 
3 |  | -import {showTemporaryTooltip, createTippy} from '../modules/tippy.js';  | 
 | 3 | +import {createTippy, showTemporaryTooltip} from '../modules/tippy.js';  | 
4 | 4 | import {hideElem, showElem, toggleElem} from '../utils/dom.js';  | 
5 | 5 | import {setFileFolding} from './file-fold.js';  | 
6 | 6 | import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js';  | 
7 | 7 | import {toAbsoluteUrl} from '../utils.js';  | 
8 | 8 | import {initDropzone} from './dropzone.js';  | 
9 |  | -import {POST, GET} from '../modules/fetch.js';  | 
 | 9 | +import {GET, POST} from '../modules/fetch.js';  | 
10 | 10 | import {showErrorToast} from '../modules/toast.js';  | 
11 | 11 | 
 
  | 
12 | 12 | const {appSubUrl} = window.config;  | 
@@ -673,19 +673,24 @@ export function initRepoIssueBranchSelect() {  | 
673 | 673 |   });  | 
674 | 674 | }  | 
675 | 675 | 
 
  | 
676 |  | -export function initSingleCommentEditor($commentForm) {  | 
 | 676 | +export async function initSingleCommentEditor($commentForm) {  | 
677 | 677 |   // pages:  | 
678 |  | -  // * normal new issue/pr page, no status-button  | 
679 |  | -  // * issue/pr view page, with comment form, has status-button  | 
 | 678 | +  // * normal new issue/pr page: no status-button, no comment-button (there is only a normal submit button which can submit empty content)  | 
 | 679 | +  // * issue/pr view page: with comment form, has status-button and comment-button  | 
680 | 680 |   const opts = {};  | 
681 | 681 |   const statusButton = document.querySelector('#status-button');  | 
682 |  | -  if (statusButton) {  | 
683 |  | -    opts.onContentChanged = (editor) => {  | 
684 |  | -      const statusText = statusButton.getAttribute(editor.value().trim() ? 'data-status-and-comment' : 'data-status');  | 
685 |  | -      statusButton.textContent = statusText;  | 
686 |  | -    };  | 
687 |  | -  }  | 
688 |  | -  initComboMarkdownEditor($commentForm.find('.combo-markdown-editor'), opts);  | 
 | 682 | +  const commentButton = document.querySelector('#comment-button');  | 
 | 683 | +  opts.onContentChanged = (editor) => {  | 
 | 684 | +    const editorText = editor.value().trim();  | 
 | 685 | +    if (statusButton) {  | 
 | 686 | +      statusButton.textContent = statusButton.getAttribute(editorText ? 'data-status-and-comment' : 'data-status');  | 
 | 687 | +    }  | 
 | 688 | +    if (commentButton) {  | 
 | 689 | +      commentButton.disabled = !editorText;  | 
 | 690 | +    }  | 
 | 691 | +  };  | 
 | 692 | +  const editor = await initComboMarkdownEditor($commentForm.find('.combo-markdown-editor'), opts);  | 
 | 693 | +  opts.onContentChanged(editor); // sync state of buttons with the initial content  | 
689 | 694 | }  | 
690 | 695 | 
 
  | 
691 | 696 | export function initIssueTemplateCommentEditors($commentForm) {  | 
 | 
0 commit comments