Refactored to use routes and App.vue
This commit is contained in:
parent
c9da3b2033
commit
96f3dda172
9 changed files with 280 additions and 206 deletions
74
src/App.vue
74
src/App.vue
|
@ -1,15 +1,75 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- Don't drop "q-app" class -->
|
|
||||||
<div id="q-app">
|
<div id="q-app">
|
||||||
|
<q-layout>
|
||||||
|
<nav-header-primary
|
||||||
|
slot="header"
|
||||||
|
class="toolbar dark"
|
||||||
|
></nav-header-primary>
|
||||||
|
|
||||||
|
<nav-header-secondary
|
||||||
|
slot="header"
|
||||||
|
class="toolbar dark"
|
||||||
|
></nav-header-secondary>
|
||||||
|
|
||||||
|
<div class="layout-view">
|
||||||
<router-view></router-view>
|
<router-view></router-view>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<nav-footer
|
||||||
|
slot="footer"
|
||||||
|
class="toolbar pink"
|
||||||
|
></nav-footer>
|
||||||
|
</q-layout>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
/*
|
import { Loading, Dialog } from 'quasar'
|
||||||
* Root component
|
import Vue from 'vue'
|
||||||
*/
|
import 'whatwg-fetch'
|
||||||
export default {}
|
import { state, dispatch } from './store'
|
||||||
</script>
|
import HeaderPrimary from './components/Headerprimary'
|
||||||
|
import HeaderSecondary from './components/Headersecondary'
|
||||||
|
import Footer from './components/Footer'
|
||||||
|
|
||||||
<style></style>
|
Vue.component('nav-header-primary', HeaderPrimary)
|
||||||
|
Vue.component('nav-header-secondary', HeaderSecondary)
|
||||||
|
Vue.component('nav-footer', Footer)
|
||||||
|
|
||||||
|
function fetchSuccess (data) {
|
||||||
|
dispatch({
|
||||||
|
type: 'SPELLS_RESOLVED',
|
||||||
|
data: {
|
||||||
|
data,
|
||||||
|
loaded: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchFailure (reason) {
|
||||||
|
let message = 'Unable to retrieve spells list'
|
||||||
|
Dialog.create({
|
||||||
|
title: 'Error',
|
||||||
|
message,
|
||||||
|
nobuttons: true
|
||||||
|
})
|
||||||
|
console.error(message, reason)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data () {
|
||||||
|
return { state }
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
if (!this.state.spells.loaded) {
|
||||||
|
Loading.show()
|
||||||
|
|
||||||
|
fetch('./statics/dnd5e.json')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(fetchSuccess)
|
||||||
|
.catch(fetchFailure)
|
||||||
|
.then(() => { Loading.hide() })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
43
src/components/Footer.vue
Normal file
43
src/components/Footer.vue
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<template>
|
||||||
|
<footer>
|
||||||
|
<q-tabs
|
||||||
|
class="pink justified"
|
||||||
|
:refs="$refs"
|
||||||
|
default-tab="tab-all"
|
||||||
|
>
|
||||||
|
<q-tab
|
||||||
|
icon="local_library"
|
||||||
|
route="/"
|
||||||
|
exact
|
||||||
|
>
|
||||||
|
All Spells
|
||||||
|
</q-tab>
|
||||||
|
<q-tab
|
||||||
|
icon="bookmark"
|
||||||
|
route="/my"
|
||||||
|
exact
|
||||||
|
>
|
||||||
|
My Spells
|
||||||
|
<span
|
||||||
|
class="label pointing-left bg-yellow text-dark"
|
||||||
|
v-show="state.chosen.length"
|
||||||
|
>{{state.chosen.length}}</span>
|
||||||
|
</q-tab>
|
||||||
|
</q-tabs>
|
||||||
|
</footer>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { state } from '../store'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data () {
|
||||||
|
return { state }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="stylus">
|
||||||
|
footer .q-tabs
|
||||||
|
width: 100%
|
||||||
|
</style>
|
47
src/components/Headerprimary.vue
Normal file
47
src/components/Headerprimary.vue
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<q-toolbar-title :padding="0">
|
||||||
|
My Spells v2.0
|
||||||
|
</q-toolbar-title>
|
||||||
|
|
||||||
|
<button v-on:click="copy">
|
||||||
|
<i>file_download</i>
|
||||||
|
<q-tooltip
|
||||||
|
anchor="bottom right"
|
||||||
|
self="top right"
|
||||||
|
>
|
||||||
|
Export Selected Spells
|
||||||
|
</q-tooltip>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button v-on:click="paste">
|
||||||
|
<i>cloud_upload</i>
|
||||||
|
<q-tooltip
|
||||||
|
anchor="bottom right"
|
||||||
|
self="top right"
|
||||||
|
>
|
||||||
|
Import Selected Spells
|
||||||
|
</q-tooltip>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { state } from '../store'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
state
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
copy () {
|
||||||
|
console.log('Copy Chosen!', this.state.chosen)
|
||||||
|
},
|
||||||
|
paste () {
|
||||||
|
console.log('Load Chosen!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
61
src/components/Headersecondary.vue
Normal file
61
src/components/Headersecondary.vue
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<q-select
|
||||||
|
type="list"
|
||||||
|
v-model="state.sortBy"
|
||||||
|
:options="sortByOptions"
|
||||||
|
></q-select>
|
||||||
|
|
||||||
|
<q-search
|
||||||
|
class="dark"
|
||||||
|
v-model="state.search"
|
||||||
|
@input="searchChanged"
|
||||||
|
></q-search>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { state, dispatch } from '../store'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
state,
|
||||||
|
sortByOptions: [
|
||||||
|
{
|
||||||
|
label: 'Relevance',
|
||||||
|
value: 'sortScore'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Name',
|
||||||
|
value: 'name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Level',
|
||||||
|
value: 'level'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'School',
|
||||||
|
value: 'school'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
searchChanged (newSearch) {
|
||||||
|
if (newSearch.length >= 3) {
|
||||||
|
this.state.previousSortBy = this.state.sortBy
|
||||||
|
this.state.sortBy = 'sortScore'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.state.sortBy = this.state.previousSortBy
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch({ type: 'SEARCH_CHANGED' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
</style>
|
|
@ -1,187 +1,21 @@
|
||||||
<template>
|
<template>
|
||||||
<q-layout>
|
<main>
|
||||||
<div slot="header" class="toolbar dark">
|
|
||||||
<q-toolbar-title :padding="0">
|
|
||||||
My Spells v2.0
|
|
||||||
</q-toolbar-title>
|
|
||||||
|
|
||||||
<button v-on:click="copy">
|
|
||||||
<i>file_download</i>
|
|
||||||
<q-tooltip
|
|
||||||
anchor="bottom right"
|
|
||||||
self="top right"
|
|
||||||
>
|
|
||||||
Export Selected Spells
|
|
||||||
</q-tooltip>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button v-on:click="paste">
|
|
||||||
<i>cloud_upload</i>
|
|
||||||
<q-tooltip
|
|
||||||
anchor="bottom right"
|
|
||||||
self="top right"
|
|
||||||
>
|
|
||||||
Import Selected Spells
|
|
||||||
</q-tooltip>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div slot="header" class="toolbar dark">
|
|
||||||
<q-select
|
|
||||||
type="list"
|
|
||||||
v-model="sortBy"
|
|
||||||
:options="sortByOptions"
|
|
||||||
></q-select>
|
|
||||||
|
|
||||||
<q-search
|
|
||||||
class="dark"
|
|
||||||
v-model="search"
|
|
||||||
@input="searchChanged"
|
|
||||||
></q-search>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="layout-view">
|
|
||||||
<section ref="tab-all">
|
|
||||||
<spell-list
|
<spell-list
|
||||||
:spells="state.spells.data"
|
:spells="state.spells.data"
|
||||||
:search="search"
|
|
||||||
:sortBy="sortBy"
|
|
||||||
></spell-list>
|
></spell-list>
|
||||||
</section>
|
</main>
|
||||||
|
|
||||||
<section ref="tab-my">
|
|
||||||
<spell-list
|
|
||||||
v-if="mySpells.length"
|
|
||||||
:spells="mySpells"
|
|
||||||
:search="search"
|
|
||||||
:sortBy="sortBy"
|
|
||||||
></spell-list>
|
|
||||||
<div v-else>None :D</div>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<footer slot="footer" class="toolbar pink">
|
|
||||||
<q-tabs
|
|
||||||
class="pink justified"
|
|
||||||
:refs="$refs"
|
|
||||||
default-tab="tab-all"
|
|
||||||
>
|
|
||||||
<q-tab name="tab-all" icon="local_library">
|
|
||||||
All Spells
|
|
||||||
</q-tab>
|
|
||||||
<q-tab name="tab-my" icon="bookmark">
|
|
||||||
My Spells
|
|
||||||
<span
|
|
||||||
class="label pointing-left bg-yellow text-dark"
|
|
||||||
v-show="mySpells.length"
|
|
||||||
>{{mySpells.length}}</span>
|
|
||||||
</q-tab>
|
|
||||||
</q-tabs>
|
|
||||||
</footer>
|
|
||||||
</q-layout>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { Loading, Dialog } from 'quasar'
|
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import 'whatwg-fetch'
|
|
||||||
import { state, dispatch } from '../store'
|
|
||||||
import SpellList from './Spelllist'
|
import SpellList from './Spelllist'
|
||||||
|
import { state } from '../store'
|
||||||
|
|
||||||
Vue.component('spell-list', SpellList)
|
Vue.component('spell-list', SpellList)
|
||||||
|
|
||||||
function fetchSuccess (data) {
|
|
||||||
dispatch({
|
|
||||||
type: 'SPELLS_RESOLVED',
|
|
||||||
data: {
|
|
||||||
data,
|
|
||||||
loaded: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchFailure (reason) {
|
|
||||||
let message = 'Unable to retrieve spells list'
|
|
||||||
Dialog.create({
|
|
||||||
title: 'Error',
|
|
||||||
message,
|
|
||||||
nobuttons: true
|
|
||||||
})
|
|
||||||
console.error(message, reason)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return { state }
|
||||||
state,
|
|
||||||
search: '',
|
|
||||||
sortBy: 'name',
|
|
||||||
previousSortBy: 'name',
|
|
||||||
sortByOptions: [
|
|
||||||
{
|
|
||||||
label: 'Relevance',
|
|
||||||
value: 'sortScore'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Name',
|
|
||||||
value: 'name'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Level',
|
|
||||||
value: 'level'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'School',
|
|
||||||
value: 'school'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
mySpells () {
|
|
||||||
if (!this.state.spells.loaded || this.state.chosen.length === 0) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.state.chosen.map(chosen => {
|
|
||||||
return this.state.spells.data.find(spell => {
|
|
||||||
return spell.name === chosen
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted () {
|
|
||||||
if (!this.state.spells.loaded) {
|
|
||||||
Loading.show()
|
|
||||||
|
|
||||||
fetch('./statics/dnd5e.json')
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(fetchSuccess)
|
|
||||||
.catch(fetchFailure)
|
|
||||||
.then(() => { Loading.hide() })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
copy () {
|
|
||||||
console.log('Copy Chosen!', this.state.chosen)
|
|
||||||
},
|
|
||||||
paste () {
|
|
||||||
console.log('Load Chosen!')
|
|
||||||
},
|
|
||||||
searchChanged (newSearch) {
|
|
||||||
if (newSearch.length >= 3) {
|
|
||||||
this.previousSortBy = this.sortBy
|
|
||||||
this.sortBy = 'sortScore'
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.sortBy = this.previousSortBy
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="stylus">
|
|
||||||
footer .q-tabs
|
|
||||||
width: 100%
|
|
||||||
</style>
|
|
||||||
|
|
35
src/components/Myspells.vue
Normal file
35
src/components/Myspells.vue
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<template>
|
||||||
|
<main>
|
||||||
|
<spell-list
|
||||||
|
v-if="mySpells.length"
|
||||||
|
:spells="mySpells"
|
||||||
|
></spell-list>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Vue from 'vue'
|
||||||
|
import SpellList from './Spelllist'
|
||||||
|
import { state } from '../store'
|
||||||
|
|
||||||
|
Vue.component('spell-list', SpellList)
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data () {
|
||||||
|
return { state }
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
mySpells () {
|
||||||
|
if (!this.state.spells.loaded || this.state.chosen.length === 0) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.state.chosen.map(chosen => {
|
||||||
|
return this.state.spells.data.find(spell => {
|
||||||
|
return spell.name === chosen
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -18,42 +18,31 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Query from '../query'
|
import Query from '../query'
|
||||||
import SpellItem from './Spellitem'
|
import SpellItem from './Spellitem'
|
||||||
|
import { state } from '../store'
|
||||||
|
|
||||||
Vue.component('spell-item', SpellItem)
|
Vue.component('spell-item', SpellItem)
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: [
|
|
||||||
'spells',
|
|
||||||
'search',
|
|
||||||
'sortBy'
|
|
||||||
],
|
|
||||||
data () {
|
data () {
|
||||||
return {
|
return { state }
|
||||||
loadedPage: 1
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
props: [
|
||||||
|
'spells'
|
||||||
|
],
|
||||||
computed: {
|
computed: {
|
||||||
filteredSpells () {
|
filteredSpells () {
|
||||||
return new Query(this.spells)
|
return new Query(this.spells)
|
||||||
.search('name', this.search)
|
.search('name', this.state.search)
|
||||||
.sort(this.sortBy)
|
.sort(this.state.sortBy)
|
||||||
.paginate(1, this.loadedPage * 20)
|
.paginate(1, this.state.loadedPagination * 20)
|
||||||
.results
|
.results
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadMore (index, done) {
|
loadMore (index, done) {
|
||||||
this.loadedPage += 1
|
this.state.loadedPagination += 1
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
sortBy (newSort) {
|
|
||||||
console.log(newSort)
|
|
||||||
},
|
|
||||||
search () {
|
|
||||||
this.loadedPage = 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -22,6 +22,7 @@ export default new VueRouter({
|
||||||
|
|
||||||
routes: [
|
routes: [
|
||||||
{ path: '/', component: load('Index') }, // Default
|
{ path: '/', component: load('Index') }, // Default
|
||||||
|
{ path: '/my', component: load('Myspells') },
|
||||||
{ path: '*', component: load('Error404') } // Not found
|
{ path: '*', component: load('Error404') } // Not found
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
14
src/store.js
14
src/store.js
|
@ -3,7 +3,11 @@ export let state = {
|
||||||
loaded: false,
|
loaded: false,
|
||||||
data: []
|
data: []
|
||||||
},
|
},
|
||||||
chosen: []
|
chosen: [],
|
||||||
|
search: '',
|
||||||
|
sortBy: 'name',
|
||||||
|
previousSortBy: 'name',
|
||||||
|
loadedPagination: 1
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dispatch (action) {
|
export function dispatch (action) {
|
||||||
|
@ -20,10 +24,10 @@ export function dispatch (action) {
|
||||||
if (index >= 0) state.chosen.splice(index, 1)
|
if (index >= 0) state.chosen.splice(index, 1)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
case 'SEARCH_CHANGED':
|
||||||
|
state.loadedPagination = 1
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default { state, dispatch }
|
||||||
state,
|
|
||||||
dispatch
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue