diff --git a/app/blog/[handle]/index.tsx b/app/blog/[handle]/index.tsx new file mode 100644 index 0000000..7e2fad3 --- /dev/null +++ b/app/blog/[handle]/index.tsx @@ -0,0 +1,5 @@ +import { Text } from "react-native" + +export default function BlogPage() { + return Hi! +} \ No newline at end of file diff --git a/app/index.tsx b/app/index.tsx index 6cea0dc..fc42ea8 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -1,9 +1,7 @@ import { AuthContext } from "@/src/context/AuthContext"; import { useContext, useEffect, useState } from "react"; import { Text, View } from "react-native"; -import { com } from "@/src/lexicons"; -import { Slingshot } from "@/src/util/slingshot"; -import { AtIdentifierString } from "@atproto/lex"; +import { resolveHandle } from "@/src/util/handle"; export default function Index() { const authCtx = useContext(AuthContext); @@ -14,10 +12,7 @@ export default function Index() { if (!authCtx.agent) return; - const result = await Slingshot.call(com["bad-example"].identity.resolveMiniDoc, { - identifier: authCtx.agent!.did as AtIdentifierString - }); - setHandle(result.handle); + setHandle(await resolveHandle(authCtx.agent!.did!)); } run(); }, [authCtx.agent, authCtx.agent?.did]); diff --git a/src/util/handle.ts b/src/util/handle.ts index 9024296..78d4a39 100644 --- a/src/util/handle.ts +++ b/src/util/handle.ts @@ -1,5 +1,18 @@ -import { Agent } from "@atproto/api"; +import { AtIdentifierString } from "@atproto/lex"; +import { Slingshot } from "./slingshot"; +import { com } from "../lexicons"; -export function resolveHandle(agent: Agent, did: string) { - +const handleCache: { [did: string]: string } = {} + +// Resolves handles either through the local cache or by requesting from Slingshot +export async function resolveHandle(did: string) { + let handle = handleCache[did] + if (handle === undefined) { + const result = await Slingshot.call(com["bad-example"].identity.resolveMiniDoc, { + identifier: did as AtIdentifierString + }); + handle = result.handle + handleCache[did] = handle + } + return handle; } \ No newline at end of file