update optimize
Build and Deploy Docker Images / build_and_deploy (push) Has been cancelled

This commit is contained in:
hamid zarghami
2026-06-06 15:06:19 +03:30
parent c9d152fbaf
commit 804f6f69ae
8 changed files with 103 additions and 20 deletions
+26
View File
@@ -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),
}),
]);
}
+39
View File
@@ -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;
}