-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
125 lines (99 loc) · 2.52 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
import { createStore } from 'redux';
const reducer = (state = [], action) => {
switch (action.type) {
case 'ADD_TASK':
var v_category
if(action.id % 2 === 0) {
v_category = "Avenue Code"
} else if (action.id % 3 === 0){
v_category = "Client"
} else {
v_category = "PUC Minas - Coreu"
}
return [
...state,
{
id: action.id,
text: action.text,
category: v_category,
deleted: false,
completed: false
}
];
case 'TOGGLE_TASK':
return state.map(task => {
if(task.id !== action.id) {
return task
}
return { ...task, completed: !action.completed}
});
case 'DELETE_TASK':
return state.map(task => {
if(task.id === action.id) {
return { ...task, deleted: !action.deleted }
}
return task
});
case 'EDIT_TASK':
return state.map(task => {
if(task.id === action.id) {
return {...task, text: action.text}
}
return task
});
case 'UP_TASK':
var tmpId = 0
var final = state.map(task => {
if(!task.deleted) {
if(task.id < action.id && task.id > tmpId) {
tmpId = task.id
}
}
return task
})
var tmpTask = final[tmpId].text
final[tmpId].text = final[action.id].text
final[action.id].text = tmpTask
tmpTask = final[tmpId].completed
final[tmpId].completed = final[action.id].completed
final[action.id].completed = tmpTask
tmpTask = final[tmpId].category
final[tmpId].category = final[action.id].category
final[action.id].category = tmpTask
return final;
case 'DOWN_TASK':
var tmpId = state.length - 1
var final = state.map(task => {
if(!task.deleted) {
if(task.id > action.id && task.id < tmpId) {
tmpId = task.id
}
}
return task
})
var tmpTask = final[tmpId].text
final[tmpId].text = final[action.id].text
final[action.id].text = tmpTask
tmpTask = final[tmpId].completed
final[tmpId].completed = final[action.id].completed
final[action.id].completed = tmpTask
tmpTask = final[tmpId].category
final[tmpId].category = final[action.id].category
final[action.id].category = tmpTask
return final;
default:
return state;
}
}
const store = createStore(reducer)
const Main = () => {
console.log(store.getState())
ReactDOM.render(
<App store={store} />, document.getElementById('app')
)
}
store.subscribe(Main)
Main()