<commit_before>import { call, put, select, takeLatest } from 'redux-saga/effects';
import { getLayers } from '../../ducks/panel-layers/map-panel-layers';
import { getStraatbeeldYear } from '../../../shared/ducks/straatbeeld/straatbeeld';
import { SET_MAP_CLICK_LOCATION, UPDATE_MAP } from '../../ducks/map/map';
import { getMapZoom } from '../../ducks/map/map-selectors';
import { REQUEST_GEOSEARCH, REQUEST_NEAREST_DETAILS } from '../geosearch/geosearch';
import {
  getSelectionType,
  SELECTION_TYPE,
  setSelection
} from '../../../shared/ducks/selection/selection';
import { getImageDataByLocation } from '../../../shared/services/straatbeeld-api/straatbeeld-api';
import { toPanorama } from '../../../app/routes';

function getHeadingDegrees([x1, y1], [x2, y2]) {
  return (Math.atan2(y2 - y1, x2 - x1) * 180) / Math.PI;
}

const latitudeLongitudeToArray = (location) => [location.latitude, location.longitude];

export function* switchClickAction(action) {
  const zoom = yield select(getMapZoom);
  const layers = yield select(getLayers);
  const selectionType = yield select(getSelectionType);

  if (selectionType === SELECTION_TYPE.PANORAMA) {
    const year = yield select(getStraatbeeldYear);
    const { location } = action.payload;
    const locationArray = latitudeLongitudeToArray(location);
    const imageData = yield call(getImageDataByLocation, locationArray, year);

      // The view direction should be towards the location that the user clicked
    const heading = getHeadingDegrees(imageData.location, locationArray);

    yield put(toPanorama(imageData.id, heading));
  } else {
    if (layers.length) {
      yield put({
        type: REQUEST_NEAREST_DETAILS,
        payload: {
          location: action.location,
          layers,
          zoom
        }
      });
    } else {
      yield put(setSelection(SELECTION_TYPE.POINT, action.location));
      yield put({
        type: REQUEST_GEOSEARCH,
        payload: [action.location.latitude, action.location.longitude]
      });
    }

    yield put({
      type: UPDATE_MAP,
      payload: {
        query: {
          selectedLocation: `${action.location.latitude},${action.location.longitude}`
        }
      }
    });
  }
}

export default function* watchMapClick() {
  yield takeLatest(SET_MAP_CLICK_LOCATION, switchClickAction);
}<commit_msg>SET_MAP_CLICK_ACTION flux standard action<commit_after>import { call, put, select, takeLatest } from 'redux-saga/effects';
import { getLayers } from '../../ducks/panel-layers/map-panel-layers';
import { getStraatbeeldYear } from '../../../shared/ducks/straatbeeld/straatbeeld';
import { SET_MAP_CLICK_LOCATION, UPDATE_MAP } from '../../ducks/map/map';
import { getMapZoom } from '../../ducks/map/map-selectors';
import { REQUEST_GEOSEARCH, REQUEST_NEAREST_DETAILS } from '../geosearch/geosearch';
import {
  getSelectionType,
  SELECTION_TYPE,
  setSelection
} from '../../../shared/ducks/selection/selection';
import { getImageDataByLocation } from '../../../shared/services/straatbeeld-api/straatbeeld-api';
import { toPanorama } from '../../../app/routes';

function getHeadingDegrees([x1, y1], [x2, y2]) {
  return (Math.atan2(y2 - y1, x2 - x1) * 180) / Math.PI;
}

const latitudeLongitudeToArray = (location) => [location.latitude, location.longitude];

export function* switchClickAction(action) {
  const zoom = yield select(getMapZoom);
  const layers = yield select(getLayers);
  const selectionType = yield select(getSelectionType);
  const { location } = action.payload;

  if (selectionType === SELECTION_TYPE.PANORAMA) {
    const year = yield select(getStraatbeeldYear);
    const locationArray = latitudeLongitudeToArray(location);
    const imageData = yield call(getImageDataByLocation, locationArray, year);

      // The view direction should be towards the location that the user clicked
    const heading = getHeadingDegrees(imageData.location, locationArray);

    yield put(toPanorama(imageData.id, heading));
  } else {
    if (layers.length) {
      yield put({
        type: REQUEST_NEAREST_DETAILS,
        payload: {
          location: location,
          layers,
          zoom
        }
      });
    } else {
      yield put(setSelection(SELECTION_TYPE.POINT, location));
      yield put({
        type: REQUEST_GEOSEARCH,
        payload: [location.latitude, location.longitude]
      });
    }

    yield put({
      type: UPDATE_MAP,
      payload: {
        query: {
          selectedLocation: `${location.latitude},${location.longitude}`
        }
      }
    });
  }
}

export default function* watchMapClick() {
  yield takeLatest(SET_MAP_CLICK_LOCATION, switchClickAction);
}
{'fraction_non_alphanumeric': 0.132960413080895, 'fraction_numerical': 0.0051635111876075735, 'mean_word_length': 3.320631970260223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '507996', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1439, 'n_words': 305}