This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import type { QueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
fetchAboutResponse,
|
||||
fetchCategoriesResponse,
|
||||
fetchFoodsResponse,
|
||||
} from "./serverMenuFetch";
|
||||
|
||||
export async function prefetchMenuPageData(
|
||||
queryClient: QueryClient,
|
||||
name: string,
|
||||
) {
|
||||
await Promise.all([
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: ["about", name],
|
||||
queryFn: () => fetchAboutResponse(name),
|
||||
}),
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: ["menu", name],
|
||||
queryFn: () => fetchFoodsResponse(name),
|
||||
}),
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: ["categories", name],
|
||||
queryFn: () => fetchCategoriesResponse(name),
|
||||
}),
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import axios from "axios";
|
||||
import { API_BASE_URL } from "@/config/const";
|
||||
import type { AboutResponse } from "../(Main)/about/types/Types";
|
||||
import type { CategoriesResponse, FoodsResponse } from "../(Main)/types/Types";
|
||||
import { getRestaurant, RESTAURANT_FETCH_TIMEOUT_MS } from "./getRestaurant";
|
||||
|
||||
function createServerAxios(slug: string) {
|
||||
return axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-SLUG": slug,
|
||||
},
|
||||
timeout: RESTAURANT_FETCH_TIMEOUT_MS,
|
||||
});
|
||||
}
|
||||
|
||||
export async function fetchAboutResponse(slug: string): Promise<AboutResponse> {
|
||||
const restaurant = await getRestaurant(slug);
|
||||
return { success: true, data: restaurant };
|
||||
}
|
||||
|
||||
export async function fetchFoodsResponse(slug: string): Promise<FoodsResponse> {
|
||||
const client = createServerAxios(slug);
|
||||
const { data } = await client.get<FoodsResponse>(
|
||||
`/public/foods/restaurant/${slug}`,
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchCategoriesResponse(
|
||||
slug: string,
|
||||
): Promise<CategoriesResponse> {
|
||||
const client = createServerAxios(slug);
|
||||
const { data } = await client.get<CategoriesResponse>(
|
||||
`/public/categories/restaurant/${slug}`,
|
||||
);
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user