Foro: restaurar posts y temas borrados (moderadores)
- lib/forum.ts: getTopic/getPosts/countPosts aceptan includeDeleted (mods ven lo borrado); Post.deleted y TopicFull.deleted. - API: PUT /api/forum/post restaura post (mod-only); moderate action 'restore' restaura tema (usa includeDeleted al leer el tema). - UI: posts borrados atenuados con badge y botón Restaurar (PostActions); TopicModBar muestra banner + Restaurar tema cuando el tema está borrado. - i18n es/en: Forum.restore, restoreTopic, deletedMark. Verificado: build OK, PUT post y moderate restore 401 sin sesión, /forum 200. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,15 @@ import { useTranslations } from 'next-intl'
|
||||
import { useRouter } from '@/i18n/navigation'
|
||||
import { RichTextArea } from './RichTextArea'
|
||||
|
||||
export function PostActions({ postId, initialText }: { postId: number; initialText: string }) {
|
||||
export function PostActions({
|
||||
postId,
|
||||
initialText,
|
||||
deleted = false,
|
||||
}: {
|
||||
postId: number
|
||||
initialText: string
|
||||
deleted?: boolean
|
||||
}) {
|
||||
const t = useTranslations('Forum')
|
||||
const router = useRouter()
|
||||
const [editing, setEditing] = useState(false)
|
||||
@@ -38,6 +46,26 @@ export function PostActions({ postId, initialText }: { postId: number; initialTe
|
||||
}
|
||||
}
|
||||
|
||||
async function restore() {
|
||||
if (busy) return
|
||||
setBusy(true)
|
||||
setError(null)
|
||||
try {
|
||||
const res = await fetch('/api/forum/post', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({ postId }),
|
||||
})
|
||||
if ((await res.json()).success) router.refresh()
|
||||
else setError(t('genericError'))
|
||||
} catch {
|
||||
setError(t('genericError'))
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function remove() {
|
||||
if (busy || !confirm(t('confirmDeletePost'))) return
|
||||
setBusy(true)
|
||||
@@ -80,6 +108,17 @@ export function PostActions({ postId, initialText }: { postId: number; initialTe
|
||||
)
|
||||
}
|
||||
|
||||
if (deleted) {
|
||||
return (
|
||||
<div className="mt-2 flex items-center gap-3 text-xs">
|
||||
<button type="button" onClick={restore} disabled={busy} className="text-green-400 hover:text-green-300 disabled:opacity-60">
|
||||
{t('restore')}
|
||||
</button>
|
||||
{error && <span className="text-red-400">{error}</span>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mt-2 flex items-center gap-3 text-xs">
|
||||
<button type="button" onClick={() => setEditing(true)} className="text-nw-muted hover:text-nw-gold-light">
|
||||
|
||||
@@ -8,11 +8,13 @@ export function TopicModBar({
|
||||
topicId,
|
||||
locked,
|
||||
sticky,
|
||||
deleted = false,
|
||||
moveForums = [],
|
||||
}: {
|
||||
topicId: number
|
||||
locked: boolean
|
||||
sticky: boolean
|
||||
deleted?: boolean
|
||||
moveForums?: { id: number; name: string }[]
|
||||
}) {
|
||||
const t = useTranslations('Forum')
|
||||
@@ -43,6 +45,22 @@ export function TopicModBar({
|
||||
}
|
||||
}
|
||||
|
||||
if (deleted) {
|
||||
return (
|
||||
<div className="mb-6 flex flex-wrap items-center gap-2 rounded-lg border border-red-900/60 bg-red-950/20 px-3 py-2 text-sm">
|
||||
<span className="mr-1 font-semibold text-red-400">{t('deletedMark')}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => act('restore')}
|
||||
disabled={busy}
|
||||
className="text-xs text-green-400 hover:text-green-300 disabled:opacity-60"
|
||||
>
|
||||
{t('restoreTopic')}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mb-6 flex flex-wrap items-center gap-2 rounded-lg border border-nw-border/60 bg-nw-panel-2/40 px-3 py-2 text-sm">
|
||||
<span className="mr-1 font-semibold text-nw-gold-light">{t('moderation')}:</span>
|
||||
|
||||
Reference in New Issue
Block a user