check fix data
This commit is contained in:
@@ -26,6 +26,9 @@ export const useGetCatalogById = (id: string) => {
|
||||
queryKey: ["catalog", id],
|
||||
queryFn: () => api.getCatalogById(id),
|
||||
enabled: !!id,
|
||||
// جلوگیری از بازنویسی state محلی با refetch هنگام فوکوس پنجره (مثلاً دو کاربر همزمان)
|
||||
refetchOnWindowFocus: false,
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -38,6 +41,15 @@ export const useUpdateCatalog = () => {
|
||||
const pendingParamsRef = useRef<Parameters<typeof api.updateCatalog>[0] | null>(null);
|
||||
const [isScheduledSaving, setIsScheduledSaving] = useState(false);
|
||||
|
||||
const cancelPendingUpdate = useCallback(() => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
timeoutRef.current = null;
|
||||
}
|
||||
pendingParamsRef.current = null;
|
||||
setIsScheduledSaving(false);
|
||||
}, []);
|
||||
|
||||
const scheduleUpdate = useCallback(
|
||||
(params: Parameters<typeof api.updateCatalog>[0], delayMs = 3000) => {
|
||||
if (timeoutRef.current) {
|
||||
@@ -79,6 +91,7 @@ export const useUpdateCatalog = () => {
|
||||
return {
|
||||
...mutation,
|
||||
scheduleUpdate,
|
||||
cancelPendingUpdate,
|
||||
isSaving: isScheduledSaving || mutation.isPending,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user