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

Save context when creating mod notes #746

Merged
merged 2 commits into from
Apr 22, 2023
Merged
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions extension/data/modules/modnotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,14 @@ function updateModNotesBadge ($badge, note) {
* @param {object} data Data associated with the popup
* @param {string} data.user Name of the relevant user
* @param {string} data.subreddit Name of the relevant subreddit
* @param {string} [data.contextID] Fullname of the item the popup was opened from, used to write note context
* @param {object[]} [data.notes] Note objects for the user, or null/undefined
* @returns {jQuery} The created popup
*/
function createModNotesPopup ({
user,
subreddit,
contextID,
notes,
defaultTabName,
defaultNoteLabel,
Expand Down Expand Up @@ -274,6 +276,7 @@ function createModNotesPopup ({
});
$popup.attr('data-user', user);
$popup.attr('data-subreddit', subreddit);
$popup.attr('data-context-id', contextID);

updateModNotesPopup($popup, {
notes,
Expand Down Expand Up @@ -460,8 +463,10 @@ export default new Module({
}, function ({defaultTabName, defaultNoteLabel}) {
// Handle authors showing up on the page
TBListener.on('author', async e => {
this.info(e.detail);
const subreddit = e.detail.data.subreddit.name;
const author = e.detail.data.author;
const contextID = e.detail.data.comment?.id || e.detail.data.post?.id;

// Deleted users can't have notes
if (author === '[deleted]') {
Expand Down Expand Up @@ -509,6 +514,7 @@ export default new Module({
user: author,
subreddit,
notes,
contextID,
defaultTabName,
defaultNoteLabel,
})
Expand Down Expand Up @@ -551,6 +557,7 @@ export default new Module({
subreddit: $popup.attr('data-subreddit'),
note: $textInput.val(),
label: $labelSelect.val() || undefined,
redditID: $popup.attr('data-context-id'),
});
$textInput.val('');
textFeedback('Note saved', FEEDBACK_POSITIVE);
Expand Down