{"size": 1400, "ext": "js", "max_stars_repo_path": "src/context/userState.js", "max_stars_repo_name": "neighborhoodwatcher/neighborhoodwatch", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/context/userState.js", "max_issues_repo_name": "neighborhoodwatcher/neighborhoodwatch", "max_issues_repo_issues_event_min_datetime": "2020-09-06T19:18:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-18T07:03:47.000Z", "max_forks_repo_path": "src/context/userState.js", "max_forks_repo_name": "neighborhoodwatcher/neighborhoodwatch", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 7, "max_forks_count": null, "avg_line_length": 17.0731707317, "max_line_length": 66, "alphanum_fraction": 0.5442857143}
import React, { useReducer } from "react";
import UserContext from "./userContext";
import UserReducer from "./userReducer";

const UserState = props => {
  const initialState = {
    user: {},
    isLoggedIn: false,
    coordinates: { lat: 0, lng: 0 },
    route: "homepage"
  };

  const [state, dispatch] = useReducer(UserReducer, initialState);

  const login = result => {
    dispatch({
      type: "LOGIN",
      payload: result
    });
  };

  const logout = () => {
    dispatch({
      type: "LOGOUT"
    });
  };

  const setRoute = route => {
    dispatch({
      type: "SET_ROUTE",
      payload: route
    });
  };

  const setCoordinates = coordinates => {
    dispatch({
      type: "SET_COORDS",
      payload: coordinates
    });
  };

  const setTopic = topic => {
    dispatch({
      type: "SET_TOPIC",
      payload: topic
    });
  };

  const setPostID = postID => {
    dispatch({
      type: "SET_POSTID",
      payload: postID
    });
  };

  const setPostTitle = postTitle => {
    dispatch({
      type: "SET_POST_TITLE",
      payload: postTitle
    });
  };

  return (
    <UserContext.Provider
      value={{
        userState: state,
        login,
        logout,
        setRoute,
        setCoordinates,
        setTopic,
        setPostID,
        setPostTitle
      }}
    >
      {props.children}
    </UserContext.Provider>
  );
};

export default UserState;
