"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { Avatar } from "../../../components/ui/primitives"; import { CONVERSATIONS, THREADS, ageLabel, type Conversation, type FeedItem } from "../../../lib/fixtures"; import { getPlatform, MOCK_COLUMN_DEFS, PLATFORMS } from "../../../lib/platforms"; import { Segmented } from "../../../components/mobile/segmented"; import { SwipeItem } from "../../../components/mobile/swipe-item"; import { ApprovalsSegment } from "../../../components/mobile/approvals-segment"; import { AmplifySheet } from "../../../components/mobile/amplify-sheet"; import { useApiResource } from "../../../lib/use-api"; import type { DraftRecord } from "../../../lib/api-types"; type Segment = "all" | "mentions" | "approvals" | "dms"; type Kind = "spike" | "mention" | "approval" | "reply" | "dm" | "health"; interface NoticeRow { id: string; kind: Kind; text: string; conversation?: Conversation; unread: boolean; } const extra: NoticeRow[] = [ { id: "spike", kind: "spike", text: "Sample spike alert · a post is getting attention", unread: true }, { id: "approval-sample", kind: "approval", text: "Sample draft waiting for review", unread: true }, { id: "health", kind: "health", text: "Facebook connection needs attention", unread: true }, ]; const initial: NoticeRow[] = [...extra, ...CONVERSATIONS.map((conversation, i) => ({ id: `conversation-${conversation.id}`, kind: (i === 0 ? "mention" : i === 1 ? "dm" : "reply") as Kind, text: conversation.preview, conversation, unread: conversation.unread > 0 }))]; const identity = (value: DraftRecord[]): DraftRecord[] => value; const empty: DraftRecord[] = []; const spikePost: FeedItem = { id: -1, platform: MOCK_COLUMN_DEFS[0]?.platformId ?? "unknown", author: "Sample author", handle: "@sample", text: "Sample spike alert post", ageMinutes: 4, likes: 120, reposts: 30, replies: 12, hasMedia: false }; export default function InboxPage({ defaultSegment = "all" }: { defaultSegment?: "all" | "approvals" }): React.ReactElement { const router = useRouter(); const [segment, setSegment] = useState(defaultSegment); const [rows, setRows] = useState(initial); const [backup, setBackup] = useState(null); const [activeId, setActiveId] = useState(CONVERSATIONS[0]?.id ?? 1); const [amplify, setAmplify] = useState(false); const drafts = useApiResource("/publishing/drafts", identity, empty, { state: "in_review", limit: 100 }); const approvals = drafts.data.length; // Fixture rows are only shown while the API is unreachable (sample mode). const sample = drafts.source === "sample"; useEffect(() => { const requested = new URLSearchParams(window.location.search).get("segment"); if (requested === "approvals" || requested === "mentions" || requested === "dms") setSegment(requested); }, []); function change(value: Segment): void { setSegment(value); window.history.replaceState(window.history.state, "", value === "all" ? "/inbox" : `/inbox?segment=${value}`); } function changeRows(update: (current: NoticeRow[]) => NoticeRow[]): void { setBackup(rows); setRows(update); } const visible = sample ? rows.filter((row) => segment === "all" || (segment === "mentions" && row.kind === "mention") || (segment === "dms" && row.kind === "dm")) : []; const selected = CONVERSATIONS.find((conversation) => conversation.id === activeId) ?? CONVERSATIONS[0]; return

Inbox

{sample && }
{backup &&
Inbox updated
}
row.unread).length + approvals }, { value: "mentions", label: "Mentions", count: visible.filter((row) => row.unread && row.kind === "mention").length }, { value: "approvals", label: "Approvals", count: approvals }, { value: "dms", label: "DMs", count: visible.filter((row) => row.unread && row.kind === "dm").length }]} value={segment} onChange={change} />
{segment === "approvals" ? :
{visible.map((row) => changeRows((current) => current.filter((item) => item.id !== row.id)) }]} rightActions={row.kind === "mention" || row.kind === "dm" ? [{ label: "Reply", onClick: () => { if (row.conversation) router.push(`/inbox/${row.conversation.id}`); } }] : []}>
{row.conversation ? : {row.kind === "spike" ? "↗" : "!"}}
{row.kind}sample{row.conversation && {row.conversation.participant}}{row.conversation && {ageLabel(row.conversation.lastMinutes)}}

{row.text}

{row.conversation && }{row.kind === "spike" && }{row.kind === "approval" && }{row.kind === "health" && }
)} {!sample && segment === "all" &&

No messages yet — direct messages arrive when connector messaging support lands.

}
}
{segment === "approvals" ?
: sample ? <>
{selected?.participant} · {PLATFORMS[selected?.platform ?? ""]?.displayName}
{(THREADS[selected?.id ?? 1] ?? []).map((message, index) =>

{message.text}

)}

Sample thread · replies await connector messaging support.

:
Inbox
No messages yet — direct messages arrive when connector messaging support lands.
} setAmplify(false)} />
; }