Skip to content

Commit 020656f

Browse files
committed
pkp/pkp-lib#11576 Add backoffice UI for comment moderation
1 parent 3035ada commit 020656f

File tree

2 files changed

+57
-39
lines changed

2 files changed

+57
-39
lines changed

src/pages/userComments/userCommentStore.js

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const useUserCommentStore = defineComponentStore(
6262
headerSrOnly: false,
6363
},
6464
{
65-
header: t('manager.userComment.reason'),
65+
header: t('manager.userComment.report.reason'),
6666
headerSrOnly: false,
6767
},
6868
{
@@ -150,12 +150,12 @@ export const useUserCommentStore = defineComponentStore(
150150
label: t('common.delete'),
151151
isWarnable: true,
152152
callback: async (close) => {
153-
const {apiUrl} = useUrl(
154-
`comments/${report.userCommentId}/reports/${report.id}`,
153+
const {isSuccess, fetch: deleteReport} = useFetch(
154+
`${apiUrl.value}/${report.userCommentId}/reports/${report.id}`,
155+
{
156+
method: 'DELETE',
157+
},
155158
);
156-
const {isSuccess, fetch: deleteReport} = useFetch(apiUrl, {
157-
method: 'DELETE',
158-
});
159159

160160
await deleteReport();
161161

@@ -322,9 +322,12 @@ export const useUserCommentStore = defineComponentStore(
322322
label: t('common.delete'),
323323
isWarnable: true,
324324
callback: async (close) => {
325-
const {isSuccess, fetch} = useFetch(apiUrl, {
326-
method: 'DELETE',
327-
});
325+
const {isSuccess, fetch} = useFetch(
326+
`${apiUrl.value}/${comment.id}`,
327+
{
328+
method: 'DELETE',
329+
},
330+
);
328331
await fetch();
329332
if (isSuccess.value) {
330333
pkp.eventBus.$emit(
@@ -348,6 +351,26 @@ export const useUserCommentStore = defineComponentStore(
348351
});
349352
}
350353

354+
/**
355+
* Get the options for comment types(approved, needs approval, reported), to select from to view comments
356+
*/
357+
const commentTypeOptions = computed(() => {
358+
return [
359+
{
360+
label: t('manager.userComment.approved'),
361+
value: 'approved',
362+
},
363+
{
364+
label: t('manager.userComment.needsApproval'),
365+
value: 'needsApproval',
366+
},
367+
{
368+
label: t('manager.userComment.reported'),
369+
value: 'reported',
370+
},
371+
];
372+
});
373+
351374
/**
352375
* Open the report detail modal for a specific report.
353376
* @param {object} report - The report to open in detail view.
@@ -359,6 +382,25 @@ export const useUserCommentStore = defineComponentStore(
359382
comment: comments.value.find((c) => c.id === report.userCommentId),
360383
});
361384
}
385+
386+
/**
387+
* Get the status text for a comment.
388+
* @param comment
389+
* @returns {string}
390+
*/
391+
function getCommentStatusText(comment) {
392+
const status = [];
393+
if (comment.isApproved) {
394+
status.push('Approved');
395+
} else {
396+
status.push('Hidden/Needs Approval');
397+
}
398+
if (comment.isReported) {
399+
status.push('Reported');
400+
}
401+
return status.join(', ');
402+
}
403+
362404
return {
363405
reportDelete,
364406
toggleCommentApproval,
@@ -371,6 +413,7 @@ export const useUserCommentStore = defineComponentStore(
371413
setCurrentReportsPage,
372414
fetchReportsPaginated: fetchCommentReports,
373415
openReport,
416+
getCommentStatusText,
374417
commentApprovalOptions,
375418
selectedCommentStatus,
376419
itemsPerPage,
@@ -380,6 +423,7 @@ export const useUserCommentStore = defineComponentStore(
380423
currentCommentReports,
381424
currentCommentReportsPagination,
382425
reportsTableColumns,
426+
commentTypeOptions,
383427
};
384428
},
385429
);

src/pages/userComments/userCommentsPage.vue

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<template #top-controls>
1010
<FieldSelect
1111
label="Status"
12-
:options="options"
12+
:options="userCommentStore.commentTypeOptions"
1313
primary-locale="en"
1414
size="normal"
1515
:value="userCommentStore.selectedCommentStatus"
@@ -47,7 +47,9 @@
4747
{{ comment.userName }}
4848
</span>
4949
</TableCell>
50-
<TableCell>{{ getStatusText(comment) }}</TableCell>
50+
<TableCell>
51+
{{ userCommentStore.getCommentStatusText(comment) }}
52+
</TableCell>
5153
<TableCell>
5254
<PkpButton
5355
:is-link="true"
@@ -96,32 +98,4 @@ const props = defineProps({
9698
9799
const userCommentStore = useUserCommentStore(props);
98100
const {t} = useLocalize();
99-
100-
const options = [
101-
{
102-
label: t('manager.userComment.approved'),
103-
value: 'approved',
104-
},
105-
{
106-
label: t('manager.userComment.needsApproval'),
107-
value: 'needsApproval',
108-
},
109-
{
110-
label: t('manager.userComment.reported'),
111-
value: 'reported',
112-
},
113-
];
114-
115-
function getStatusText(comment) {
116-
const status = [];
117-
if (comment.isApproved) {
118-
status.push('Approved');
119-
} else {
120-
status.push('Hidden/Needs Approval');
121-
}
122-
if (comment.isReported) {
123-
status.push('Reported');
124-
}
125-
return status.join(', ');
126-
}
127101
</script>

0 commit comments

Comments
 (0)