Skip to content
Snippets Groups Projects

feat(vector-map): avoid multiple loading overlays

Merged Miłosz Grocholewski requested to merge feat/MIN-107-avoid-multiple-load-overlays into development
5 files
+ 48
7
Compare changes
  • Side-by-side
  • Inline
Files
5
import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { useAppSelector } from '@/redux/hooks/useAppSelector';
import {
import {
 
areOverlayBioEntitiesLoadedSelector,
isOverlayActiveSelector,
isOverlayActiveSelector,
isOverlayLoadingSelector,
isOverlayLoadingSelector,
} from '@/redux/overlayBioEntity/overlayBioEntity.selector';
} from '@/redux/overlayBioEntity/overlayBioEntity.selector';
import { removeOverlayBioEntityForGivenOverlay } from '@/redux/overlayBioEntity/overlayBioEntity.slice';
import { getOverlayBioEntityForAllModels } from '@/redux/overlayBioEntity/overlayBioEntity.thunk';
import { getOverlayBioEntityForAllModels } from '@/redux/overlayBioEntity/overlayBioEntity.thunk';
import { BASE_API_URL } from '@/constants';
import { BASE_API_URL } from '@/constants';
import { apiPath } from '@/redux/apiPath';
import { apiPath } from '@/redux/apiPath';
import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus';
import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus';
import { overlaySelector, userOverlaySelector } from '@/redux/overlays/overlays.selectors';
import { overlaySelector, userOverlaySelector } from '@/redux/overlays/overlays.selectors';
 
import {
 
addOverlayToOverlaysId,
 
removeOverlayFromOverlaysId,
 
} from '@/redux/overlayBioEntity/overlayBioEntity.slice';
import { useEmptyBackground } from './useEmptyBackground';
import { useEmptyBackground } from './useEmptyBackground';
type UseOverlay = {
type UseOverlay = {
@@ -25,6 +29,9 @@ export const useOverlay = (overlayId: number): UseOverlay => {
@@ -25,6 +29,9 @@ export const useOverlay = (overlayId: number): UseOverlay => {
const isOverlayLoading = useAppSelector(state => isOverlayLoadingSelector(state, overlayId));
const isOverlayLoading = useAppSelector(state => isOverlayLoadingSelector(state, overlayId));
const { setBackgroundtoEmptyIfAvailable } = useEmptyBackground();
const { setBackgroundtoEmptyIfAvailable } = useEmptyBackground();
const overlay = useAppSelector(state => overlaySelector(state, overlayId));
const overlay = useAppSelector(state => overlaySelector(state, overlayId));
 
const areOverlayBioEntitiesLoaded = useAppSelector(state =>
 
areOverlayBioEntitiesLoadedSelector(state, overlayId),
 
);
const userOverlay = useAppSelector(state => userOverlaySelector(state, overlayId));
const userOverlay = useAppSelector(state => userOverlaySelector(state, overlayId));
const dispatchPluginEvents = (): void => {
const dispatchPluginEvents = (): void => {
@@ -41,9 +48,13 @@ export const useOverlay = (overlayId: number): UseOverlay => {
@@ -41,9 +48,13 @@ export const useOverlay = (overlayId: number): UseOverlay => {
const toggleOverlay = async (): Promise<void> => {
const toggleOverlay = async (): Promise<void> => {
if (isOverlayActive) {
if (isOverlayActive) {
dispatch(removeOverlayBioEntityForGivenOverlay({ overlayId }));
dispatch(removeOverlayFromOverlaysId(overlayId));
} else {
} else {
await dispatch(getOverlayBioEntityForAllModels({ overlayId }));
if (areOverlayBioEntitiesLoaded) {
 
dispatch(addOverlayToOverlaysId(overlayId));
 
} else {
 
await dispatch(getOverlayBioEntityForAllModels({ overlayId }));
 
}
setBackgroundtoEmptyIfAvailable();
setBackgroundtoEmptyIfAvailable();
}
}
Loading