1
0
Fork 0

Checkboxes add to stateful chosen list

This commit is contained in:
Joe Wroten 2017-05-14 06:43:22 -05:00
parent 18f5e653fc
commit 86b2ad9a72
4 changed files with 28 additions and 5 deletions

View file

@ -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')

View file

@ -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)
} }
} }
} }

View file

@ -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

View file

@ -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
} }
} }