-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Do not reload page after adding comments in Pull Request reviews #13877
Conversation
Codecov Report
@@ Coverage Diff @@
## master #13877 +/- ##
==========================================
- Coverage 41.85% 41.81% -0.04%
==========================================
Files 743 743
Lines 79393 79453 +60
==========================================
- Hits 33228 33223 -5
- Misses 40703 40766 +63
- Partials 5462 5464 +2
Continue to review full report at Codecov.
|
Some suggestions. Mostly async ajax requests and simplification.diff --git a/web_src/js/index.js b/web_src/js/index.js
index fbbd97bdf..b94bf527c 100644
--- a/web_src/js/index.js
+++ b/web_src/js/index.js
@@ -1275,9 +1275,9 @@ function initPullRequestReview() {
e.preventDefault();
$(this).closest('.menu').toggle('visible');
});
- $('a.add-code-comment').on('click', function (e) {
+ $('a.add-code-comment').on('click', async function (e) {
if ($(e.target).hasClass('btn-add-single')) return; // https://github.com/go-gitea/gitea/issues/4745
e.preventDefault();
const isSplit = $(this).closest('.code-diff').hasClass('code-diff-split');
@@ -1308,22 +1308,20 @@ function initPullRequestReview() {
const td = ntr.find(`.add-comment-${side}`);
let commentCloud = td.find('.comment-code-cloud');
if (commentCloud.length === 0 && !ntr.find('button[name="is_review"]').length) {
- const url = $(this).data('new-comment-url');
- $.get(url, (data) => {
- td.html(data);
- commentCloud = td.find('.comment-code-cloud');
- assingMenuAttributes(commentCloud.find('.menu'));
- td.find("input[name='line']").val(idx);
- td.find("input[name='side']").val(side === 'left' ? 'previous' : 'proposed');
- td.find("input[name='path']").val(path);
- const $textarea = commentCloud.find('textarea');
- attachTribute($textarea.get(), {mentions: true, emoji: true});
- const $simplemde = setCommentSimpleMDE($textarea);
- $textarea.focus();
- $simplemde.codemirror.focus();
- });
+ const data = await $.get($(this).data('new-comment-url'));
+ td.html(data);
+ commentCloud = td.find('.comment-code-cloud');
+ assingMenuAttributes(commentCloud.find('.menu'));
+ td.find("input[name='line']").val(idx);
+ td.find("input[name='side']").val(side === 'left' ? 'previous' : 'proposed');
+ td.find("input[name='path']").val(path);
+ const $textarea = commentCloud.find('textarea');
+ attachTribute($textarea.get(), {mentions: true, emoji: true});
+ const $simplemde = setCommentSimpleMDE($textarea);
+ $textarea.focus();
+ $simplemde.codemirror.focus();
}
});
}
@@ -2483,31 +2481,26 @@ $(document).ready(async () => {
e.checked = false;
$(e).trigger('click');
});
- $(document).on('click', '.resolve-conversation', function (e) {
+ $(document).on('click', '.resolve-conversation', async function (e) {
e.preventDefault();
- const id = $(this).data('comment-id');
+ const comment_id = $(this).data('comment-id');
const origin = $(this).data('origin');
const action = $(this).data('action');
const url = $(this).data('update-url');
- $.post(url, {
- _csrf: csrf,
- origin,
- action,
- comment_id: id,
- }, (data) => {
- if ($(this).closest('.conversation-holder').length) {
- const conversation = $(data);
- $(this).closest('.conversation-holder').replaceWith(conversation);
- conversation.find('.dropdown').dropdown();
- initReactionSelector(conversation);
- initClipboard();
- } else {
- reload();
- }
- });
+ const data = await $.post(url, {_csrf: csrf, origin, action, comment_id});
+ if ($(this).closest('.conversation-holder').length) {
+ const conversation = $(data);
+ $(this).closest('.conversation-holder').replaceWith(conversation);
+ conversation.find('.dropdown').dropdown();
+ initReactionSelector(conversation);
+ initClipboard();
+ } else {
+ reload();
+ }
});
buttonsClickOnEnter();
searchUsers();
@@ -3617,27 +3610,23 @@ function initIssueList() {
$(document).on('click', 'button[name="is_review"]', (e) => {
$(e.target).closest('form').append('<input type="hidden" name="is_review" value="true">');
});
-$(document).on('submit', '.conversation-holder form', (e) => {
+$(document).on('submit', '.conversation-holder form', async (e) => {
e.preventDefault();
const form = $(e.target);
- $.post(form.attr('action'), form.serialize(), (data) => {
- const conversation = $(data);
- const path = conversation.data('path');
- const side = conversation.data('side');
- const idx = conversation.data('idx');
- const lineType = form.closest('tr').data('line-type');
- form.closest('.conversation-holder').replaceWith(conversation);
- if (lineType === 'same') {
- $(`a.add-code-comment[data-path="${path}"][data-idx="${idx}"]`).addClass('invisible');
- } else {
- $(`a.add-code-comment[data-path="${path}"][data-side="${side}"][data-idx="${idx}"]`).addClass('invisible');
- }
- conversation.find('.dropdown').dropdown();
- initReactionSelector(conversation);
- initClipboard();
- });
+ const newConversationHolder = $(await $.post(form.attr('action'), form.serialize()));
+ const {path, side, idx} = newConversationHolder.data();
+ form.closest('.conversation-holder').replaceWith(newConversationHolder);
+ if (form.closest('tr').data('line-type') === 'same') {
+ $(`a.add-code-comment[data-path="${path}"][data-idx="${idx}"]`).addClass('invisible');
+ } else {
+ $(`a.add-code-comment[data-path="${path}"][data-side="${side}"][data-idx="${idx}"]`).addClass('invisible');
+ }
+ newConversationHolder.find('.dropdown').dropdown();
+ initReactionSelector(newConversationHolder);
+ initClipboard();
});
window.cancelCodeComment = function (btn) {
const form = $(btn).closest('form'); |
FetchCodeCommentsByLine was initially more or less copied from fetchCodeCommentsByReview. Now they both use a common findCodeComments function instead
252d8db
to
eadbbbe
Compare
Rebased because there were some merge conflicts. I also extracted some duplicate code. FetchCodeCommentsByLine was initially more or less copied from fetchCodeCommentsByReview. Now they both use a common findCodeComments function instead. |
ping 👀 |
🚀 |
* master: (252 commits) Issues overview should not show issues from archived repos (go-gitea#13220) Display SVG files as images instead of text (go-gitea#14101) [skip ci] Updated translations via Crowdin Update docs to clarify issues raised in go-gitea#14272 (go-gitea#14318) [skip ci] Updated translations via Crowdin [Refactor] Passwort Hash/Set (go-gitea#14282) Add option to change username to the admin panel (go-gitea#14229) fix mailIssueCommentBatch for pull request (go-gitea#14252) Remove self from MAINTAINERS (go-gitea#14286) Do not reload page after adding comments in Pull Request reviews (go-gitea#13877) Fix session bug when introduce chi (go-gitea#14287) [skip ci] Updated translations via Crowdin Add secure/httpOnly attributes to the lang cookie (go-gitea#9690) (go-gitea#14279) Some code improvements (go-gitea#14266) [skip ci] Updated translations via Crowdin Fix wrong type on hooktask to convert typ from char(16) to varchar(16) (go-gitea#14148) Upgrade XORM links in documentation. (go-gitea#14265) Check permission for the appropriate unit type (go-gitea#14261) Add compliance check for windows to ensure cross platform build (go-gitea#14260) [skip ci] Updated translations via Crowdin ...
Fixes #8861.
Use ajax on PR review page for submitting review comments, adding replies and (un)resolving conversations, instead of refreshing the entire page on each interaction.