'use client' import { useState, useEffect, useCallback } from 'react' import { Globe, ExternalLink, Trash2, Loader2, Copy, Check } from 'lucide-react' import { toast } from 'sonner' import { useLanguage } from '@/lib/i18n' interface PublishedNote { id: string title: string | null publicSlug: string | null publishedAt: string | null } export default function UserPublishedPage() { const { t } = useLanguage() const [notes, setNotes] = useState([]) const [loading, setLoading] = useState(true) const [copiedId, setCopiedId] = useState(null) const load = useCallback(async () => { setLoading(true) try { const res = await fetch('/api/user/published') const data = await res.json() setNotes(data.notes || []) } catch { toast.error('Erreur') } finally { setLoading(false) } }, []) useEffect(() => { load() }, [load]) const unpublish = async (noteId: string) => { try { const res = await fetch('/api/notes/publish', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ noteId, action: 'unpublish' }), }) if (res.ok) { toast.success(t('richTextEditor.unpublishSuccess') || 'Note dépubliée'); load() } else { toast.error('Erreur') } } catch { toast.error('Erreur') } } const copyLink = (slug: string, noteId: string) => { const url = `${window.location.origin}/p/${slug}` navigator.clipboard?.writeText(url).then(() => { setCopiedId(noteId); setTimeout(() => setCopiedId(null), 2000); toast.success('Lien copié !') }).catch(() => { const el = document.createElement('textarea'); el.value = url; document.body.appendChild(el); el.select() document.execCommand('copy'); document.body.removeChild(el) setCopiedId(noteId); setTimeout(() => setCopiedId(null), 2000); toast.success('Lien copié !') }) } return (

{t('settings.publishedTitle') || 'Mes pages publiées'}

{t('settings.publishedDesc') || 'Gérez les notes que vous avez publiées publiquement.'}

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

{t('settings.publishedEmpty') || 'Aucune note publiée pour le moment.'}

) : (
{notes.map(note => (
{note.title || 'Sans titre'}
{note.publishedAt ? new Date(note.publishedAt).toLocaleDateString() : ''}
))}
)}
) }