import * as TID from "@atcute/tid"; import { createResource, createSignal, For, onMount, Show } from "solid-js"; import { getAllBacklinks, getRecordBacklinks, LinksWithRecords } from "../utils/api.js"; import { localDateFromTimestamp } from "../utils/date.js"; import { Button } from "./button.jsx"; type BacklinksProps = { target: string; collection: string; path: string; }; type BacklinkEntry = { collection: string; path: string; counts: { distinct_dids: number; records: number }; }; const flattenLinks = (links: Record): BacklinkEntry[] => { const entries: BacklinkEntry[] = []; Object.keys(links) .toSorted() .forEach((collection) => { const paths = links[collection]; Object.keys(paths) .toSorted() .forEach((path) => { if (paths[path].records > 0) { entries.push({ collection, path, counts: paths[path] }); } }); }); return entries; }; const BacklinkRecords = (props: BacklinksProps & { cursor?: string }) => { const [links, setLinks] = createSignal(); const [more, setMore] = createSignal(false); onMount(async () => { const res = await getRecordBacklinks(props.target, props.collection, props.path, props.cursor); setLinks(res); }); return ( Loading…

}> {({ did, collection, rkey }) => { const timestamp = TID.validate(rkey) ? localDateFromTimestamp(TID.parse(rkey).timestamp / 1000) : null; return ( {rkey} {did} {timestamp ?? ""} ); }} } >
); }; const Backlinks = (props: { target: string }) => { const [response] = createResource(async () => { const res = await getAllBacklinks(props.target); return flattenLinks(res.links); }); return (
Loading…

}>

No backlinks found.

{(entry) => ( )}
); }; const BacklinkSection = ( props: BacklinksProps & { counts: { distinct_dids: number; records: number } }, ) => { const [expanded, setExpanded] = createSignal(false); return (
); }; export { Backlinks };