import { useEffect, useState } from "react"; import { Link, useParams } from "react-router-dom"; import { publicApi } from "../api/endpoints"; import type { PublicInfographicData, PublicReportData } from "../api/types"; import { InfographicFrame } from "../components/Infographic"; import Logo from "../components/Logo"; import { ReportView } from "../components/ReportView"; import { Loading } from "../components/ui"; /** What a share link opens: /r/:token. Read only, no sign in, not indexed. */ export default function PublicReport() { const { token = "" } = useParams(); const [shared, setShared] = useState(null); const [missing, setMissing] = useState(false); const [showSources, setShowSources] = useState(false); useEffect(() => { // Shared pages stay out of search results. const meta = document.createElement("meta"); meta.name = "robots"; meta.content = "noindex, nofollow"; document.head.appendChild(meta); return () => meta.remove(); }, []); useEffect(() => { publicApi.report(token).then( (r) => { setShared(r); document.title = `${r.title} | Notestack`; }, () => setMissing(true), ); }, [token]); if (missing) { return (

This link does not work

The page may have been taken down, or the link is wrong.

Go to Notestack
); } if (!shared) return
; if (shared.kind === "infographic") { return (

Infographic

{shared.title}

Made with Notestack
); } const report = shared; const posts = report.sources?.posts ?? []; return (
{report.show_sources && report.sources && (
{showSources && (

Made from

{report.sources.chats > 0 &&

{report.sources.chats} notebook chat{report.sources.chats === 1 ? "" : "s"}

}
    {posts.map((p, i) => (
  • {p.url ? {p.title} : p.title}
  • ))}
)}
)}

{report.format === "interactive" ? "Interactive report" : "Report"}

{report.title}

{report.created_at ? new Date(report.created_at).toLocaleDateString(undefined, { year: "numeric", month: "long", day: "numeric" }) : ""} {report.created_at && " ยท "} {report.blocks.filter((b) => b.type === "prose").length} sections

); }