Skip to content

Commit

Permalink
feat: list item count (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
h27-webdev authored and gr2m committed Feb 19, 2018
1 parent ea81c2c commit 5552562
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions public/assets/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ form.add-item label {
form.add-item button {
width: 100%;
}
.hide-item-count {
display: none;
}

@media (min-width: 768px) {
form.add-item {
Expand Down
3 changes: 3 additions & 0 deletions public/assets/js/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var $addItemForm = document.querySelector('form.add-item')
var $itemsList = document.querySelector('.items .list')
var $clearButton = document.querySelector('[data-action="clear"]')
var $itemCount = document.querySelector('.item-count')

/**
* With hoodie we're storing our data locally and it will stick around next time you reload.
Expand Down Expand Up @@ -94,6 +95,7 @@ $itemsList.addEventListener('click', function (event) {
})

function render (items) {
$itemCount.classList.toggle('hide-item-count', items.length === 0);
if (items.length === 0) {
document.body.setAttribute('data-store-state', 'empty')
return
Expand All @@ -110,6 +112,7 @@ function render (items) {
'<td><a href="#" data-action="remove">Delete</a></td>' +
'</tr>'
}).join('')
$itemCount.innerHTML = "List Count: " + items.length;
}

function orderByCreatedAt (item1, item2) {
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ <h1><a href="/">Tracker</a></h1>
<button class="primary" data-action="clear" data-hide-if="store-empty">
Clear tracked items
</button>
<p class="item-count"></p>
</div>
</main>

Expand Down

0 comments on commit 5552562

Please sign in to comment.