{"size": 862, "ext": "js", "max_stars_repo_path": "hunts/src/modalSlice.js", "max_stars_repo_name": "gradut/cardboard", "max_stars_repo_stars_event_min_datetime": "2019-11-19T21:50:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-24T05:51:23.000Z", "max_issues_repo_path": "hunts/src/modalSlice.js", "max_issues_repo_name": "gradut/cardboard", "max_issues_repo_issues_event_min_datetime": "2019-11-25T01:15:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-22T15:06:53.000Z", "max_forks_repo_path": "hunts/src/modalSlice.js", "max_forks_repo_name": "gradut/cardboard", "max_forks_repo_forks_event_min_datetime": "2022-01-02T22:18:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-20T10:52:56.000Z"}
{"max_stars_count": 21, "max_issues_count": 404, "max_forks_count": 9, "avg_line_length": 26.1212121212, "max_line_length": 81, "alphanum_fraction": 0.63225058}
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import { isRejectedAction } from "./utils";

export const modalSlice = createSlice({
  name: "modal",
  initialState: {
    show: false,
    type: null,
    props: {},
  },
  reducers: {
    showModal: (state, action) => {
      state.show = true;
      state.type = action.payload.type;
      state.props = action.payload.props;
    },
    hideModal: (state) => {
      state.show = false;
    },
  },
  extraReducers: (builder) => {
    builder.addMatcher(isRejectedAction, (state, action) => {
      // On any error, the modal should close, so that the alert is visible.
      // Might need something more precise later but this is good enough for now.
      state.show = false;
    });
  },
});

export const { showModal, hideModal } = modalSlice.actions;

export default modalSlice.reducer;
