mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 13:28:25 +00:00 
			
		
		
		
	Use "is-loading" to avoid duplicate form submit for code comment (#28143)
When the form is going to be submitted, add the "is-loading" class to show an indicator and avoid user UI events. When the request finishes (success / error), remove the "is-loading" class to make user can interact the UI.
This commit is contained in:
		@@ -6,8 +6,9 @@ import {initDiffCommitSelect} from './repo-diff-commitselect.js';
 | 
				
			|||||||
import {validateTextareaNonEmpty} from './comp/ComboMarkdownEditor.js';
 | 
					import {validateTextareaNonEmpty} from './comp/ComboMarkdownEditor.js';
 | 
				
			||||||
import {initViewedCheckboxListenerFor, countAndUpdateViewedFiles, initExpandAndCollapseFilesButton} from './pull-view-file.js';
 | 
					import {initViewedCheckboxListenerFor, countAndUpdateViewedFiles, initExpandAndCollapseFilesButton} from './pull-view-file.js';
 | 
				
			||||||
import {initImageDiff} from './imagediff.js';
 | 
					import {initImageDiff} from './imagediff.js';
 | 
				
			||||||
 | 
					import {showErrorToast} from '../modules/toast.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const {csrfToken, pageData} = window.config;
 | 
					const {csrfToken, pageData, i18n} = window.config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function initRepoDiffReviewButton() {
 | 
					function initRepoDiffReviewButton() {
 | 
				
			||||||
  const $reviewBox = $('#review-box');
 | 
					  const $reviewBox = $('#review-box');
 | 
				
			||||||
@@ -50,6 +51,9 @@ function initRepoDiffConversationForm() {
 | 
				
			|||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ($form.hasClass('is-loading')) return;
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      $form.addClass('is-loading');
 | 
				
			||||||
      const formData = new FormData($form[0]);
 | 
					      const formData = new FormData($form[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // if the form is submitted by a button, append the button's name and value to the form data
 | 
					      // if the form is submitted by a button, append the button's name and value to the form data
 | 
				
			||||||
@@ -70,6 +74,11 @@ function initRepoDiffConversationForm() {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
      $newConversationHolder.find('.dropdown').dropdown();
 | 
					      $newConversationHolder.find('.dropdown').dropdown();
 | 
				
			||||||
      initCompReactionSelector($newConversationHolder);
 | 
					      initCompReactionSelector($newConversationHolder);
 | 
				
			||||||
 | 
					    } catch { // here the caught error might be a jQuery AJAX error (thrown by await $.post), which is not good to use for error message handling
 | 
				
			||||||
 | 
					      showErrorToast(i18n.network_error);
 | 
				
			||||||
 | 
					    } finally {
 | 
				
			||||||
 | 
					      $form.removeClass('is-loading');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $(document).on('click', '.resolve-conversation', async function (e) {
 | 
					  $(document).on('click', '.resolve-conversation', async function (e) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user