-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.jsx
128 lines (117 loc) · 2.86 KB
/
App.jsx
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
126
127
128
import React, { Component } from 'react';
import { createStore} from 'redux';
import config from '../config.js';
class NavBar extends Component {
render () {
return (
<div className={this.props.className}>
{this.props.content}
</div>
);
}
}
class Section extends Component {
render() {
let section = this.props.section,
body = section.body;
return (
<div className={section.group.className} onClick={this.props.clickFN}>
<div className={section.head.className}>
{section.head.content}
</div>
<GridView className={body.className} content={body.content} visible = {body.visible}/>
</div>
);
}
}
class GridView extends Component {
render() {
let props = this.props;
console.log(props.visible)
return (
<div style={{display: props.visible ? 'block' : 'none' }}>
{
props.content.map((content, index) =>
<div className={props.className} key={index.toString()}>
<p>{content.name}</p>
<button >Add</button>
<Lists lists={content.lists}/>
</div>
)
}
</div>
);
}
}
class Lists extends Component {
render() {
let displayTime = (list) => {
if (list.start && list.end) {
return (
<div>{list.start} - {list.end}</div>
);
}
}
return (
<div>
{
this.props.lists.map((list, key) =>
<div className='planner-lists' key={key.toString()}>
{displayTime(list)}
<div>{list.name}</div>
</div>
)
}
</div>
)
}
}
const head = (state = {}, action) => {
switch (action.type) {
case 'TOGGLE_VISIBLITY':
if (state.head.content !== action.id) {
return state
}
state.body.visible = !state.body.visible;
/*return Object.assign({}, state, {
visible: !state.visible
})*/
return state;
default:
return state
}
}
const heads = (state = [], action) => {
switch (action.type) {
case 'TOGGLE_VISIBLITY':
state.body = state.body.map(t =>
head(t, action)
);
}
return state;
}
export const store = createStore(heads, config);
export class App extends Component {
render() {
let config = this.props.config;
return (
<div>
<NavBar className={config.head.className} content={config.head.content} />
<div>
{
config.body.map((section, index) =>
<Section key={section.head.content} section={section} clickFN={() => {
let content = section.head.content;
store.dispatch({
type: 'TOGGLE_VISIBLITY',
id: content
});
}
}/>
)
}
</div>
</div>
)
}
}