fix(orders): список не пустеет при возврате — кэш отдаёт обёртку {data,error}, состояние не стирается

This commit is contained in:
Hermes 2026-09-10 15:04:47 +02:00
parent 52dc913fa7
commit 73b9512f15
2 changed files with 9 additions and 4 deletions

View File

@ -52,7 +52,7 @@ export const useOrderGroups = ({
} }
setLoadError(""); setLoadError("");
if (!enabled) { setOrderGroups([]); setIsLoading(false); return; } if (!enabled) { setIsLoading(false); return; }
// Single-group mode: load only the requested group (avoids pulling all // Single-group mode: load only the requested group (avoids pulling all
// 430 groups with their full source_orders JSON — 2.6MB — for a detail view). // 430 groups with their full source_orders JSON — 2.6MB — for a detail view).
@ -80,12 +80,17 @@ export const useOrderGroups = ({
if (groupsResult.error) { if (groupsResult.error) {
setLoadError(groupsResult.error?.message || "Не удалось загрузить группы доставки"); setLoadError(groupsResult.error?.message || "Не удалось загрузить группы доставки");
setOrderGroups([]); // Список не стираем — показываем прежние данные, а не пустой экран.
setIsLoading(false); setIsLoading(false);
return; return;
} }
const payload = groupsResult.data || {}; const payload = groupsResult.data || {};
// Неожиданная форма ответа — тоже не стираем список.
if (!Array.isArray(payload.data)) {
setIsLoading(false);
return;
}
setOrderGroups(payload.data || []); setOrderGroups(payload.data || []);
setTotalGroups(payload.total ?? (payload.data?.length || 0)); setTotalGroups(payload.total ?? (payload.data?.length || 0));
setIsLoading(false); setIsLoading(false);
@ -110,7 +115,7 @@ export const useOrderGroups = ({
} }
if (cancelled) return; if (cancelled) return;
}; };
if (enabled) doLoad(); else { setOrderGroups([]); setIsLoading(false); } if (enabled) doLoad(); else { setIsLoading(false); }
return () => { cancelled = true; }; return () => { cancelled = true; };
}, [loadLiveData, enabled]); }, [loadLiveData, enabled]);

View File

@ -616,7 +616,7 @@ export const fetchOrderGroups = async ({
if (!forceRefresh) { if (!forceRefresh) {
const cached = orderGroupsCache.get(cacheKey); const cached = orderGroupsCache.get(cacheKey);
if (cached) return cached; if (cached) return { data: cached, error: null };
} }
return safeSupabaseCall(async () => { return safeSupabaseCall(async () => {