Open platform to collect and prioritize feedback
Some more WIP towards an admin page for the moderation stuff.
Matt Roberts9b0a2b99012b
diff --git a/public/pages/Administration/pages/ContentModeration.page.scss b/public/pages/Administration/pages/ContentModeration.page.scssnew file mode 100644index 000000000..326f0a2dc--- /dev/null+++ b/public/pages/Administration/pages/ContentModeration.page.scss@@ -0,0 +1,126 @@+@use "~@fider/assets/styles/variables.scss" as *;++#p-admin-moderation {+ .page-title {+ font-size: 1.5rem;+ font-weight: 600;+ margin-bottom: 1.5rem;++ .page-subtitle {+ display: block;+ font-size: 1rem;+ font-weight: normal;+ color: var(--colors-gray-600);+ margin-top: 0.25rem;+ }+ }+}++.c-moderation-page {+ width: 100%;++ &__empty {+ text-align: center;+ padding: 2rem;+ background-color: var(--colors-gray-50);+ border-radius: 0.25rem;+ margin-top: 1rem;+ }++ &__content {+ margin-top: 1rem;+ }+}++.c-moderation-section {+ margin-bottom: 2rem;++ &__title {+ font-size: 1.25rem;+ font-weight: 600;+ margin-bottom: 1rem;+ padding-bottom: 0.5rem;+ border-bottom: 1px solid var(--colors-gray-200);+ }++ &__items {+ display: flex;+ flex-direction: column;+ gap: 0.5rem;+ }+}++.c-moderation-item {+ display: flex;+ flex-direction: column;+ border: 1px solid var(--colors-gray-200);+ border-radius: 0.25rem;+ overflow: hidden;+ transition: background-color 0.2s ease;++ &:hover {+ background-color: rgba(var(--colors-blue-100-rgb), 0.5);+ }++ &__content {+ padding: 1rem;+ }++ &__header {+ margin-bottom: 0.75rem;+ }++ &__user {+ font-weight: 500;+ }++ &__body {+ margin-left: 2.5rem;+ }++ &__title {+ font-size: 1.125rem;+ font-weight: 600;+ margin: 0;+ }++ &__text {+ margin: 0;+ color: var(--colors-gray-700);+ word-break: break-word;+ }++ &__post-reference {+ font-size: 0.875rem;+ color: var(--colors-gray-600);++ a {+ color: var(--colors-blue-700);+ text-decoration: none;++ &:hover {+ text-decoration: underline;+ }+ }+ }++ &__actions {+ display: none;+ padding: 0.75rem 1rem;+ background-color: var(--colors-gray-50);+ border-top: 1px solid var(--colors-gray-200);++ .c-moderation-item:hover & {+ display: block;+ }+ }+}++// Responsive adjustments+@media (max-width: 768px) {+ .c-moderation-item {+ &__actions {+ display: block; // Always show actions on mobile+ }+ }+}diff --git a/public/pages/Administration/pages/ContentModeration.page.tsx b/public/pages/Administration/pages/ContentModeration.page.tsxindex 7e0073a39..70f089fa3 100644--- a/public/pages/Administration/pages/ContentModeration.page.tsx+++ b/public/pages/Administration/pages/ContentModeration.page.tsx@@ -1,9 +1,318 @@-import React from "react"+import "./ContentModeration.page.scss"-interface ContentModerationPageProps {- // Define props here+import React, { useState, useEffect } from "react"+import { Button, Avatar, Loader, Icon } from "@fider/components/common"+import { Header } from "@fider/components"+import { HStack, VStack } from "@fider/components/layout"+import { actions, http, notify } from "@fider/services"+import { User } from "@fider/models"+import { useFider } from "@fider/hooks"+import { Trans } from "@lingui/react/macro"+import IconCheck from "@fider/assets/images/heroicons-check.svg"+import IconX from "@fider/assets/images/heroicons-x.svg"+import IconShieldCheck from "@fider/assets/images/heroicons-shieldcheck.svg"+import IconBan from "@fider/assets/images/heroicons-x-circle.svg"+import { Moment } from "@fider/components/common"++interface ModerationItem {+ type: "post" | "comment"+ id: number+ postId?: number+ postNumber?: number+ postSlug?: string+ title?: string+ content: string+ user: User+ createdAt: string+ postTitle?: string+}++interface ContentModerationPageState {+ items: ModerationItem[]+ loading: boolean}-export default function ContentModerationPage(props: ContentModerationPageProps) {- return <div>Content Moderation Page</div>+const ContentModerationPage = () => {+ const [state, setState] = useState<ContentModerationPageState>({+ items: [],+ loading: true,+ })+ const fider = useFider()++ const fetchItems = async () => {+ setState((prev) => ({ ...prev, loading: true }))+ const result = await http.get<{ items: ModerationItem[] }>("/_api/admin/moderation/items")+ if (result.ok) {+ setState({ items: result.data.items, loading: false })+ } else {+ setState((prev) => ({ ...prev, loading: false }))+ notify.error(<Trans id="moderation.fetch.error">Failed to fetch moderation items</Trans>)+ }+ }++ useEffect(() => {+ fetchItems()+ }, [])++ const handleApprovePost = async (postId: number) => {+ const result = await actions.approvePost(postId)+ if (result.ok) {+ notify.success(<Trans id="moderation.post.approved">Post approved successfully</Trans>)+ setState((prev) => ({+ ...prev,+ items: prev.items.filter((item) => !(item.type === "post" && item.id === postId)),+ }))+ } else {+ notify.error(<Trans id="moderation.post.approve.error">Failed to approve post</Trans>)+ }+ }++ const handleDeclinePost = async (postId: number) => {+ const result = await actions.declinePost(postId)+ if (result.ok) {+ notify.success(<Trans id="moderation.post.declined">Post declined successfully</Trans>)+ setState((prev) => ({+ ...prev,+ items: prev.items.filter((item) => !(item.type === "post" && item.id === postId)),+ }))+ } else {+ notify.error(<Trans id="moderation.post.decline.error">Failed to decline post</Trans>)+ }+ }++ const handleApproveComment = async (commentId: number) => {+ const result = await actions.approveComment(commentId)+ if (result.ok) {+ notify.success(<Trans id="moderation.comment.approved">Comment approved successfully</Trans>)+ setState((prev) => ({+ ...prev,+ items: prev.items.filter((item) => !(item.type === "comment" && item.id === commentId)),+ }))+ } else {+ notify.error(<Trans id="moderation.comment.approve.error">Failed to approve comment</Trans>)+ }+ }++ const handleDeclineComment = async (commentId: number) => {+ const result = await actions.declineComment(commentId)+ if (result.ok) {+ notify.success(<Trans id="moderation.comment.declined">Comment declined successfully</Trans>)+ setState((prev) => ({+ ...prev,+ items: prev.items.filter((item) => !(item.type === "comment" && item.id === commentId)),+ }))+ } else {+ notify.error(<Trans id="moderation.comment.decline.error">Failed to decline comment</Trans>)+ }+ }++ const handleApprovePostAndVerify = async (postId: number) => {+ const result = await http.post(`/api/v1/admin/moderation/posts/${postId}/approve-and-verify`)+ if (result.ok) {+ notify.success(<Trans id="moderation.post.approved.verified">Post approved and user verified</Trans>)+ setState((prev) => ({+ ...prev,+ items: prev.items.filter((item) => !(item.type === "post" && item.id === postId)),+ }))+ } else {+ notify.error(<Trans id="moderation.post.approve.verify.error">Failed to approve post and verify user</Trans>)+ }+ }++ const handleDeclinePostAndBlock = async (postId: number) => {+ const result = await http.post(`/api/v1/admin/moderation/posts/${postId}/decline-and-block`)+ if (result.ok) {+ notify.success(<Trans id="moderation.post.declined.blocked">Post declined and user blocked</Trans>)+ setState((prev) => ({+ ...prev,+ items: prev.items.filter((item) => !(item.type === "post" && item.id === postId)),+ }))+ } else {+ notify.error(<Trans id="moderation.post.decline.block.error">Failed to decline post and block user</Trans>)+ }+ }++ const handleApproveCommentAndVerify = async (commentId: number) => {+ const result = await http.post(`/api/v1/admin/moderation/comments/${commentId}/approve-and-verify`)+ if (result.ok) {+ notify.success(<Trans id="moderation.comment.approved.verified">Comment approved and user verified</Trans>)+ setState((prev) => ({+ ...prev,+ items: prev.items.filter((item) => !(item.type === "comment" && item.id === commentId)),+ }))+ } else {+ notify.error(<Trans id="moderation.comment.approve.verify.error">Failed to approve comment and verify user</Trans>)+ }+ }++ const handleDeclineCommentAndBlock = async (commentId: number) => {+ const result = await http.post(`/api/v1/admin/moderation/comments/${commentId}/decline-and-block`)+ if (result.ok) {+ notify.success(<Trans id="moderation.comment.declined.blocked">Comment declined and user blocked</Trans>)+ setState((prev) => ({+ ...prev,+ items: prev.items.filter((item) => !(item.type === "comment" && item.id === commentId)),+ }))+ } else {+ notify.error(<Trans id="moderation.comment.decline.block.error">Failed to decline comment and block user</Trans>)+ }+ }++ const renderDivider = (title: string, count: number) => {+ return (+ <HStack spacing={2} className="py-4 w-full">+ <div className="text-blue-500 text-title">+ {title} ({count})+ </div>+ <hr className="border-blue-500 flex-grow"></hr>+ </HStack>+ )+ }++ const renderModerationItem = (item: ModerationItem) => {+ return (+ <div key={`${item.type}-${item.id}`} className="c-moderation-item">+ <div className="c-moderation-item__content">+ <HStack spacing={4} className="c-moderation-item__header">+ <Avatar user={item.user} />+ <VStack spacing={0}>+ <span className="c-moderation-item__user">{item.user.name}</span>+ <Moment date={item.createdAt} locale={fider.currentLocale} />+ </VStack>+ </HStack>++ {item.type === "post" && (+ <VStack spacing={2} className="c-moderation-item__body">+ <h3 className="c-moderation-item__title">{item.title}</h3>+ <p className="c-moderation-item__text">{item.content}</p>+ </VStack>+ )}++ {item.type === "comment" && (+ <VStack spacing={2} className="c-moderation-item__body">+ <span className="c-moderation-item__post-reference">+ <Trans id="moderation.comment.on">+ On post: <a href={`/posts/${item.postNumber}/${item.postSlug}`}>{item.postTitle}</a>+ </Trans>+ </span>+ <p className="c-moderation-item__text">{item.content}</p>+ </VStack>+ )}+ </div>++ <div className="c-moderation-item__actions">+ <HStack spacing={2}>+ {item.type === "post" && (+ <>+ <Button size="small" variant="primary" onClick={() => handleApprovePost(item.id)}>+ <Icon sprite={IconCheck} />+ <span>+ <Trans id="action.approve">Approve</Trans>+ </span>+ </Button>+ <Button size="small" variant="danger" onClick={() => handleDeclinePost(item.id)}>+ <Icon sprite={IconX} />+ <span>+ <Trans id="action.decline">Decline</Trans>+ </span>+ </Button>+ <Button size="small" variant="secondary" onClick={() => handleApprovePostAndVerify(item.id)}>+ <Icon sprite={IconShieldCheck} />+ <span>+ <Trans id="action.approve.verify">Approve & Verify</Trans>+ </span>+ </Button>+ <Button size="small" variant="danger" onClick={() => handleDeclinePostAndBlock(item.id)}>+ <Icon sprite={IconBan} />+ <span>+ <Trans id="action.decline.block">Decline & Block</Trans>+ </span>+ </Button>+ </>+ )}++ {item.type === "comment" && (+ <>+ <Button size="small" variant="primary" onClick={() => handleApproveComment(item.id)}>+ <Icon sprite={IconCheck} />+ <span>+ <Trans id="action.approve">Approve</Trans>+ </span>+ </Button>+ <Button size="small" variant="danger" onClick={() => handleDeclineComment(item.id)}>+ <Icon sprite={IconX} />+ <span>+ <Trans id="action.decline">Decline</Trans>+ </span>+ </Button>+ <Button size="small" variant="secondary" onClick={() => handleApproveCommentAndVerify(item.id)}>+ <Icon sprite={IconShieldCheck} />+ <span>+ <Trans id="action.approve.verify">Approve & Verify</Trans>+ </span>+ </Button>+ <Button size="small" variant="danger" onClick={() => handleDeclineCommentAndBlock(item.id)}>+ <Icon sprite={IconBan} />+ <span>+ <Trans id="action.decline.block">Decline & Block</Trans>+ </span>+ </Button>+ </>+ )}+ </HStack>+ </div>+ </div>+ )+ }++ const posts = state.items.filter((item) => item.type === "post")+ const comments = state.items.filter((item) => item.type === "comment")++ return (+ <>+ <Header />+ <div id="p-admin-moderation" className="page container">+ <h1 className="text-large">+ <Trans id="moderation.title">Moderation Queue</Trans>+ </h1>+ <p className="text-body text-lg mt-3">+ <Trans id="moderation.subtitle">These posts and comments are from people outside of your trusted users list, you decide if they get published.</Trans>+ </p>++ <div className="c-moderation-page">+ {state.loading ? (+ <Loader />+ ) : state.items.length === 0 ? (+ <div className="c-moderation-page__empty">+ <p>+ <Trans id="moderation.empty">All content has been moderated. You're all caught up!</Trans>+ </p>+ </div>+ ) : (+ <div className="c-moderation-page__content">+ {posts.length > 0 && (+ <>+ {renderDivider("New ideas", posts.length)}+ <div className="c-moderation-section">+ <div className="c-moderation-section__items">{posts.map(renderModerationItem)}</div>+ </div>+ </>+ )}++ {comments.length > 0 && (+ <div className="c-moderation-section">+ <h2 className="c-moderation-section__title">+ <Trans id="moderation.section.comments">New comments</Trans> ({comments.length})+ </h2>+ <div className="c-moderation-section__items">{comments.map(renderModerationItem)}</div>+ </div>+ )}+ </div>+ )}+ </div>+ </div>+ </>+ )}++export default ContentModerationPagediff --git a/public/pages/Administration/pages/Moderation.page.tsx b/public/pages/Administration/pages/Moderation.page.tsxdeleted file mode 100644index 629ca7aba..000000000--- a/public/pages/Administration/pages/Moderation.page.tsx+++ /dev/null@@ -1,388 +0,0 @@-import React from "react"-import { Button, Loader } from "@fider/components"-import { actions, notify, Fider } from "@fider/services"-import { AdminBasePage } from "@fider/pages/Administration/components/AdminBasePage"-import { HStack, VStack } from "@fider/components/layout"--interface ModerationItem {- id: number- type: "post" | "comment"- title?: string- content: string- user: {- id: number- name: string- email: string- }- createdAt: string- postId?: number- postNumber?: number- postSlug?: string- postTitle?: string-}--interface ModerationPageState {- items: ModerationItem[]- loading: boolean- selectedItems: Set<string>- selectAll: boolean-}--export default class ModerationPage extends AdminBasePage<any, ModerationPageState> {- public id = "p-admin-moderation"- public name = "moderation"- public title = "Moderation"- public subtitle = "Review and approve content"-- constructor(props: any) {- super(props)-- this.state = {- items: [],- loading: true,- selectedItems: new Set(),- selectAll: false,- }- }-- public async componentDidMount() {- await this.loadModerationItems()- }-- private loadModerationItems = async () => {- this.setState({ loading: true })- try {- const response = await fetch("/_api/admin/moderation/items")- if (response.ok) {- const data = await response.json()- this.setState({ items: data.items || [], loading: false })- } else {- notify.error("Failed to load moderation items")- this.setState({ loading: false })- }- } catch (error) {- notify.error("Failed to load moderation items")- this.setState({ loading: false })- }- }-- private handleSelectItem = (itemKey: string, checked: boolean) => {- const selectedItems = new Set(this.state.selectedItems)- if (checked) {- selectedItems.add(itemKey)- } else {- selectedItems.delete(itemKey)- }-- const selectAll = selectedItems.size === this.state.items.length- this.setState({ selectedItems, selectAll })- }-- private handleSelectAll = (checked: boolean) => {- if (checked) {- const selectedItems = new Set(this.state.items.map(item => `${item.type}-${item.id}`))- this.setState({ selectedItems, selectAll: true })- } else {- this.setState({ selectedItems: new Set(), selectAll: false })- }- }-- private bulkApprove = async () => {- const { selectedItems } = this.state- if (selectedItems.size === 0) {- notify.error("Please select items to approve")- return- }-- const postIDs: number[] = []- const commentIDs: number[] = []-- selectedItems.forEach(itemKey => {- const [type, id] = itemKey.split('-')- if (type === 'post') {- postIDs.push(parseInt(id))- } else if (type === 'comment') {- commentIDs.push(parseInt(id))- }- })-- try {- const response = await actions.bulkApproveItems(postIDs, commentIDs)- if (response.ok) {- notify.success(`Approved ${selectedItems.size} item(s) successfully`)- await this.loadModerationItems()- this.setState({ selectedItems: new Set(), selectAll: false })- } else {- notify.error("Failed to approve items")- }- } catch (error) {- notify.error("Failed to approve items")- }- }-- private bulkDecline = async () => {- const { selectedItems } = this.state- if (selectedItems.size === 0) {- notify.error("Please select items to decline")- return- }-- if (!confirm(`Are you sure you want to decline ${selectedItems.size} item(s)? This action cannot be undone.`)) {- return- }-- const postIDs: number[] = []- const commentIDs: number[] = []-- selectedItems.forEach(itemKey => {- const [type, id] = itemKey.split('-')- if (type === 'post') {- postIDs.push(parseInt(id))- } else if (type === 'comment') {- commentIDs.push(parseInt(id))- }- })-- try {- const response = await actions.bulkDeclineItems(postIDs, commentIDs)- if (response.ok) {- notify.success(`Declined ${selectedItems.size} item(s) successfully`)- await this.loadModerationItems()- this.setState({ selectedItems: new Set(), selectAll: false })- } else {- notify.error("Failed to decline items")- }- } catch (error) {- notify.error("Failed to decline items")- }- }-- private approveItem = async (item: ModerationItem) => {- try {- let response- if (item.type === 'post') {- response = await actions.approvePost(item.id)- } else {- response = await actions.approveComment(item.id)- }-- if (response.ok) {- notify.success(`${item.type === 'post' ? 'Post' : 'Comment'} approved successfully`)- await this.loadModerationItems()- } else {- notify.error(`Failed to approve ${item.type}`)- }- } catch (error) {- notify.error(`Failed to approve ${item.type}`)- }- }-- private declineItem = async (item: ModerationItem) => {- if (!confirm(`Are you sure you want to decline this ${item.type}? This action cannot be undone.`)) {- return- }-- try {- let response- if (item.type === 'post') {- response = await actions.declinePost(item.id)- } else {- response = await actions.declineComment(item.id)- }-- if (response.ok) {- notify.success(`${item.type === 'post' ? 'Post' : 'Comment'} declined successfully`)- await this.loadModerationItems()- } else {- notify.error(`Failed to decline ${item.type}`)- }- } catch (error) {- notify.error(`Failed to decline ${item.type}`)- }- }-- private formatDate = (dateString: string) => {- return new Date(dateString).toLocaleDateString('en-US', {- year: 'numeric',- month: 'short',- day: 'numeric',- hour: '2-digit',- minute: '2-digit'- })- }-- public content() {- const { items, loading, selectedItems, selectAll } = this.state-- if (!Fider.session.tenant.isModerationEnabled) {- return (- <div className="p-4 bg-blue-50 rounded border-l-4 border-blue-500">- <p className="text-blue-800">- Content moderation is currently disabled for this site. You can enable it in the{" "}- <a href="/admin/privacy" className="text-blue-600 underline">Privacy Settings</a>.- </p>- </div>- )- }-- if (loading) {- return <Loader />- }-- if (items.length === 0) {- return (- <div className="text-center py-8">- <h3 className="text-lg font-medium text-gray-900 mb-2">No pending items</h3>- <p className="text-gray-600">All content has been moderated.</p>- </div>- )- }-- return (- <VStack spacing={4}>- <div className="flex justify-between items-center">- <h3 className="text-lg font-medium">- {items.length} item(s) awaiting moderation- </h3>- <HStack spacing={2}>- <Button- variant="primary"- size="small"- onClick={this.bulkApprove}- disabled={selectedItems.size === 0}- >- Approve Selected ({selectedItems.size})- </Button>- <Button- variant="danger"- size="small"- onClick={this.bulkDecline}- disabled={selectedItems.size === 0}- >- Decline Selected ({selectedItems.size})- </Button>- </HStack>- </div>-- <div className="bg-white shadow rounded-lg overflow-hidden">- <table className="min-w-full divide-y divide-gray-200">- <thead className="bg-gray-50">- <tr>- <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">- <input- type="checkbox"- checked={selectAll}- onChange={(e) => this.handleSelectAll(e.target.checked)}- className="rounded border-gray-300"- />- </th>- <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">- Type- </th>- <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">- Content- </th>- <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">- Author- </th>- <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">- Created- </th>- <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">- Actions- </th>- </tr>- </thead>- <tbody className="bg-white divide-y divide-gray-200">- {items.map((item) => {- const itemKey = `${item.type}-${item.id}`- const isSelected = selectedItems.has(itemKey)-- return (- <tr key={itemKey} className={isSelected ? "bg-blue-50" : ""}>- <td className="px-4 py-4 whitespace-nowrap">- <input- type="checkbox"- checked={isSelected}- onChange={(e) => this.handleSelectItem(itemKey, e.target.checked)}- className="rounded border-gray-300"- />- </td>- <td className="px-4 py-4 whitespace-nowrap">- <span className={`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${- item.type === 'post'- ? 'bg-green-100 text-green-800'- : 'bg-blue-100 text-blue-800'- }`}>- {item.type === 'post' ? 'Post' : 'Comment'}- </span>- </td>- <td className="px-4 py-4">- <div className="max-w-xs">- <div className="font-medium text-gray-900 truncate">- {item.title || (item.type === 'comment' ? 'Comment' : 'Post')}- </div>- <div className="text-sm text-gray-500 truncate">- {item.content}- </div>- {item.type === 'comment' && item.postTitle && (- <div className="text-xs text-gray-400 truncate">- on: {item.postTitle}- </div>- )}- </div>- </td>- <td className="px-4 py-4 whitespace-nowrap text-sm text-gray-900">- {item.user.name}- </td>- <td className="px-4 py-4 whitespace-nowrap text-sm text-gray-500">- {this.formatDate(item.createdAt)}- </td>- <td className="px-4 py-4 whitespace-nowrap text-sm">- <HStack spacing={1}>- <Button- variant="primary"- size="small"- onClick={() => this.approveItem(item)}- >- Approve- </Button>- <Button- variant="danger"- size="small"- onClick={() => this.declineItem(item)}- >- Decline- </Button>- {item.type === 'post' && item.postNumber && item.postSlug && (- <a- href={`/posts/${item.postNumber}/${item.postSlug}`}- target="_blank"- rel="noopener noreferrer"- className="text-blue-600 hover:text-blue-800 text-xs"- >- View- </a>- )}- {item.type === 'comment' && item.postNumber && item.postSlug && (- <a- href={`/posts/${item.postNumber}/${item.postSlug}#comment-${item.id}`}- target="_blank"- rel="noopener noreferrer"- className="text-blue-600 hover:text-blue-800 text-xs"- >- View- </a>- )}- </HStack>- </td>- </tr>- )- })}- </tbody>- </table>- </div>- </VStack>- )- }-}\ No newline at end of file