{"size": 691, "ext": "js", "max_stars_repo_path": "web-ui/src/js/hooks/useUndoMarker.js", "max_stars_repo_name": "lemartin19/cs4550-project", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "web-ui/src/js/hooks/useUndoMarker.js", "max_issues_repo_name": "lemartin19/cs4550-project", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "web-ui/src/js/hooks/useUndoMarker.js", "max_forks_repo_name": "lemartin19/cs4550-project", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.7916666667, "max_line_length": 65, "alphanum_fraction": 0.6338639653}
'use es6';

import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { getSessionToken } from '../data/login';
import { getStagedRoute, setMarkers } from '../data/routes';

export const useUndoMarker = ({ undoMarkerButton }) => {
  const dispatch = useDispatch();
  const { points } = useSelector(getStagedRoute);
  const token = useSelector(getSessionToken);

  useEffect(() => {
    if (undoMarkerButton) {
      undoMarkerButton.addEventListener('click', () =>
        setMarkers(
          points.filter((val, idx) => idx !== points.length - 1),
          token
        ).then(dispatch)
      );
    }
  }, [points, token, undoMarkerButton]);
};
