{"size": 1149, "ext": "js", "max_stars_repo_path": "src/redux/chat/chatReducer.js", "max_stars_repo_name": "3KINGZ/Chat-App", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/redux/chat/chatReducer.js", "max_issues_repo_name": "3KINGZ/Chat-App", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/redux/chat/chatReducer.js", "max_forks_repo_name": "3KINGZ/Chat-App", "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": 17.4090909091, "max_line_length": 60, "alphanum_fraction": 0.4743255004}
import { SEND_MESSAGE } from "./chatTypes";
import { v4 as uuidv4 } from "uuid";
const initialState = {
  users: [
    {
      id: uuidv4(),
      name: "Martin",
      messages: [],
    },
    {
      id: uuidv4(),
      name: "Jessie",
      messages: [],
    },
    {
      id: uuidv4(),
      name: "Alexander",
      messages: [],
    },
    {
      id: uuidv4(),
      name: "Eugene",
      messages: [],
    },
    {
      id: uuidv4(),
      name: "Lloyd",
      messages: [],
    },
    {
      id: uuidv4(),
      name: "Caleb",
      messages: [],
    },
    {
      id: uuidv4(),
      name: "Doughlas",
      messages: [],
    },
    {
      id: uuidv4(),
      name: "Phoebe",
      messages: [],
    },
    {
      id: uuidv4(),
      name: "Katie",
      messages: [],
    },
  ],
};

const addToCartReducer = (state = initialState, action) => {
  if (action.type === SEND_MESSAGE) {
    const newState = [...state.users];
    const user = newState[action.payload.id];
    user.messages.push(action.payload.message);
    state.users = newState;
    return state;
  } else {
    return state;
  }
};

export default addToCartReducer;
