This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import * as api from "../service/HomeService";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import * as api from "../service/HomeService";
|
||||
|
||||
export const useCreateCatalog = () => {
|
||||
return useMutation({
|
||||
@@ -31,6 +31,16 @@ export const useGetCatalogById = (id: string) => {
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
};
|
||||
export const useGetCatalogBySlug = (slug: string) => {
|
||||
return useQuery({
|
||||
queryKey: ["catalog", slug],
|
||||
queryFn: () => api.getCatalogBySlug(slug),
|
||||
enabled: !!slug,
|
||||
// جلوگیری از بازنویسی state محلی با refetch هنگام فوکوس پنجره (مثلاً دو کاربر همزمان)
|
||||
refetchOnWindowFocus: false,
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateCatalog = () => {
|
||||
const mutation = useMutation({
|
||||
@@ -38,7 +48,9 @@ export const useUpdateCatalog = () => {
|
||||
});
|
||||
|
||||
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const pendingParamsRef = useRef<Parameters<typeof api.updateCatalog>[0] | null>(null);
|
||||
const pendingParamsRef = useRef<
|
||||
Parameters<typeof api.updateCatalog>[0] | null
|
||||
>(null);
|
||||
const [isScheduledSaving, setIsScheduledSaving] = useState(false);
|
||||
|
||||
const cancelPendingUpdate = useCallback(() => {
|
||||
|
||||
@@ -20,7 +20,14 @@ export const getCatalogs = async () => {
|
||||
|
||||
export const getCatalogById = async (id: string) => {
|
||||
const { data } = await axios.get<CatalogByIdResponseType>(
|
||||
`/public/catalogue/slug/${id}`,
|
||||
`/admin/catalogue/${id}`,
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getCatalogBySlug = async (slug: string) => {
|
||||
const { data } = await axios.get<CatalogByIdResponseType>(
|
||||
`/public/catalogue/slug/${slug}`,
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user