This commit is contained in:
girault 2022-06-11 12:09:27 +02:00
parent c8311babd7
commit 7d332c542e

View File

@ -2,7 +2,7 @@
<h3>{ props.title }</h3> <h3>{ props.title }</h3>
<ul> <ul>
<li each={ item in state.items }> <li each={ item in state.items.filter(e => e.done == state.search || state.search === undefined ) }>
<label class={ item.done ? 'completed' : null }> <label class={ item.done ? 'completed' : null }>
<input <input
type="checkbox" type="checkbox"
@ -18,11 +18,11 @@
<button disabled={ !state.text }> <button disabled={ !state.text }>
Add #{ state.items.length + 1 } Add #{ state.items.length + 1 }
</button> </button>
<button onclick={ clear }>Clear done</button> <button disabled={this.state.items.filter(e => e["done"]).length == 0} onclick={ clear }>Clear done</button>
<ul class="filters"> <ul class="filters">
<li> <a href="#">All</a></li> <li> <a onclick={() =>filtre(undefined)} href="#">All</a></li>
<li> <a href="#">Active</a></li> <li> <a onclick={() => filtre(false)} href="#">Active</a></li>
<li> <a href="#">Done</a></li> <li> <a onclick={() => filtre(true)} href="#">Done</a></li>
</ul> </ul>
</form> </form>
<script> <script>
@ -31,27 +31,46 @@
// initial state // initial state
this.state = { this.state = {
items: props.items, items: props.items,
text: '' text: '',
search: undefined
} }
}, },
edit(e) { edit(e) {
// update only the text state // update only the text state
e.preventDefault()
this.update({ this.update({
text: e.target.value text: e.target.value
}) })
}, },
clear(e) { clear(e) {
e.preventDefault()
this.state.items = this.state.items.filter(e => e.done == false)
this.update()
// COMPLETEZ // COMPLETEZ
}, },
add(e) { add(e) {
// COMPLETEZ // COMPLETEZ
this.idem.push(e) e.preventDefault()
this.update({items: this.items }) let tab = new Array()
tab["title"] = this.state.text
tab["done"] = false
this.state.items.push(tab)
this.$("form input").value = ""
this.state.text = ""
this.update()
}, },
toggle(item) { toggle(item) {
item.done = !item.done item.done = !item.done
// trigger a component update // trigger a component update
this.update() this.update()
},
filtre(type) {
console.log(type + " and " + this.state.search)
this.update({
search: type
})
} }
} }
</script> </script>