import { createSlice , PayloadAction } from "@reduxjs/toolkit" ; import StateInterface from "reducers/types" ; import { ContestListType , QuestionMapType , SubmissionType , UserInfoType } from 'types' ; export const FetchedData = createSlice ( { name : "FetchDataReducer" , initialState : { submissionList : [ ] as SubmissionType [ ] , questionMap : { } as QuestionMapType , userInfo : { } as UserInfoType , contestData : [ ] as ContestListType [ ] , apiFetched : false } , reducers : { saveSubmissionList : ( state , action ) => { state . submissionList = action . payload ; } , saveQuestionMap : ( state , action ) => { state . questionMap = action . payload ; } , saveUserInfo : ( state , action ) => { state . userInfo = action . payload ; } , saveContestInfo : ( state , action ) => { state . contestData = action . payload ; } , saveApiFetched : ( state , action ) => { state . apiFetched = action . payload ; } , } , } ) ; export const selectSubmissionList = ( state ) : SubmissionType [ ] => state . fetchData . submissionList ; export const selectQuestionMap = ( state ) : QuestionMapType => state . fetchData . questionMap ; export const selectUserInfo = ( state ) : UserInfoType => state . fetchData . userInfo ; export const selectContestData = ( state ) : ContestListType [ ] => state . fetchData . contestData ; export const selectApiFetched = ( state ) : boolean => state . fetchData . apiFetched ; export const { saveQuestionMap , saveContestInfo , saveUserInfo , saveSubmissionList , saveApiFetched } = FetchedData . actions ; export default FetchedData . reducer ;