Checkboxes add to stateful chosen list
This commit is contained in:
parent
18f5e653fc
commit
86b2ad9a72
4 changed files with 28 additions and 5 deletions
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
<div class="layout-view">
|
<div class="layout-view">
|
||||||
<spell-list
|
<spell-list
|
||||||
v-if="state.spells.data.length"
|
|
||||||
:spells="state.spells.data"
|
:spells="state.spells.data"
|
||||||
:search="search"
|
:search="search"
|
||||||
></spell-list>
|
></spell-list>
|
||||||
|
@ -58,7 +57,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
if (this.state.spells.loaded === false) {
|
if (!this.state.spells.loaded) {
|
||||||
Loading.show()
|
Loading.show()
|
||||||
|
|
||||||
fetch('./statics/dnd5e.json')
|
fetch('./statics/dnd5e.json')
|
||||||
|
|
|
@ -12,12 +12,17 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="item-secondary">
|
<div class="item-secondary">
|
||||||
<q-checkbox v-model="checked" disable></q-checkbox>
|
<q-checkbox
|
||||||
|
v-model="checked"
|
||||||
|
@input="toggle"
|
||||||
|
></q-checkbox>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { state, dispatch } from '../store'
|
||||||
|
|
||||||
let capitalize = str => str.charAt(0).toUpperCase() + str.slice(1)
|
let capitalize = str => str.charAt(0).toUpperCase() + str.slice(1)
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -43,6 +48,16 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
openSpell (event) {
|
openSpell (event) {
|
||||||
console.log(this.spell.name)
|
console.log(this.spell.name)
|
||||||
|
},
|
||||||
|
toggle (want) {
|
||||||
|
dispatch({
|
||||||
|
type: 'CHANGE_CHOSEN',
|
||||||
|
data: {
|
||||||
|
want,
|
||||||
|
name: this.spell.name
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log(state.chosen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ export default {
|
||||||
return this.search.length >= 3 ? 'sortScore' : this.sortBy
|
return this.search.length >= 3 ? 'sortScore' : this.sortBy
|
||||||
},
|
},
|
||||||
pagedSpells () {
|
pagedSpells () {
|
||||||
debugger
|
|
||||||
return new Query(this.filteredSpells)
|
return new Query(this.filteredSpells)
|
||||||
.paginate(1, this.loadedPage * 20)
|
.paginate(1, this.loadedPage * 20)
|
||||||
.results
|
.results
|
||||||
|
|
12
src/store.js
12
src/store.js
|
@ -2,7 +2,8 @@ export let state = {
|
||||||
spells: {
|
spells: {
|
||||||
loaded: false,
|
loaded: false,
|
||||||
data: []
|
data: []
|
||||||
}
|
},
|
||||||
|
chosen: []
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dispatch (action) {
|
export function dispatch (action) {
|
||||||
|
@ -10,6 +11,15 @@ export function dispatch (action) {
|
||||||
case 'SPELLS_RESOLVED':
|
case 'SPELLS_RESOLVED':
|
||||||
state.spells = action.data
|
state.spells = action.data
|
||||||
break
|
break
|
||||||
|
case 'CHANGE_CHOSEN':
|
||||||
|
if (action.data.want) {
|
||||||
|
state.chosen.push(action.data.name)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let index = state.chosen.indexOf(action.data.name)
|
||||||
|
if (index >= 0) state.chosen.splice(index, 1)
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue