Skip to content
Snippets Groups Projects

feat: add map API communication

Merged Adrian Orłów requested to merge feature/MIN-103-map-api-comm into development
6 unresolved threads

Context:

In !43 (merged) we've prepared full map data management but without covering aspect of communication with API. !43 (merged) creates only solution for handling and fetching backend data.

Objective:

This PR adds API communication of the map, which means simply using actions and data in the components.

It includes:

  • initializing map with backend data
  • pushing all fetched data to the store
  • middleware that watched for changes in map/modelId and rebuilds local map data
  • unit tests of the above

Additionally:

  • Prettier config upgrade
Edited by Adrian Orłów

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
44 49 new TileLayer({
45 50 visible: true,
46 51 source: new XYZ({
47 url: 'https://pdmap.uni.lu/map_images/9d4911bdeeea752f076e57a91d9b1f45/_nested0/{z}/{x}/{y}.PNG',
48 // TODO: build url from data in redux
52 url: `${BASE_MAP_IMAGES_URL}/map_images/${project?.directory}/${currentBackgroundImagePath}/{z}/{x}/{y}.PNG`,
  • As in previous PR - models reducer is already in development branch. Steps 1-3 might is written in synchronous way but logic behind handling synchronization is a bit confusing. It could probably be moved to thunks. It might be RFC from my side

  • Adrian Orłów added 48 commits

    added 48 commits

    Compare with previous version

  • Adrian Orłów added 1 commit

    added 1 commit

    • 525ff421 - feat: move map init hook logic to redux

    Compare with previous version

  • Adrian Orłów added 2 commits

    added 2 commits

    • fe8f1719 - test: add tests for map init hook logic
    • 24042df9 - feat: add map middleware and tests

    Compare with previous version

  • Adrian Orłów marked this merge request as ready

    marked this merge request as ready

  • Adrian Orłów changed the description

    changed the description

  • 28 29 export const store = configureStore({
    29 30 reducer: reducers,
    30 31 devTools: true,
    32 enhancers: [applyMiddleware(mapMiddleware)],
  • 1 import { getUpdatedMapData } from '@/utils/map/getUpdatedMapData';
    2 import { Middleware, MiddlewareAPI } from '@reduxjs/toolkit';
    3 import type { AppDispatch, RootState } from '../../store';
    4 import { setMapData } from '../map.slice';
    5 import { MiddlewareAllowedAction } from '../map.types';
    6 import { checkIfIsActionValid } from './checkIfIsActionValid';
    7 import { getUpdatedModel } from './getUpdatedModel';
    8
    9 /* prettier-ignore */
    10 export const mapMiddleware: Middleware =
    11 ({ getState, dispatch }: MiddlewareAPI<AppDispatch, RootState>) =>
    12 (next: AppDispatch) =>
    13 // eslint-disable-next-line consistent-return
    14 (action: MiddlewareAllowedAction) => {
  • 1 import type { RootState } from '@/redux/store';
    2 import { MIDDLEWARE_ALLOWED_ACTIONS } from '../map.constants';
    3 import { MiddlewareAllowedAction } from '../map.types';
    4
    5 export const checkIfIsActionValid = (
    6 action: MiddlewareAllowedAction,
    7 state: RootState,
    8 ): boolean => {
    9 const isAllowedAction = MIDDLEWARE_ALLOWED_ACTIONS.some(allowedAction =>
  • 1 import type { RootState } from '@/redux/store';
    2 import { MIDDLEWARE_ALLOWED_ACTIONS } from '../map.constants';
    3 import { MiddlewareAllowedAction } from '../map.types';
    4
    5 export const checkIfIsActionValid = (
    6 action: MiddlewareAllowedAction,
    7 state: RootState,
    8 ): boolean => {
    9 const isAllowedAction = MIDDLEWARE_ALLOWED_ACTIONS.some(allowedAction =>
    10 action.type.includes(allowedAction),
    11 );
    12
    13 const { modelId: currentModelId } = state.map.data;
  • 1 import { getUpdatedMapData } from '@/utils/map/getUpdatedMapData';
    2 import { Middleware, MiddlewareAPI } from '@reduxjs/toolkit';
    3 import type { AppDispatch, RootState } from '../../store';
    4 import { setMapData } from '../map.slice';
    5 import { MiddlewareAllowedAction } from '../map.types';
    6 import { checkIfIsActionValid } from './checkIfIsActionValid';
    7 import { getUpdatedModel } from './getUpdatedModel';
    8
    9 /* prettier-ignore */
    10 export const mapMiddleware: Middleware =
    11 ({ getState, dispatch }: MiddlewareAPI<AppDispatch, RootState>) =>
    12 (next: AppDispatch) =>
    13 // eslint-disable-next-line consistent-return
    14 (action: MiddlewareAllowedAction) => {
    15 const state = getState();
    16 const isActionValid = checkIfIsActionValid(action, state);
  • Idea looks ok. If I don't miss context behind your middleware -> I would use middleware listener proposed by redux-toolkit documentation and it's RFC from my side

  • Tadeusz Miesiąc approved this merge request

    approved this merge request

  • Adrian Orłów added 1 commit

    added 1 commit

    • ec7c962f - feat: rewrite map middleware with use of RTK util

    Compare with previous version

  • Adrian Orłów mentioned in commit ed22d825

    mentioned in commit ed22d825

  • merged

  • Please register or sign in to reply
    Loading