atproto explorer

backlinks API types

juli.ee a96fd57b 13dd9973

verified
+30 -8
+12 -6
src/components/backlinks.tsx
··· 1 1 import * as TID from "@atcute/tid"; 2 2 import { createResource, createSignal, For, onMount, Show } from "solid-js"; 3 - import { getAllBacklinks, getDidBacklinks, getRecordBacklinks } from "../utils/api.js"; 3 + import { 4 + getAllBacklinks, 5 + getDidBacklinks, 6 + getRecordBacklinks, 7 + LinksWithDids, 8 + LinksWithRecords, 9 + } from "../utils/api.js"; 4 10 import { localDateFromTimestamp } from "../utils/date.js"; 5 11 import { Button } from "./button.jsx"; 6 12 ··· 128 134 dids: boolean; 129 135 cursor?: string; 130 136 }) => { 131 - const [links, setLinks] = createSignal<any>(); 137 + const [links, setLinks] = createSignal<LinksWithDids | LinksWithRecords>(); 132 138 const [more, setMore] = createSignal<boolean>(false); 133 139 134 140 onMount(async () => { ··· 147 153 return ( 148 154 <Show when={links()} fallback={<p>Loading&hellip;</p>}> 149 155 <Show when={dids}> 150 - <For each={links().linking_dids}> 156 + <For each={(links() as LinksWithDids).linking_dids}> 151 157 {(did) => ( 152 158 <a 153 159 href={`/at://${did}`} ··· 159 165 </For> 160 166 </Show> 161 167 <Show when={!dids}> 162 - <For each={links().linking_records}> 168 + <For each={(links() as LinksWithRecords).linking_records}> 163 169 {({ did, collection, rkey }) => ( 164 170 <p class="relative flex w-full items-center gap-1 font-mono"> 165 171 <a ··· 177 183 )} 178 184 </For> 179 185 </Show> 180 - <Show when={links().cursor}> 186 + <Show when={links()?.cursor}> 181 187 <Show when={more()} fallback={<Button onClick={() => setMore(true)}>Load More</Button>}> 182 188 <BacklinkItems 183 189 target={target} 184 190 collection={collection} 185 191 path={path} 186 192 dids={dids} 187 - cursor={links().cursor} 193 + cursor={links()!.cursor} 188 194 /> 189 195 </Show> 190 196 </Show>
+18 -2
src/utils/api.ts
··· 119 119 }; 120 120 } 121 121 122 + type LinksWithRecords = { 123 + cursor: string; 124 + total: number; 125 + linking_records: Array<{ did: string; collection: string; rkey: string }>; 126 + }; 127 + 128 + type LinksWithDids = { 129 + cursor: string; 130 + total: number; 131 + linking_dids: Array<string>; 132 + }; 133 + 122 134 const getConstellation = async ( 123 135 endpoint: string, 124 136 target: string, ··· 152 164 path: string, 153 165 cursor?: string, 154 166 limit?: number, 155 - ) => getConstellation("/links", target, collection, path, cursor, limit || 100); 167 + ): Promise<LinksWithRecords> => 168 + getConstellation("/links", target, collection, path, cursor, limit || 100); 156 169 157 170 const getDidBacklinks = ( 158 171 target: string, ··· 160 173 path: string, 161 174 cursor?: string, 162 175 limit?: number, 163 - ) => getConstellation("/links/distinct-dids", target, collection, path, cursor, limit || 100); 176 + ): Promise<LinksWithDids> => 177 + getConstellation("/links/distinct-dids", target, collection, path, cursor, limit || 100); 164 178 165 179 export { 166 180 didDocCache, ··· 175 189 resolvePDS, 176 190 validateHandle, 177 191 type LinkData, 192 + type LinksWithDids, 193 + type LinksWithRecords, 178 194 };