-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Make issue meta dropdown support Enter, confirm before reloading #23014
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
Changes from all commits
8a4382b
649fa2d
8668a88
6d1c734
1bd96d3
d263120
ec0919e
afef2c4
1f94a46
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 |
---|---|---|
|
@@ -29,6 +29,26 @@ import {hideElem, showElem} from '../utils/dom.js'; | |
|
||
const {csrfToken} = window.config; | ||
|
||
// if there are draft comments (more than 20 chars), confirm before reloading, to avoid losing comments | ||
function reloadConfirmDraftComment() { | ||
const commentTextareas = [ | ||
document.querySelector('.edit-content-zone:not(.gt-hidden) textarea'), | ||
document.querySelector('.edit_area'), | ||
]; | ||
for (const textarea of commentTextareas) { | ||
// Most users won't feel too sad if they lose a comment with 10 or 20 chars, they can re-type these in seconds. | ||
// But if they have typed more (like 50) chars and the comment is lost, they will be very unhappy. | ||
if (textarea && textarea.value.trim().length > 20) { | ||
textarea.parentElement.scrollIntoView(); | ||
if (!window.confirm('Page will be reloaded, but there are draft comments. Continuing to reload will discard the comments. Continue?')) { | ||
return; | ||
} | ||
break; | ||
} | ||
} | ||
window.location.reload(); | ||
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. I'm of the opinion that it's better to just save unsubmitted data into 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. I also proposed so (draft) as one approach. 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.
Before SimpleMDE/EasyMDE, there is a global However, 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. I think we should remove this Ideally I would this to also not use |
||
} | ||
|
||
export function initRepoCommentForm() { | ||
const $commentForm = $('.comment.form'); | ||
if ($commentForm.length === 0) { | ||
|
@@ -86,22 +106,27 @@ export function initRepoCommentForm() { | |
let hasUpdateAction = $listMenu.data('action') === 'update'; | ||
const items = {}; | ||
|
||
$(`.${selector}`).dropdown('setting', 'onHide', () => { | ||
hasUpdateAction = $listMenu.data('action') === 'update'; // Update the var | ||
if (hasUpdateAction) { | ||
// TODO: Add batch functionality and make this 1 network request. | ||
(async function() { | ||
for (const [elementId, item] of Object.entries(items)) { | ||
$(`.${selector}`).dropdown({ | ||
'action': 'nothing', // do not hide the menu if user presses Enter | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fullTextSearch: 'exact', | ||
async onHide() { | ||
hasUpdateAction = $listMenu.data('action') === 'update'; // Update the var | ||
if (hasUpdateAction) { | ||
// TODO: Add batch functionality and make this 1 network request. | ||
const itemEntries = Object.entries(items); | ||
for (const [elementId, item] of itemEntries) { | ||
await updateIssuesMeta( | ||
item['update-url'], | ||
item.action, | ||
item['issue-id'], | ||
elementId, | ||
); | ||
} | ||
window.location.reload(); | ||
})(); | ||
} | ||
if (itemEntries.length) { | ||
reloadConfirmDraftComment(); | ||
} | ||
} | ||
}, | ||
}); | ||
|
||
$listMenu.find('.item:not(.no-select)').on('click', function (e) { | ||
|
@@ -196,7 +221,7 @@ export function initRepoCommentForm() { | |
'clear', | ||
$listMenu.data('issue-id'), | ||
'', | ||
).then(() => window.location.reload()); | ||
).then(reloadConfirmDraftComment); | ||
} | ||
|
||
$(this).parent().find('.item').each(function () { | ||
|
@@ -239,7 +264,7 @@ export function initRepoCommentForm() { | |
'', | ||
$menu.data('issue-id'), | ||
$(this).data('id'), | ||
).then(() => window.location.reload()); | ||
).then(reloadConfirmDraftComment); | ||
} | ||
|
||
let icon = ''; | ||
|
@@ -272,7 +297,7 @@ export function initRepoCommentForm() { | |
'', | ||
$menu.data('issue-id'), | ||
$(this).data('id'), | ||
).then(() => window.location.reload()); | ||
).then(reloadConfirmDraftComment); | ||
} | ||
|
||
$list.find('.selected').html(''); | ||
|
Uh oh!
There was an error while loading. Please reload this page.