"use client"; import { useEffect, useState } from "react"; import { api } from "@/lib/api"; import { cn } from "@/lib/utils"; import { formatDate } from "@/lib/utils"; import { EyeOff, UserX, Undo2, Plus } from "lucide-react"; type Tab = "hidden" | "blocked"; export default function ModerationPage() { const [tab, setTab] = useState("hidden"); const [hiddenContent, setHiddenContent] = useState([]); const [blockedPubkeys, setBlockedPubkeys] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); const [hideEventId, setHideEventId] = useState(""); const [hideReason, setHideReason] = useState(""); const [blockPubkey, setBlockPubkey] = useState(""); const [blockReason, setBlockReason] = useState(""); const loadData = async () => { try { const [h, b] = await Promise.all([ api.getHiddenContent(), api.getBlockedPubkeys(), ]); setHiddenContent(h); setBlockedPubkeys(b); } catch (err: any) { setError(err.message); } finally { setLoading(false); } }; useEffect(() => { loadData(); }, []); const handleHide = async () => { if (!hideEventId.trim()) return; setError(""); try { await api.hideContent(hideEventId, hideReason || undefined); setHideEventId(""); setHideReason(""); await loadData(); } catch (err: any) { setError(err.message); } }; const handleUnhide = async (id: string) => { try { await api.unhideContent(id); await loadData(); } catch (err: any) { setError(err.message); } }; const handleBlock = async () => { if (!blockPubkey.trim()) return; setError(""); try { await api.blockPubkey(blockPubkey, blockReason || undefined); setBlockPubkey(""); setBlockReason(""); await loadData(); } catch (err: any) { setError(err.message); } }; const handleUnblock = async (id: string) => { try { await api.unblockPubkey(id); await loadData(); } catch (err: any) { setError(err.message); } }; if (loading) { return (
Loading moderation data...
); } return (

Moderation

{error &&

{error}

}
{tab === "hidden" && (

Hide Content

setHideEventId(e.target.value)} className="bg-surface-container-highest text-on-surface rounded-lg px-4 py-3 w-full focus:outline-none focus:ring-1 focus:ring-primary/40 flex-1" /> setHideReason(e.target.value)} className="bg-surface-container-highest text-on-surface rounded-lg px-4 py-3 w-full focus:outline-none focus:ring-1 focus:ring-primary/40 flex-1" />
{hiddenContent.length === 0 ? (

No hidden content.

) : ( hiddenContent.map((item) => (

{item.nostrEventId?.slice(0, 16)}...

{item.reason && (

{item.reason}

)} {item.createdAt && (

{formatDate(item.createdAt)}

)}
)) )}
)} {tab === "blocked" && (

Block Pubkey

setBlockPubkey(e.target.value)} className="bg-surface-container-highest text-on-surface rounded-lg px-4 py-3 w-full focus:outline-none focus:ring-1 focus:ring-primary/40 flex-1" /> setBlockReason(e.target.value)} className="bg-surface-container-highest text-on-surface rounded-lg px-4 py-3 w-full focus:outline-none focus:ring-1 focus:ring-primary/40 flex-1" />
{blockedPubkeys.length === 0 ? (

No blocked pubkeys.

) : ( blockedPubkeys.map((item) => (

{item.pubkey?.slice(0, 16)}...{item.pubkey?.slice(-8)}

{item.reason && (

{item.reason}

)} {item.createdAt && (

{formatDate(item.createdAt)}

)}
)) )}
)}
); }