Commit dfcbbcba authored by Neranga K.T.'s avatar Neranga K.T.

src->store

parent ae0499a7
export const SET_ANSWERS = 'SET_ANSWERS';
export const SET_TIME = 'SET_TIME';
export const CLEAR_DATA = 'CLEAR_DATA';
export const setAnswers = (data) => {
return {type: SET_ANSWERS, data: data}
}
export const setTime = (time) => {
return {type: SET_TIME, time: time}
}
export const clearData = () => {
return {type: CLEAR_DATA}
}
\ No newline at end of file
import { CLEAR_DATA, SET_ANSWERS, SET_TIME } from "../actions/memory";
const initialState = {
memoryData: {},
screenTime: {}
}
const memoryReducer = (state=initialState, action) => {
switch(action.type){
case SET_ANSWERS:
const addedAnswer = action.data;
const question = addedAnswer.question;
const answer = addedAnswer.answer;
return {
...state,
memoryData: {...state.memoryData, [question]:answer }
}
case SET_TIME:
const trackedTimes = action.time;
const timeKey = trackedTimes.question;
const time = trackedTimes.time;
return {
...state,
screenTime: {...state.screenTime, [timeKey]: time}
}
case CLEAR_DATA:
return{
...state,
memoryData: {},
screenTime: {}
}
default:
return state
}
}
export default memoryReducer;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment