Skip to content

Commit 733cf77

Browse files
committed
15 extra credit
1 parent 507e53a commit 733cf77

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

15 - LocalStorage/index-RIO.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ <h2>LOCAL TAPAS</h2>
2323
<input type="text" name="item" placeholder="Item Name" required>
2424
<input type="submit" value="+ Add Item">
2525
</form>
26+
<div class='actions'>
27+
<button class='action' data-action='clear'>clear</button>
28+
<button class='action' data-action='checkAll'>check all</button>
29+
<button class='action' data-action='uncheckAll'>un-check all</button>
30+
</div>
2631
</div>
2732

2833
<script>
2934
const addItems = document.querySelector('.add-items');
3035
const itemsList = document.querySelector('.plates');
3136
const items = JSON.parse(localStorage.getItem('items')) || [];
37+
const actions = document.querySelectorAll('button.action');
3238

3339
function addItem(e) {
3440
e.preventDefault();
@@ -63,8 +69,37 @@ <h2>LOCAL TAPAS</h2>
6369
localStorage.setItem('items', JSON.stringify(items));
6470
}
6571

72+
function clear() {
73+
console.log('clearing all');
74+
populateList([], itemsList);
75+
localStorage.removeItem('items');
76+
}
77+
78+
function checkAll() {
79+
console.log('check all');
80+
items.forEach(item => {
81+
item.done = true;
82+
});
83+
populateList(items, itemsList);
84+
localStorage.setItem('items', JSON.stringify(items));
85+
}
86+
87+
function uncheckAll() {
88+
console.log('clear all');
89+
items.forEach(item => {
90+
item.done = false;
91+
});
92+
populateList(items, itemsList);
93+
localStorage.setItem('items', JSON.stringify(items));
94+
}
95+
96+
function doAction(e) {
97+
window[e.target.dataset.action]();
98+
}
99+
66100
addItems.addEventListener('submit', addItem);
67101
itemsList.addEventListener('click', toggleItem);
102+
actions.forEach(action => action.addEventListener('click', doAction));
68103
populateList(items, itemsList);
69104
</script>
70105

15 - LocalStorage/style.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,14 @@
7676
outline:0;
7777
border:1px solid rgba(0,0,0,0.1);
7878
}
79+
80+
div.actions {
81+
margin-top: 10px;
82+
}
83+
84+
button.action {
85+
padding: 5px;
86+
outline: 0;
87+
border: 1px solid rgba(0,0,0,0.1);
88+
border-radius: 2px;
89+
}

0 commit comments

Comments
 (0)