Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "is-loading" to avoid duplicate form submit for code comment #28143

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion web_src/js/features/repo-diff.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down