Skip to content
Snippets Groups Projects

feat: publications modal elements links + reaction search (MIN-241, MIN-229)

All threads resolved!
Files
2
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 type { AppDispatch } from '@/redux/store';
import type { BioEntityContent } from '@/types/models';
interface Args {
bioEntityContents: BioEntityContent[];
dispatch: AppDispatch;
}
export const fetchReactionsAndGetBioEntitiesIds = async ({
dispatch,
bioEntityContents,
}: Args): Promise<string[]> => {
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) {
return [];
}
const result = await dispatch(
getReactionsByIds({
ids: bioEntityReactionsIds,
shouldConcat: true,
}),
);
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(''));
return bioEntitiesIds;
};
Loading