"use client"; import { useCallback, useState } from "react"; import { toast } from "sonner"; import { api, AdminError, type AdminPost } from "@/lib/api"; import { usePagedList } from "@/lib/use-paged-list"; import { ListShell, EmptyRow } from "@/components/list-shell"; import { Table, THead, TR, TH, TD } from "@/components/ui/table"; import { Button } from "@/components/ui/button"; import { useConfirm } from "@/components/confirm"; import { fmtDate } from "@/lib/utils"; import { Clamp } from "@/components/ui/clamp"; export default function PostsPage() { const [q, setQ] = useState(""); const fetcher = useCallback( (limit: number, offset: number) => api.posts(q, limit, offset), [q], ); const list = usePagedList(fetcher, [q]); const confirm = useConfirm(); async function run(action: Promise, successMsg: string) { try { await action; toast.success(successMsg); list.refresh(); } catch (err) { toast.error(err instanceof AdminError ? err.message : "Action failed."); } } async function onDelete(p: AdminPost) { if ( await confirm({ title: "Delete this post?", message: "It will be removed from the app. You can restore it here later.", confirmLabel: "Delete post", destructive: true, }) ) { run(api.deletePost(p.id), "Post deleted."); } } return ( {list.items.length === 0 && !list.loading ? ( ) : ( list.items.map((p) => ( )) )}
Post Author Engagement Created Actions
{p.caption || "—"}
{p.source_title ? ( {p.source_title} ) : null} {p.deleted_at ? ( Deleted ) : p.is_hidden ? ( Hidden ) : null}
{p.author_name} {`@${p.author_handle}`} {p.likes_count} likes · {p.comments_count} comments {fmtDate(p.created_at)}
{p.deleted_at ? ( ) : ( <> )}
); }