diff --git a/web/src/store/slices/catalogueJurSlice/catalogueJurSlice.ts b/web/src/store/slices/catalogueJurSlice/catalogueJurSlice.ts index 2f8cb32..e863b79 100644 --- a/web/src/store/slices/catalogueJurSlice/catalogueJurSlice.ts +++ b/web/src/store/slices/catalogueJurSlice/catalogueJurSlice.ts @@ -10,6 +10,7 @@ const initialState: CatalogueJurSliceType = { total_groups: 0, loading: false, error: null, + currentRequestId: null, isGettingArchive: false, relatedGroupFilter: null, activeCompanyGroup: null, @@ -32,22 +33,30 @@ const catalogueJurSlice = createSlice({ resetRows(state) { state.raw_rows = []; state.total_groups = 0; + // Запрос, начатый до сброса, больше не нужен: его ответ отбросится в fulfilled/rejected + state.currentRequestId = null; + state.loading = false; }, }, extraReducers: (builder) => { builder - .addCase(getCatalogueJurThunk.pending, (state, _) => { + .addCase(getCatalogueJurThunk.pending, (state, action) => { + state.currentRequestId = action.meta.requestId; state.loading = true; state.error = null; }) .addCase(getCatalogueJurThunk.fulfilled, (state, action) => { + if (action.meta.requestId !== state.currentRequestId) return; state.raw_rows = action.payload.items; state.total_groups = action.payload.total; state.loading = false; + state.currentRequestId = null; }) .addCase(getCatalogueJurThunk.rejected, (state, action) => { + if (action.meta.requestId !== state.currentRequestId) return; state.error = action.payload ?? 'Неизвестная ошибка'; state.loading = false; + state.currentRequestId = null; }) // Выбранная ГК — копия строки списка ГК: после перезагрузки списка берём свежую (счётчик ЮЛ в шапке и вкладке) .addCase(getCompanyGroupsThunk.fulfilled, (state, action) => { diff --git a/web/src/store/slices/catalogueJurSlice/types.ts b/web/src/store/slices/catalogueJurSlice/types.ts index 7227c33..9048d8a 100644 --- a/web/src/store/slices/catalogueJurSlice/types.ts +++ b/web/src/store/slices/catalogueJurSlice/types.ts @@ -7,6 +7,7 @@ export interface CatalogueJurSliceType { raw_rows: ICatalogueJur[]; loading: boolean; error: string | null; + currentRequestId: string | null; isGettingArchive: boolean; relatedGroupFilter?: RelatedGroupOut | null; activeCompanyGroup?: ICompanyGroup | null;