-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
57 lines (52 loc) · 1.52 KB
/
App.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
import Component from './library/Component.js';
import Trello from './components/Trello.js';
import { setInitialGlobalState, setGlobalState, getGlobalState } from './library/globalState.js';
class App extends Component {
constructor(props) {
super(props);
this.init();
}
init() {
const localState = JSON.parse(localStorage.getItem('trelloState'));
if (localState) setInitialGlobalState(localState);
else
setInitialGlobalState({
lists: [],
modal: { listId: null, cardId: null, isOpened: false, isEditingTitle: false, isEditingDescription: false },
isAddingList: false,
});
}
render() {
return `${new Trello().render()}`;
}
addEvents() {
return [
{
type: 'beforeunload',
selector: 'window',
handler: () => {
setGlobalState(beforeState => {
const newList = [
...beforeState.lists.map(list => ({ ...list, isEditingTitle: false, isAddingCard: false })),
];
const newTrelloState = {
...beforeState,
isAddingList: false,
lists: newList,
modal: {
listId: null,
cardId: null,
isOpened: false,
isEditingTitle: false,
isEditingDescription: false,
},
};
return newTrelloState;
});
localStorage.setItem('trelloState', JSON.stringify(getGlobalState()));
},
},
];
}
}
export default App;