diff --git a/src/components/Markers.tsx b/src/components/Markers.tsx index a28c6d8..28b1806 100644 --- a/src/components/Markers.tsx +++ b/src/components/Markers.tsx @@ -5,7 +5,7 @@ import IMarker, { IMarkerData } from "../interfaces/IMarker"; import { useAppDispatch } from "../store/hooks"; import { getZone } from "../api/Zone"; import { getWorld } from "../api/World"; -import { selectZone, closeZone } from "../store/slices/Zone"; +import { closeZone } from "../store/slices/Zone"; export default (markers: Array) => { const dispatch = useAppDispatch(); @@ -33,23 +33,18 @@ export default (markers: Array) => { icon={icon} position={position} eventHandlers={{ - click: () => { + click: async () => { if (data.destinationID) { let destination: any; if (data.destinationID === "overworld") { - destination = "00000"; - dispatch(closeZone()); + dispatch(closeZone()) } else { destination = data.destinationID; - - dispatch(getWorld()).then((data) => { - const zones: any = data.payload.zones; - const zone: any = zones.filter( - (z: any) => z.id === destination - )[0]; - dispatch(closeZone()); - dispatch(getZone(zone)); - }); + const world = await dispatch(getWorld()) + const zones = world.payload.zones; + const zone = zones.filter((z:any) => z.id === destination)[0]; + dispatch(closeZone()) + setTimeout(() => { dispatch(getZone(zone)); }, 500); } } }, diff --git a/src/store/slices/Zone.ts b/src/store/slices/Zone.ts index 73d4cd4..ba43b6f 100644 --- a/src/store/slices/Zone.ts +++ b/src/store/slices/Zone.ts @@ -17,7 +17,7 @@ export const worldSlice = createSlice({ name: 'zone', initialState, reducers: { - closeZone: (state) => { + closeZone: (state) => { state.zone = null; } },