Localstorage for chosen spells
This commit is contained in:
parent
603dc59bfa
commit
36581c4665
2 changed files with 28 additions and 6 deletions
22
src/App.vue
22
src/App.vue
|
@ -19,7 +19,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { Loading, Dialog } from 'quasar'
|
import { LocalStorage, Loading, Dialog } from 'quasar'
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import 'whatwg-fetch'
|
import 'whatwg-fetch'
|
||||||
import { state, dispatch } from './store'
|
import { state, dispatch } from './store'
|
||||||
|
@ -49,19 +49,29 @@ function fetchFailure (reason) {
|
||||||
console.error(message, reason)
|
console.error(message, reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fetchSpells () {
|
||||||
|
fetch('./statics/dnd5e.json')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(fetchSuccess)
|
||||||
|
.catch(fetchFailure)
|
||||||
|
.then(() => { Loading.hide() })
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return { state }
|
return { state }
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
|
if (LocalStorage.has('chosen')) {
|
||||||
|
dispatch({
|
||||||
|
type: 'LOAD_LOCAL_CHOSEN'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.state.spells.loaded) {
|
if (!this.state.spells.loaded) {
|
||||||
Loading.show()
|
Loading.show()
|
||||||
|
|
||||||
fetch('./statics/dnd5e.json')
|
fetchSpells()
|
||||||
.then(response => response.json())
|
|
||||||
.then(fetchSuccess)
|
|
||||||
.catch(fetchFailure)
|
|
||||||
.then(() => { Loading.hide() })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
src/store.js
12
src/store.js
|
@ -1,3 +1,5 @@
|
||||||
|
import { LocalStorage } from 'quasar'
|
||||||
|
|
||||||
export let state = {
|
export let state = {
|
||||||
spells: {
|
spells: {
|
||||||
loaded: false,
|
loaded: false,
|
||||||
|
@ -15,6 +17,9 @@ export function dispatch (action) {
|
||||||
case 'SPELLS_RESOLVED':
|
case 'SPELLS_RESOLVED':
|
||||||
state.spells = action.data
|
state.spells = action.data
|
||||||
break
|
break
|
||||||
|
case 'LOAD_LOCAL_CHOSEN' :
|
||||||
|
state.chosen = LocalStorage.get.item('chosen').split(',')
|
||||||
|
break
|
||||||
case 'CHANGE_CHOSEN':
|
case 'CHANGE_CHOSEN':
|
||||||
if (action.data.want) {
|
if (action.data.want) {
|
||||||
state.chosen.push(action.data.name)
|
state.chosen.push(action.data.name)
|
||||||
|
@ -23,6 +28,13 @@ export function dispatch (action) {
|
||||||
let index = state.chosen.indexOf(action.data.name)
|
let index = state.chosen.indexOf(action.data.name)
|
||||||
if (index >= 0) state.chosen.splice(index, 1)
|
if (index >= 0) state.chosen.splice(index, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state.chosen.length) {
|
||||||
|
LocalStorage.set('chosen', state.chosen.join(','))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LocalStorage.remove('chosen')
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case 'SEARCH_CHANGED':
|
case 'SEARCH_CHANGED':
|
||||||
state.loadedPagination = 1
|
state.loadedPagination = 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue