import { ComAtprotoLabelDefs } from "@atcute/atproto"; import { Client, CredentialManager } from "@atcute/client"; import { A, useParams, useSearchParams } from "@solidjs/router"; import { createResource, createSignal, For, onMount, Show } from "solid-js"; import { Button } from "../components/button.jsx"; import { StickyOverlay } from "../components/sticky.jsx"; import { TextInput } from "../components/text-input.jsx"; import { labelerCache, resolvePDS } from "../utils/api.js"; import { localDateFromTimestamp } from "../utils/date.js"; const LabelView = () => { const params = useParams(); const [searchParams, setSearchParams] = useSearchParams(); const [cursor, setCursor] = createSignal(); const [labels, setLabels] = createSignal([]); const [filter, setFilter] = createSignal(); const [labelCount, setLabelCount] = createSignal(0); const did = params.repo; let rpc: Client; onMount(async () => { await resolvePDS(did); rpc = new Client({ handler: new CredentialManager({ service: labelerCache[did] }), }); refetch(); }); const fetchLabels = async () => { const uriPatterns = (document.getElementById("patterns") as HTMLInputElement).value; if (!uriPatterns) return; const res = await rpc.get("com.atproto.label.queryLabels", { params: { uriPatterns: uriPatterns.toString().trim().split(","), sources: [did as `did:${string}:${string}`], cursor: cursor(), }, }); if (!res.ok) throw new Error(res.data.error); setCursor(res.data.labels.length < 50 ? undefined : res.data.cursor); setLabels(labels().concat(res.data.labels) ?? res.data.labels); return res.data.labels; }; const [response, { refetch }] = createResource(fetchLabels); const initQuery = async () => { setLabels([]); setCursor(""); setSearchParams({ uriPatterns: (document.getElementById("patterns") as HTMLInputElement).value, }); refetch(); }; const filterLabels = () => { const newFilter = labels().filter((label) => (filter() ? filter() === label.val : true)); setLabelCount(newFilter.length); return newFilter; }; return (
{ e.preventDefault(); initQuery(); }} >