Skip to content

Commit

Permalink
FIX: updated queryKey for PreviewTable to match /transactions and /bl…
Browse files Browse the repository at this point in the history
…ocks so that query cache is correctly primed
  • Loading branch information
ejmg committed Aug 5, 2024
1 parent 3c1866a commit 2c33fc6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@ const LandingCard: FC<CardProps> = ({ heading, children, className, buttonText,
export default function Home() {
const queryClient = getQueryClient();

const blocksQuery = "previewBlocks";
const transactionsQuery = "previewTransactions";
const blocksQuery = "BlocksTable";
const transactionsQuery = "TransactionsTable";
const blocksEndpoint = "api/blocks";
const transactionEndpoint = "api/transactions";
const errorMessage = "Problems were encountered while trying to query explorer data for the main page, please try again.";

Promise.all([
queryClient.prefetchQuery({
queryFn: () => getTransactions({ endpoint: transactionEndpoint, pageIndex: 0 }),
queryKey: [transactionsQuery],
queryKey: [transactionsQuery, 0],
staleTime: 0,
meta: {
errorMessage,
},
}),
queryClient.prefetchQuery({
queryFn: () => getBlocks({ endpoint: blocksEndpoint, pageIndex: 0 }),
queryKey: [blocksQuery],
queryKey: [blocksQuery, 0],
staleTime: 0,
meta: {
errorMessage,
Expand Down
8 changes: 4 additions & 4 deletions src/components/PreviewTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface QueryOptions {

interface PreviewTableProps {
className?: string,
queryName: "previewBlocks" | "previewTransactions",
queryName: "BlocksTable" | "TransactionsTable",
pageIndex: number,
endpoint: string,
errorMessage: string,
Expand All @@ -33,7 +33,7 @@ export function PreviewTable ({
errorMessage,
} : PreviewTableProps) {

const getFn = queryName === "previewBlocks" ? getBlocks : getTransactions;
const getFn = queryName === "BlocksTable" ? getBlocks : getTransactions;

const { data } : {
data : {
Expand All @@ -51,7 +51,7 @@ export function PreviewTable ({
}[];
}
} = useSuspenseQuery({
queryKey: [queryName],
queryKey: [queryName, pageIndex],
queryFn: () => getFn({ endpoint, pageIndex }),
// refresh preview data every 15 seconds
refetchInterval: 15 * 1000,
Expand All @@ -63,7 +63,7 @@ export function PreviewTable ({
const { results } = data ?? { pages: 0, results: []};

// Checks only necessary for safely enforcing type. See todo comment above.
if (queryName === "previewBlocks") {
if (queryName === "BlocksTable") {
const tableData = results as {
height: bigint,
created_at: string,
Expand Down

0 comments on commit 2c33fc6

Please sign in to comment.