'use client' import { useState, useEffect, useCallback } from 'react' import { Globe, Eye, Trash2, ExternalLink, Loader2, Shield, ShieldAlert } from 'lucide-react' import { toast } from 'sonner' interface PublishedNote { id: string title: string | null publicSlug: string | null publishedAt: string | null user: { name: string | null } _count?: { reports: number } } export default function PublishedAdminPage() { const [notes, setNotes] = useState([]) const [loading, setLoading] = useState(true) const load = useCallback(async () => { setLoading(true) try { const res = await fetch('/api/admin/published') const data = await res.json() setNotes(data.notes || []) } catch { toast.error('Erreur') } finally { setLoading(false) } }, []) useEffect(() => { load() }, [load]) const forceUnpublish = async (noteId: string) => { try { const res = await fetch('/api/admin/published', { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ noteId }), }) if (res.ok) { toast.success('Note dépubliée') load() } else { toast.error('Erreur') } } catch { toast.error('Erreur') } } return (

Pages publiées

({notes.length})
{loading ? (
) : notes.length === 0 ? (

Aucune note publiée.

) : (
{notes.map(note => (
{note.title || 'Sans titre'}
par {note.user?.name || 'Inconnu'} · {note.publishedAt ? new Date(note.publishedAt).toLocaleDateString() : ''} {note._count?.reports ? ( {note._count.reports} signalement{note._count.reports > 1 ? 's' : ''} ) : null}
))}
)}
) }