check fix data

This commit is contained in:
Hamid
2026-05-17 00:50:23 -07:00
parent 7589a26706
commit 5bbd677f41
3 changed files with 78 additions and 23 deletions
+13
View File
@@ -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,
};
};