-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Fix repo diff review comment counter increment behaviour #31641
Changes from all commits
3bbb210
4cd3734
25f947d
2f1a5ce
1e05144
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,15 +19,40 @@ function initRepoDiffReviewButton() { | |||||
const counter = reviewBox.querySelector('.review-comments-counter'); | ||||||
if (!counter) return; | ||||||
|
||||||
$(document).on('click', 'button[name="pending_review"]', (e) => { | ||||||
const $form = $(e.target).closest('form'); | ||||||
// Watch for the form's submit event. | ||||||
$form.on('submit', () => { | ||||||
const num = parseInt(counter.getAttribute('data-pending-comment-number')) + 1 || 1; | ||||||
function handleFormSubmit(form, textarea) { | ||||||
if (form.getAttribute('data-handler-attached') === 'true') return; | ||||||
form.setAttribute('data-handler-attached', 'true'); | ||||||
form.addEventListener('submit', (event) => { | ||||||
if (textarea.value.trim() === '') { | ||||||
event.preventDefault(); | ||||||
return; | ||||||
} | ||||||
const num = (parseInt(counter.getAttribute('data-pending-comment-number')) || 0) + 1; | ||||||
counter.setAttribute('data-pending-comment-number', num); | ||||||
counter.textContent = num; | ||||||
animateOnce(reviewBox, 'pulse-1p5-200'); | ||||||
form.removeAttribute('data-handler-attached'); | ||||||
}); | ||||||
} | ||||||
|
||||||
// Handle submit on click | ||||||
document.addEventListener('click', (e) => { | ||||||
if (e.target.name === 'pending_review') { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This condition seems wrong to me: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either way, it's probably better to use
Suggested change
|
||||||
const form = e.target.closest('form'); | ||||||
const textarea = form.querySelector('textarea'); | ||||||
handleFormSubmit(form, textarea); | ||||||
} | ||||||
}); | ||||||
|
||||||
// Handle submit by ctrl+enter | ||||||
document.addEventListener('keydown', (e) => { | ||||||
if (e.ctrlKey && e.key === 'Enter') { | ||||||
const textarea = e.target; | ||||||
if (textarea.tagName.toLowerCase() === 'textarea') { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. toLowerCase? 🤨 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, why is |
||||||
const form = textarea.closest('form'); | ||||||
handleFormSubmit(form, textarea); | ||||||
} | ||||||
} | ||||||
}); | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This architecture is a bit weird:
Why remove and re-add the handler all the time?
Typically, our behavior would rather be "initialize once on page load, and then keep it".