Skip to content

Commit

Permalink
feat: add ability to flag post from LQA review queue
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Jun 12, 2024
1 parent 98b1d4a commit 099e39e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CopyPastorAPI } from './UserscriptTools/CopyPastorAPI';
import { Cached, Store } from './UserscriptTools/Store';

import Page from './UserscriptTools/Page';
import { Checkbox } from '@userscripters/stacks-helpers';

interface ReviewQueueResponse {
postId: number;
Expand Down Expand Up @@ -95,6 +96,21 @@ export function setupReview(): void {
const submit = document.querySelector('form .js-modal-submit');
if (!submit) return;

const [, checkbox] = Checkbox.makeStacksCheckboxes(
[
{
id: 'advanced-flagging-flag-post',
labelConfig: {
text: 'Flag post',
classes: [ 'mt2' ]
},
selected: true
}
]
);
checkbox.classList.add('flex--item');
submit.parentElement?.append(checkbox);

submit.addEventListener('click', async event => {
// find the "Not an answer" flag type
const flagType = Store.flagTypes.find(({ id }) => id === 7);
Expand Down
24 changes: 21 additions & 3 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,28 @@ export async function addProgress(
// indicate loading
toggleLoading(target);

try {
post.progress = new Progress(target);
post.progress.attach();
post.progress = new Progress(target);
post.progress.attach();

const input = document.querySelector<HTMLInputElement>('#advanced-flagging-flag-post');
if (input?.checked) {
const flagProgress = post.progress.addItem('Flagging as NAA...');

try {
await post.flag(FlagNames.NAA, null);
flagProgress.completed();
} catch (error) {
console.error(error);

flagProgress.failed(
error instanceof Error
? error.message
: 'see console for more details'
);
}
}

try {
await post.sendFeedbacks(flagType);
} finally {
// remove previously added indicators
Expand Down

0 comments on commit 099e39e

Please sign in to comment.