import { useCallback, useEffect, useMemo, useState } from "react"; import { EyeOff, Eye, MessageCircle, RefreshCw, Send } from "lucide-react"; import { api } from "../api.js"; import { Badge, Button, cx, Empty, ErrorNote, Panel, Spinner, timeAgo } from "../ui.jsx"; export default function Inbox() { const [clients, setClients] = useState([]); const [client, setClient] = useState(""); const [days, setDays] = useState(14); const [items, setItems] = useState(null); const [view, setView] = useState("unreplied"); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); useEffect(() => { api("/api/overview").then((r) => { const l = r.clients.filter((c) => c.linked); setClients(l); setClient((c) => c || l[0]?.slug || ""); }).catch(setError); }, []); const load = useCallback(() => { if (!client) return; setLoading(true); setError(null); api(`/api/inbox?client=${client}&days=${days}`).then((r) => setItems(r.comments)).catch((e) => { setError(e); setItems([]); }).finally(() => setLoading(false)); }, [client, days]); useEffect(() => { setItems(null); load(); }, [load]); const shown = useMemo(() => (items || []).filter((c) => view === "all" || (view === "unreplied" ? !c.replied && !c.hidden : c.hidden)), [items, view]); const open = (items || []).filter((c) => !c.replied && !c.hidden).length; const patch = (id, p) => setItems((xs) => xs.map((x) => (x.id === id ? { ...x, ...p } : x))); return (

Inbox

Comments on Instagram and Facebook posts. Reply within a few hours; it helps reach.

{[["unreplied", `Needs reply${items ? ` (${open})` : ""}`], ["all", "All"], ["hidden", "Hidden"]].map(([k, l]) => ( ))}
{items === null ? : !shown.length ? ( No comments in this view for the selected period. ) : (
    {shown.map((c) => patch(c.id, p)} />)}
)}
); } function Row({ c, client, onChange }) { const [text, setText] = useState(""); const [busy, setBusy] = useState(null); const [error, setError] = useState(null); const send = async () => { setBusy("reply"); setError(null); try { await api("/api/inbox/reply", { method: "POST", body: { client, platform: c.platform, commentId: c.id, message: text } }); onChange({ replied: true, myReply: text }); setText(""); } catch (e) { setError(e); } setBusy(null); }; const hide = async () => { setBusy("hide"); setError(null); try { await api("/api/inbox/hide", { method: "POST", body: { client, platform: c.platform, commentId: c.id, hide: !c.hidden } }); onChange({ hidden: !c.hidden }); } catch (e) { setError(e); } setBusy(null); }; return (
  • {c.platform === "instagram" ? "@" : ""}{c.from} {c.platform} {c.replied && replied} {c.hidden && hidden} {timeAgo(c.at)} {c.post?.permalink && on “{c.post.caption || "post"}”}

    {c.text}

    {c.myReply &&

    You: {c.myReply}

    } {!c.replied && !c.hidden && (
    setText(e.target.value)} onKeyDown={(e) => e.key === "Enter" && text.trim() && send()} />
    )}
  • ); }