diff --git a/src/components/hover-card/lexicon.tsx b/src/components/hover-card/lexicon.tsx index 9085a5e..269bc6b 100644 --- a/src/components/hover-card/lexicon.tsx +++ b/src/components/hover-card/lexicon.tsx @@ -1,9 +1,8 @@ import type { Nsid } from "@atcute/lexicons"; -import type { AtprotoDid } from "@atcute/lexicons/syntax"; import { A } from "@solidjs/router"; import { Show } from "solid-js"; -import { parseLexiconRef, resolveLexicon, schemaHash } from "../../lib/lexicon"; +import { parseLexiconRef, resolveLexicon, schemaHref } from "../../lib/lexicon"; import { LexiconSchemaView, type LexiconSchema } from "../lexicon-schema"; import HoverCard, { HoverCardError, type HoverTriggerRenderer } from "./base"; import { createHoverResource } from "./resource"; @@ -16,19 +15,14 @@ interface LexiconHoverCardProps { hoverDelay?: number; } -interface LexiconState { - authority: AtprotoDid; - schema: LexiconSchema; -} - -const fetchLexiconPreview = async (nsid: string): Promise => { - const { authority, schema } = await resolveLexicon(nsid as Nsid); - return { authority, schema: schema.rawSchema as LexiconSchema }; +const fetchLexiconPreview = async (nsid: string): Promise => { + const { schema } = await resolveLexicon(nsid as Nsid); + return schema.rawSchema as LexiconSchema; }; const LexiconHoverCard = (props: LexiconHoverCardProps) => { const parsed = () => parseLexiconRef(props.lexicon); - const href = () => `/lexicon/${parsed().nsid}${schemaHash(parsed().defName)}`; + const href = () => schemaHref(parsed().nsid, parsed().defName); const preview = createHoverResource(() => parsed().nsid, fetchLexiconPreview, { getErrorMessage: (err) => (err instanceof Error ? err.message : "Failed to resolve schema"), }); @@ -60,13 +54,7 @@ const LexiconHoverCard = (props: LexiconHoverCardProps) => { {(data) => ( - + )} diff --git a/src/components/lexicon-schema.tsx b/src/components/lexicon-schema.tsx index b5f7c74..6984e68 100644 --- a/src/components/lexicon-schema.tsx +++ b/src/components/lexicon-schema.tsx @@ -1,12 +1,16 @@ import type { Nsid } from "@atcute/lexicons"; -import type { AtprotoDid } from "@atcute/lexicons/syntax"; import { A, useLocation } from "@solidjs/router"; import { createContext, createEffect, For, type JSX, Show, useContext } from "solid-js"; -import { parseLexiconRef, resolveLexicon, schemaHash, schemaHref } from "../lib/lexicon"; +import { + lexiconRecordHref, + parseLexiconRef, + resolveLexicon, + schemaHash, + schemaHref, +} from "../lib/lexicon"; import HoverCard, { HoverCardError } from "./hover-card/base"; import { createHoverResource } from "./hover-card/resource"; -import Tooltip from "./tooltip.jsx"; // Style constants const CONTAINER_CLASS = @@ -90,14 +94,9 @@ export interface LexiconSchema { }; } -interface LexiconPreviewState { - authority: AtprotoDid; - schema: LexiconSchema; -} - -const fetchLexiconPreview = async (nsid: string): Promise => { - const { authority, schema } = await resolveLexicon(nsid as Nsid); - return { authority, schema: schema.rawSchema as LexiconSchema }; +const fetchLexiconPreview = async (nsid: string): Promise => { + const { schema } = await resolveLexicon(nsid as Nsid); + return schema.rawSchema as LexiconSchema; }; function SchemaRefHoverCard(props: { refType: string; children: JSX.Element }) { @@ -131,13 +130,7 @@ function SchemaRefHoverCard(props: { refType: string; children: JSX.Element }) { {(data) => ( - + )} @@ -739,7 +732,6 @@ const DefSection = (props: { name: string; def: LexiconDef; preview?: boolean }) export const LexiconSchemaView = (props: { schema: LexiconSchema; - authority?: AtprotoDid; preview?: boolean; inertRefs?: boolean; focusDef?: string; @@ -786,27 +778,25 @@ export const LexiconSchemaView = (props: {
{/* Header */}
-
+

- {props.schema.id} + {props.preview ? ( + props.schema.id + ) : ( + + {props.schema.id} + + )}

v{props.schema.lexicon} - - - - - - -

diff --git a/src/lib/lexicon.ts b/src/lib/lexicon.ts index 6759e19..8b2adca 100644 --- a/src/lib/lexicon.ts +++ b/src/lib/lexicon.ts @@ -1,6 +1,6 @@ -import { ResolvedSchema } from "@atcute/lexicon-resolver"; -import { Nsid } from "@atcute/lexicons"; -import { AtprotoDid } from "@atcute/lexicons/syntax"; +import type { ResolvedSchema } from "@atcute/lexicon-resolver"; +import type { Nsid } from "@atcute/lexicons"; +import type { AtprotoDid } from "@atcute/lexicons/syntax"; import { resolveLexiconAuthority, resolveLexiconSchema } from "./api.js"; @@ -21,6 +21,8 @@ export const schemaHash = (defName?: string) => (defName ? `#schema:${defName}` export const schemaHref = (nsid: string, defName?: string) => `/lexicon/${nsid}${schemaHash(defName)}`; +export const lexiconRecordHref = (nsid: string) => `/lexicon/${nsid}#record`; + export const resolveLexicon = (nsid: Nsid): Promise => { let cached = cache.get(nsid); if (cached) return cached; diff --git a/src/lib/schema-tab.tsx b/src/lib/schema-tab.tsx index 8a1be22..8548bde 100644 --- a/src/lib/schema-tab.tsx +++ b/src/lib/schema-tab.tsx @@ -1,6 +1,5 @@ -import { ResolvedSchema } from "@atcute/lexicon-resolver"; -import { Nsid } from "@atcute/lexicons"; -import { AtprotoDid } from "@atcute/lexicons/syntax"; +import type { ResolvedSchema } from "@atcute/lexicon-resolver"; +import type { Nsid } from "@atcute/lexicons"; import { useLocation } from "@solidjs/router"; import { createEffect, createSignal, ErrorBoundary, Show } from "solid-js"; @@ -10,7 +9,6 @@ import { resolveLexicon } from "./lexicon.js"; export const useLexiconSchema = (collection: () => string | undefined) => { const location = useLocation(); const [schema, setSchema] = createSignal(); - const [authority, setAuthority] = createSignal(); const [error, setError] = createSignal(); const [loading, setLoading] = createSignal(false); @@ -22,7 +20,6 @@ export const useLexiconSchema = (collection: () => string | undefined) => { setLoading(true); resolveLexicon(col as Nsid).then( (result) => { - setAuthority(result.authority); setSchema(result.schema); setLoading(false); }, @@ -34,12 +31,11 @@ export const useLexiconSchema = (collection: () => string | undefined) => { } }); - return { schema, authority, error, loading, showSchema }; + return { schema, error, loading, showSchema }; }; export const SchemaTabContent = (props: { schema?: ResolvedSchema; - authority?: AtprotoDid; loading: boolean; error?: string; fallbackSchema?: any; @@ -53,10 +49,7 @@ export const SchemaTabContent = (props: {

Error: {err.message}
}> - +
diff --git a/src/views/collection.tsx b/src/views/collection.tsx index 674e589..56e9f96 100644 --- a/src/views/collection.tsx +++ b/src/views/collection.tsx @@ -547,7 +547,6 @@ const CollectionView = () => { diff --git a/src/views/record.tsx b/src/views/record.tsx index 3b58fb1..dd2af8f 100644 --- a/src/views/record.tsx +++ b/src/views/record.tsx @@ -542,7 +542,6 @@ export const RecordView = () => {