👁️
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

prefetch helper

+27 -12
+25
src/lib/constellation-queries.ts
··· 5 5 import type { Did } from "@atcute/lexicons"; 6 6 import { 7 7 infiniteQueryOptions, 8 + type QueryClient, 8 9 queryOptions, 9 10 useQuery, 10 11 } from "@tanstack/react-query"; ··· 366 367 staleTime: 60 * 1000, 367 368 }); 368 369 } 370 + 371 + // ============================================================================ 372 + // Prefetch Helpers 373 + // ============================================================================ 374 + 375 + /** 376 + * Prefetch social stats for an item (card or deck). 377 + * Use in route loaders to warm the cache before render. 378 + */ 379 + export function prefetchSocialStats<T extends SocialItemType>( 380 + queryClient: QueryClient, 381 + itemUri: T extends "card" ? CardItemUri : DeckItemUri, 382 + itemType: T, 383 + ) { 384 + return Promise.all([ 385 + queryClient.prefetchQuery(itemSaveCountQueryOptions(itemUri, itemType)), 386 + queryClient.prefetchQuery(itemLikeCountQueryOptions(itemUri, itemType)), 387 + itemType === "card" 388 + ? queryClient.prefetchQuery( 389 + cardDeckCountQueryOptions(itemUri as CardItemUri), 390 + ) 391 + : null, 392 + ] as const); 393 + }
+2 -12
src/routes/card/$id.tsx
··· 6 6 import { OracleText } from "@/components/OracleText"; 7 7 import { SocialStats } from "@/components/social/SocialStats"; 8 8 import { getAllFaces } from "@/lib/card-faces"; 9 - import { 10 - itemLikeCountQueryOptions, 11 - itemSaveCountQueryOptions, 12 - } from "@/lib/constellation-queries"; 9 + import { prefetchSocialStats } from "@/lib/constellation-queries"; 13 10 import { FORMAT_GROUPS } from "@/lib/format-utils"; 14 11 import { 15 12 getCardByIdQueryOptions, ··· 54 51 const socialPromise = cardPromise.then((card) => { 55 52 if (!card?.oracle_id) return; 56 53 const oracleUri = toOracleUri(asOracleId(card.oracle_id)); 57 - return Promise.all([ 58 - context.queryClient.ensureQueryData( 59 - itemSaveCountQueryOptions(oracleUri, "card"), 60 - ), 61 - context.queryClient.ensureQueryData( 62 - itemLikeCountQueryOptions(oracleUri, "card"), 63 - ), 64 - ]); 54 + return prefetchSocialStats(context.queryClient, oracleUri, "card"); 65 55 }); 66 56 67 57 const [card] = await Promise.all([