-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.js
67 lines (59 loc) · 2.51 KB
/
component.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
// Contains all the logic hooking our components to the store
const renderAndAddListeners = () => {
const items = store.getState().present;
// Render views
renderCanvas(items);
renderEditor(items);
// Dispatch actions when buttons are clicked
items.forEach((item, index) => {
// DELETE_ITEM
document.getElementById('item-editor-' + index + '-delete').addEventListener('click', () => {
store.dispatch(actions.deleteItemAction(index));
});
// SET_ITEM_TEXT
document.getElementById('item-editor-' + index + '-text').addEventListener('change', (e) => {
const text = e.target.value;
store.dispatch(actions.setItemTextAction(index, text));
});
// SET_ITEM_BOLD
document.getElementById('item-editor-' + index + '-bold').addEventListener('change', (e) => {
const bold = e.target.parentElement.classList.contains("is-checked");
store.dispatch(actions.setItemBoldAction(index, bold));
});
// SET_ITEM_ITALIC
document.getElementById('item-editor-' + index + '-italic').addEventListener('change', (e) => {
const italic = e.target.parentElement.classList.contains("is-checked");
store.dispatch(actions.setItemItalicAction(index, italic));
});
// SET_ITEM_UNDERLINE
document.getElementById('item-editor-' + index + '-underline').addEventListener('change', (e) => {
const underline = e.target.parentElement.classList.contains("is-checked");
store.dispatch(actions.setItemUnderlineAction(index, underline));
});
// INCREASE_ITEM_SIZE
document.getElementById('item-editor-' + index + '-size-up').addEventListener('click', () => {
console.log("sizeup")
store.dispatch(actions.increaseItemSizeAction(index));
});
// DECREASE_ITEM_SIZE
document.getElementById('item-editor-' + index + '-size-down').addEventListener('click', () => {
store.dispatch(actions.decreaseItemSizeAction(index));
});
});
}
store.subscribe(() => {
renderAndAddListeners();
});
renderAndAddListeners();
// ADD_ITEM
document.getElementById('add-item').addEventListener("click", () => {
store.dispatch(actions.addItemAction());
});
// UNDO
document.getElementById('undo').addEventListener("click", () => {
store.dispatch({ type: 'UNDO'});
});
// REDO
document.getElementById('redo').addEventListener("click", () => {
store.dispatch({ type: 'REDO'});
});