From fe5744ad3cfdb8fd963029f1357c991fb118db77 Mon Sep 17 00:00:00 2001 From: rimar1337 <132627503+rimar1337@users.noreply.github.com> Date: Tue, 21 Oct 2025 12:02:50 +0700 Subject: [PATCH] for real this time --- src/components/UniversalPostRenderer.tsx | 5 +++- src/routes/profile.$did/post.$rkey.tsx | 10 ++++++- src/routes/settings.tsx | 9 +++--- src/utils/useQuery.ts | 38 +++++++++++++----------- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/components/UniversalPostRenderer.tsx b/src/components/UniversalPostRenderer.tsx index 3e005b7..f7442a2 100644 --- a/src/components/UniversalPostRenderer.tsx +++ b/src/components/UniversalPostRenderer.tsx @@ -5,7 +5,7 @@ import { DropdownMenu } from "radix-ui"; import * as React from "react"; import { type SVGProps } from "react"; -import { composerAtom, likedPostsAtom } from "~/utils/atoms"; +import { composerAtom, constellationURLAtom, likedPostsAtom } from "~/utils/atoms"; import { useHydratedEmbed } from "~/utils/useHydrated"; import { useQueryConstellation, @@ -401,9 +401,12 @@ export function UniversalPostRendererATURILoader({ // path: ".reply.parent.uri", // }); + const [constellationurl] = useAtom(constellationURLAtom) + const infinitequeryresults = useInfiniteQuery({ ...yknowIReallyHateThisButWhateverGuardedConstructConstellationInfiniteQueryLinks( { + constellation: constellationurl, method: "/links", target: atUri, collection: "app.bsky.feed.post", diff --git a/src/routes/profile.$did/post.$rkey.tsx b/src/routes/profile.$did/post.$rkey.tsx index 269e4b7..a455354 100644 --- a/src/routes/profile.$did/post.$rkey.tsx +++ b/src/routes/profile.$did/post.$rkey.tsx @@ -1,10 +1,12 @@ import { AtUri } from "@atproto/api"; import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query"; import { createFileRoute, Outlet } from "@tanstack/react-router"; +import { useAtom } from "jotai"; import React, { useLayoutEffect } from "react"; import { Header } from "~/components/Header"; import { UniversalPostRendererATURILoader } from "~/components/UniversalPostRenderer"; +import { constellationURLAtom, slingshotURLAtom } from "~/utils/atoms"; //import { usePersistentStore } from '~/providers/PersistentStoreProvider'; import { constructPostQuery, @@ -275,9 +277,12 @@ export function ProfilePostComponent({ // path: ".reply.parent.uri", // }); // const replies = repliesData?.linking_records.slice(0, 50) ?? []; + const [constellationurl] = useAtom(constellationURLAtom) + const infinitequeryresults = useInfiniteQuery({ ...yknowIReallyHateThisButWhateverGuardedConstructConstellationInfiniteQueryLinks( { + constellation: constellationurl, method: "/links", target: atUri, collection: "app.bsky.feed.post", @@ -386,6 +391,9 @@ export function ProfilePostComponent({ } }, [parents, layoutReady]); + + const [slingshoturl] = useAtom(slingshotURLAtom) + React.useEffect(() => { if (parentsLoading) { setLayoutReady(false); @@ -414,7 +422,7 @@ export function ProfilePostComponent({ while (currentParentUri && safetyCounter < MAX_PARENTS) { try { const parentPost = await queryClient.fetchQuery( - constructPostQuery(currentParentUri) + constructPostQuery(currentParentUri, slingshoturl) ); if (!parentPost) break; parentChain.push(parentPost); diff --git a/src/routes/settings.tsx b/src/routes/settings.tsx index 440e742..18eddb5 100644 --- a/src/routes/settings.tsx +++ b/src/routes/settings.tsx @@ -30,18 +30,19 @@ export function Settings() { + please restart/refresh the app if changes arent applying correctly ); } diff --git a/src/utils/useQuery.ts b/src/utils/useQuery.ts index 21d950d..be35e53 100644 --- a/src/utils/useQuery.ts +++ b/src/utils/useQuery.ts @@ -6,15 +6,15 @@ import { useInfiniteQuery, useQuery, type UseQueryResult} from "@tanstack/react-query"; +import { useAtom } from "jotai"; -import { constellationURLAtom, slingshotURLAtom, store } from "./atoms"; +import { constellationURLAtom, slingshotURLAtom } from "./atoms"; -export function constructIdentityQuery(didorhandle?: string) { +export function constructIdentityQuery(didorhandle?: string, slingshoturl?: string) { return queryOptions({ queryKey: ["identity", didorhandle], queryFn: async () => { if (!didorhandle) return undefined as undefined - const slingshoturl = store.get(slingshotURLAtom) const res = await fetch( `https://${slingshoturl}/xrpc/com.bad-example.identity.resolveMiniDoc?identifier=${encodeURIComponent(didorhandle)}` ); @@ -58,15 +58,15 @@ export function useQueryIdentity(didorhandle?: string): Error > export function useQueryIdentity(didorhandle?: string) { - return useQuery(constructIdentityQuery(didorhandle)); + const [slingshoturl] = useAtom(slingshotURLAtom) + return useQuery(constructIdentityQuery(didorhandle, slingshoturl)); } -export function constructPostQuery(uri?: string) { +export function constructPostQuery(uri?: string, slingshoturl?: string) { return queryOptions({ queryKey: ["post", uri], queryFn: async () => { if (!uri) return undefined as undefined - const slingshoturl = store.get(slingshotURLAtom) const res = await fetch( `https://${slingshoturl}/xrpc/com.bad-example.repo.getUriRecord?at_uri=${encodeURIComponent(uri)}` ); @@ -122,15 +122,15 @@ export function useQueryPost(uri?: string): Error > export function useQueryPost(uri?: string) { - return useQuery(constructPostQuery(uri)); + const [slingshoturl] = useAtom(slingshotURLAtom) + return useQuery(constructPostQuery(uri, slingshoturl)); } -export function constructProfileQuery(uri?: string) { +export function constructProfileQuery(uri?: string, slingshoturl?: string) { return queryOptions({ queryKey: ["profile", uri], queryFn: async () => { if (!uri) return undefined as undefined - const slingshoturl = store.get(slingshotURLAtom) const res = await fetch( `https://${slingshoturl}/xrpc/com.bad-example.repo.getUriRecord?at_uri=${encodeURIComponent(uri)}` ); @@ -186,7 +186,8 @@ export function useQueryProfile(uri?: string): Error > export function useQueryProfile(uri?: string) { - return useQuery(constructProfileQuery(uri)); + const [slingshoturl] = useAtom(slingshotURLAtom) + return useQuery(constructProfileQuery(uri, slingshoturl)); } // export function constructConstellationQuery( @@ -222,6 +223,7 @@ export function useQueryProfile(uri?: string) { // target: string // ): QueryOptions; export function constructConstellationQuery(query?:{ + constellation: string, method: | "/links" | "/links/distinct-dids" @@ -254,9 +256,8 @@ export function constructConstellationQuery(query?:{ const path = query?.path const cursor = query.cursor const dids = query?.dids - const constellation = store.get(constellationURLAtom); const res = await fetch( - `https://${constellation}${method}?target=${encodeURIComponent(target)}${collection ? `&collection=${encodeURIComponent(collection)}` : ""}${path ? `&path=${encodeURIComponent(path)}` : ""}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}${dids ? dids.map((did) => `&did=${encodeURIComponent(did)}`).join("") : ""}` + `https://${query.constellation}${method}?target=${encodeURIComponent(target)}${collection ? `&collection=${encodeURIComponent(collection)}` : ""}${path ? `&path=${encodeURIComponent(path)}` : ""}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}${dids ? dids.map((did) => `&did=${encodeURIComponent(did)}`).join("") : ""}` ); if (!res.ok) throw new Error("Failed to fetch post"); try { @@ -345,8 +346,9 @@ export function useQueryConstellation(query?: { > | undefined { //if (!query) return; + const [constellationurl] = useAtom(constellationURLAtom) return useQuery( - constructConstellationQuery(query) + constructConstellationQuery(query && {constellation: constellationurl, ...query}) ); } @@ -451,12 +453,11 @@ export function useQueryPreferences(options: { -export function constructArbitraryQuery(uri?: string) { +export function constructArbitraryQuery(uri?: string, slingshoturl?: string) { return queryOptions({ queryKey: ["arbitrary", uri], queryFn: async () => { if (!uri) return undefined as undefined - const slingshoturl = store.get(slingshotURLAtom) const res = await fetch( `https://${slingshoturl}/xrpc/com.bad-example.repo.getUriRecord?at_uri=${encodeURIComponent(uri)}` ); @@ -511,7 +512,8 @@ export function useQueryArbitrary(uri?: string): UseQueryResult< Error >; export function useQueryArbitrary(uri?: string) { - return useQuery(constructArbitraryQuery(uri)); + const [slingshoturl] = useAtom(slingshotURLAtom) + return useQuery(constructArbitraryQuery(uri, slingshoturl)); } export function constructFallbackNothingQuery(){ @@ -626,12 +628,12 @@ export function useInfiniteQueryFeedSkeleton(options: { export function yknowIReallyHateThisButWhateverGuardedConstructConstellationInfiniteQueryLinks(query?: { + constellation: string, method: '/links' target?: string collection: string path: string }) { - const constellationHost = store.get(constellationURLAtom) console.log( 'yknowIReallyHateThisButWhateverGuardedConstructConstellationInfiniteQueryLinks', query, @@ -657,7 +659,7 @@ export function yknowIReallyHateThisButWhateverGuardedConstructConstellationInfi const cursor = pageParam const res = await fetch( - `https://${constellationHost}${method}?target=${encodeURIComponent(target)}${ + `https://${query.constellation}${method}?target=${encodeURIComponent(target)}${ collection ? `&collection=${encodeURIComponent(collection)}` : '' }${path ? `&path=${encodeURIComponent(path)}` : ''}${ cursor ? `&cursor=${encodeURIComponent(cursor)}` : '' -- 2.51.2