|
@@ -1,42 +1,23 @@
|
|
|
import React, { Component } from 'react';
|
|
|
-import logo from './logo.svg';
|
|
|
import './App.css';
|
|
|
|
|
|
import { connect, Provider } from 'react-redux';
|
|
|
import { createStore, combineReducers } from 'redux';
|
|
|
|
|
|
|
|
|
-let todoList = [
|
|
|
- {
|
|
|
- title: 'todo one',
|
|
|
- text: 'todo one text',
|
|
|
- timestamp: (new Date()).getTime()
|
|
|
- },
|
|
|
- {
|
|
|
- title: 'todo two',
|
|
|
- text: 'todo two text',
|
|
|
- timestamp: (new Date()).getTime()
|
|
|
- },
|
|
|
- {
|
|
|
- title: 'todo three',
|
|
|
- text: 'todo three text',
|
|
|
- timestamp: (new Date()).getTime()
|
|
|
- }
|
|
|
-];
|
|
|
-
|
|
|
|
|
|
function todoReducer(state, action){
|
|
|
if (typeof state === 'undefined'){
|
|
|
- return {items: JSON.parse(localStorage.todo)};
|
|
|
+ return {items: JSON.parse(localStorage.todo || "[]")};
|
|
|
}
|
|
|
- if (action.type == 'NEW_TODO'){
|
|
|
+ if (action.type === 'NEW_TODO'){
|
|
|
console.log(state);
|
|
|
return {items: [...state.items, {title: action.title, text: action.text, timestamp: (new Date()).getTime()}]}
|
|
|
}
|
|
|
- if (action.type == 'DELETE_TODO'){
|
|
|
+ if (action.type === 'DELETE_TODO'){
|
|
|
let items = [];
|
|
|
for (let i=0;i<state.items.length;i++){
|
|
|
- if (state.items[i].timestamp != action.timestamp){
|
|
|
+ if (state.items[i].timestamp !== action.timestamp){
|
|
|
items.push(state.items[i]);
|
|
|
}
|
|
|
}
|