import { useEffect, useState } from "react"; import { Navigate, useNavigate } from "react-router-dom"; import { resurfaceApi } from "../api/endpoints"; import type { Job, ResurfaceItem } from "../api/types"; import { Reader } from "../components/Reader"; import { ScheduleModal } from "../components/ScheduleModal"; import { errorMessage, formatDate, JobProgress, Loading } from "../components/ui"; import { useJob } from "../hooks/useJob"; type Data = Awaited>; function Row({ item, onRead, onSchedule }: { item: ResurfaceItem; onRead: () => void; onSchedule: () => void }) { const navigate = useNavigate(); return (
  • {item.evergreen_score !== null && ( {Math.round(item.evergreen_score * 100)} )}

    {formatDate(item.published_at)} {item.years_ago ? ` · ${item.years_ago} year${item.years_ago > 1 ? "s" : ""} ago today` : ""} {item.last_resurfaced_at ? ` · reshared ${formatDate(item.last_resurfaced_at)}` : ""}

    {item.angle &&

    {item.angle}

    }
  • ); } /** Old posts worth a second orbit. Scoring runs after every sync, so there is nothing to press first. */ export function ResurfaceIdeas({ onScheduled }: { onScheduled?: () => void }) { const [data, setData] = useState(null); const [job, setJob] = useState(null); const [reading, setReading] = useState(null); const [scheduling, setScheduling] = useState(null); const [error, setError] = useState(null); const load = () => resurfaceApi.get().then(setData); useEffect(() => { load(); }, []); const live = useJob(job, () => load()); const running = live && (live.status === "queued" || live.status === "running"); if (!data) return ; const items = [...data.on_this_day, ...data.evergreen.filter((e) => !data.on_this_day.some((o) => o.id === e.id))]; return (
    {live && (running || live.status === "failed") && } {error &&

    {error}

    } {items.length === 0 && (

    {data.total_posts ? "No reshare ideas yet. They appear after your posts are scored." : "Connect a source to get reshare ideas."}

    )}
      {items.slice(0, 8).map((i) => ( setReading(i.id)} onSchedule={() => setScheduling(i)} /> ))}
    {data.unscored > 0 && !running && ( )} {reading && setReading(null)} />} {scheduling && ( setScheduling(null)} onScheduled={() => { load(); onScheduled?.(); }} /> )}
    ); } /** The old Resurfacing page now lives inside Launchpad. */ export default function Resurface() { return ; }