diff --git a/src/redux/bioEntity/thunks/getBioEntity.ts b/src/redux/bioEntity/thunks/getBioEntity.ts index a3e9c058bcde397f2efd140c23dfb882c3d7655d..f8a302ee49a3d97ea240da6bbad3f282b0bc0355 100644 --- a/src/redux/bioEntity/thunks/getBioEntity.ts +++ b/src/redux/bioEntity/thunks/getBioEntity.ts @@ -1,8 +1,5 @@ -import { getBioEntitiesIdsFromReaction } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/getBioEntitiesIdsFromReaction'; -import { SIZE_OF_EMPTY_ARRAY, ZERO } from '@/constants/common'; import { bioEntityResponseSchema } from '@/models/bioEntityResponseSchema'; import { apiPath } from '@/redux/apiPath'; -import { selectTab } from '@/redux/drawer/drawer.slice'; import { axiosInstanceNewAPI } from '@/services/api/utils/axiosInstance'; import { BioEntityContent, BioEntityResponse } from '@/types/models'; import { PerfectSearchParams } from '@/types/search'; @@ -11,9 +8,7 @@ import { getErrorMessage } from '@/utils/getErrorMessage'; import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema'; import { createAsyncThunk } from '@reduxjs/toolkit'; import { addNumbersToEntityNumberData } from '../../entityNumber/entityNumber.slice'; -import { getReactionsByIds } from '../../reactions/reactions.thunks'; import { BIO_ENTITY_FETCHING_ERROR_PREFIX } from '../bioEntity.constants'; -import { getMultiBioEntity } from '../bioEntity.thunks'; type GetBioEntityProps = PerfectSearchParams; @@ -37,38 +32,6 @@ export const getBioEntity = createAsyncThunk< bioEntityResponseSchema, ); - const bioEntityReactionsIds = (response.data?.content || []) - .filter(c => c?.bioEntity?.idReaction) - .map(c => c?.bioEntity?.id) - .filter((id): id is number => typeof id === 'number'); - - if (bioEntityReactionsIds.length > ZERO) { - dispatch( - getReactionsByIds({ - ids: bioEntityReactionsIds, - shouldConcat: true, - }), - ).then(async result => { - if (typeof result.payload === 'string') return; - - const reactions = result.payload?.data; - if (!reactions || reactions.length === SIZE_OF_EMPTY_ARRAY) return; - - const bioEntitiesIds = reactions - .map(reaction => getBioEntitiesIdsFromReaction(reaction)) - .flat(); - - // dispatch(openReactionDrawerById(reactions[FIRST_ARRAY_ELEMENT].id)); - dispatch(selectTab('')); - await dispatch( - getMultiBioEntity({ - searchQueries: bioEntitiesIds, - isPerfectMatch: true, - }), - ); - }); - } - if (addNumbersToEntityNumber && response.data.content) { const bioEntityIds = response.data.content.map(b => b.bioEntity.elementId); dispatch(addNumbersToEntityNumberData(bioEntityIds)); diff --git a/src/redux/bioEntity/thunks/getMultiBioEntity.ts b/src/redux/bioEntity/thunks/getMultiBioEntity.ts index 23afeb9ceec3a5f13196c6a482bd0e1290bfe40b..ec8a92ebff6c34224ecdaaca5e0ef946b5a30f6c 100644 --- a/src/redux/bioEntity/thunks/getMultiBioEntity.ts +++ b/src/redux/bioEntity/thunks/getMultiBioEntity.ts @@ -1,3 +1,7 @@ +import { getBioEntitiesIdsFromReaction } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/getBioEntitiesIdsFromReaction'; +import { SIZE_OF_EMPTY_ARRAY, ZERO } from '@/constants/common'; +import { selectTab } from '@/redux/drawer/drawer.slice'; +import { getReactionsByIds } from '@/redux/reactions/reactions.thunks'; import { BioEntityContent } from '@/types/models'; import { PerfectMultiSearchParams } from '@/types/search'; import { ThunkConfig } from '@/types/store'; @@ -36,6 +40,38 @@ export const getMultiBioEntity = createAsyncThunk< const bioEntityIds = bioEntityContents.map(b => b.bioEntity.elementId); dispatch(addNumbersToEntityNumberData(bioEntityIds)); + const bioEntityReactionsIds = (bioEntityContents || []) + .filter(c => c?.bioEntity?.idReaction) + .map(c => c?.bioEntity?.id) + .filter((id): id is number => typeof id === 'number'); + + if (bioEntityReactionsIds.length > ZERO) { + dispatch( + getReactionsByIds({ + ids: bioEntityReactionsIds, + shouldConcat: true, + }), + ).then(async result => { + if (typeof result.payload === 'string') return; + + const reactions = result.payload?.data; + if (!reactions || reactions.length === SIZE_OF_EMPTY_ARRAY) return; + + const bioEntitiesIds = reactions + .map(reaction => getBioEntitiesIdsFromReaction(reaction)) + .flat(); + + // dispatch(openReactionDrawerById(reactions[FIRST_ARRAY_ELEMENT].id)); + dispatch(selectTab('')); + await dispatch( + getMultiBioEntity({ + searchQueries: bioEntitiesIds, + isPerfectMatch: true, + }), + ); + }); + } + return bioEntityContents; } catch (error) { const errorMessage = getErrorMessage({