B6: SPA navigation after case creation (useNavigate instead of window.location.href)
B7: stop AdminDashboard refetching the case list on selection change selectedCaseId was both read and written inside the list-loading effect and listed in its deps, causing a second fetch on first render and after every filter reset. Auto-select now uses a functional state update, so the effect no longer depends on selectedCaseId; editForm stays in sync via the existing selectedCase effect.
This commit is contained in:
@@ -76,11 +76,16 @@ function AdminDashboard() {
|
||||
throw new Error(`Не удалось загрузить список кейсов (${response.status})`);
|
||||
}
|
||||
const payload = await response.json();
|
||||
setCases(payload.items || []);
|
||||
const items = payload.items || [];
|
||||
setCases(items);
|
||||
setTotal(payload.total || 0);
|
||||
if ((payload.items || []).length && !selectedCaseId) {
|
||||
setSelectedCaseId(payload.items[0].id);
|
||||
setEditForm(payload.items[0]);
|
||||
// Auto-select the first row only when nothing is selected yet.
|
||||
// Functional update so this effect does not have to read (and depend
|
||||
// on) selectedCaseId — depending on it caused a second fetch on first
|
||||
// render and after every filter reset. editForm is kept in sync by the
|
||||
// selectedCase effect below.
|
||||
if (items.length) {
|
||||
setSelectedCaseId((current) => current || items[0].id);
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.name !== 'AbortError') {
|
||||
@@ -93,7 +98,7 @@ function AdminDashboard() {
|
||||
|
||||
loadCases();
|
||||
return () => controller.abort();
|
||||
}, [filters.ageMax, filters.ageMin, filters.status, page, selectedCaseId]);
|
||||
}, [filters.ageMax, filters.ageMin, filters.status, page]);
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController();
|
||||
|
||||
Reference in New Issue
Block a user