Merge pull request #11 from sharpshark28/improvement/nopagination
[IMPROVEMENT] Removed pagination, displays all spells now at once
This commit is contained in:
commit
b3bd386195
7 changed files with 60 additions and 66 deletions
|
@ -37,6 +37,10 @@ function fetchSuccess (data) {
|
||||||
loaded: true
|
loaded: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
dispatch({
|
||||||
|
type: 'SPELLS_CREATE_INDEX',
|
||||||
|
data
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchFailure (reason) {
|
function fetchFailure (reason) {
|
||||||
|
@ -63,9 +67,7 @@ export default {
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
if (LocalStorage.has('chosen')) {
|
if (LocalStorage.has('chosen')) {
|
||||||
dispatch({
|
dispatch({type: 'LOAD_LOCAL_CHOSEN'})
|
||||||
type: 'LOAD_LOCAL_CHOSEN'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.state.spells.loaded) {
|
if (!this.state.spells.loaded) {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<template>
|
<template>
|
||||||
<main>
|
<main>
|
||||||
<spell-list
|
<spell-list
|
||||||
v-if="state.spells.data.length"
|
v-if="state.indexedSpells.length"
|
||||||
:spells="state.spells.data"
|
:spells="state.indexedSpells"
|
||||||
></spell-list>
|
></spell-list>
|
||||||
<page-empty
|
<page-empty
|
||||||
v-else
|
v-else
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
v-else
|
v-else
|
||||||
title="You haven't chosen any spells"
|
title="You haven't chosen any spells"
|
||||||
>
|
>
|
||||||
Try <i>bookmark</i> bookmarking spells from the
|
Try <span class="text-pink"><i>bookmark</i> Bookmarking</span> spells from the
|
||||||
<router-link to="/">all spells page</router-link> to add to your spellbook.
|
<router-link to="/">all spells page</router-link> to add to your spellbook.
|
||||||
</page-empty>
|
</page-empty>
|
||||||
</main>
|
</main>
|
||||||
|
@ -34,7 +34,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.state.chosen.map(chosen => {
|
return this.state.chosen.map(chosen => {
|
||||||
return this.state.spells.data.find(spell => {
|
return this.state.indexedSpells.find(spell => {
|
||||||
return spell.name === chosen
|
return spell.name === chosen
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="page-spell">
|
<div class="page-spell">
|
||||||
<router-link
|
<button
|
||||||
tag="button"
|
v-go-back=" '/' "
|
||||||
to="/"
|
|
||||||
class="page-back-small primary shadow-1"
|
class="page-back-small primary shadow-1"
|
||||||
>
|
>
|
||||||
<i>arrow_back</i>
|
<i>arrow_back</i>
|
||||||
Back
|
Back
|
||||||
</router-link>
|
</button>
|
||||||
|
|
||||||
<router-link
|
<button
|
||||||
tag="button"
|
v-go-back=" '/' "
|
||||||
to="/"
|
|
||||||
class="page-back-big primary circular big shadow-2"
|
class="page-back-big primary circular big shadow-2"
|
||||||
>
|
>
|
||||||
<i>arrow_back</i>
|
<i>arrow_back</i>
|
||||||
</router-link>
|
</button>
|
||||||
|
|
||||||
<div class="card bg-white">
|
<div class="card bg-white">
|
||||||
<div class="card-title bg-pink text-white">
|
<div class="card-title bg-pink text-white">
|
||||||
|
@ -93,7 +91,7 @@ export default {
|
||||||
return { state }
|
return { state }
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
state.lastSpell = this.state.spell.data.name
|
this.state.lastSpell = this.spell.name
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
checked () {
|
checked () {
|
||||||
|
|
|
@ -11,22 +11,15 @@
|
||||||
{{classes}}
|
{{classes}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="item-secondary">
|
<div class="item-secondary" v-on:click="toggle">
|
||||||
<i
|
<i
|
||||||
class="float-left text-pink"
|
class="float-left text-pink bookmark checked"
|
||||||
v-if="checked"
|
v-if="checked"
|
||||||
v-on:click="checked = false"
|
|
||||||
>bookmark</i>
|
>bookmark</i>
|
||||||
<i
|
<i
|
||||||
class="float-left text-grey-5"
|
class="float-left text-grey-7 bookmark"
|
||||||
v-else
|
v-else
|
||||||
v-on:click="checked = true"
|
|
||||||
>bookmark_border</i>
|
>bookmark_border</i>
|
||||||
<q-checkbox
|
|
||||||
class="float-right pink"
|
|
||||||
v-model="checked"
|
|
||||||
@input="toggle"
|
|
||||||
></q-checkbox>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -60,11 +53,11 @@ export default {
|
||||||
openSpell (event) {
|
openSpell (event) {
|
||||||
this.$router.push('/spell/' + this.spell.name)
|
this.$router.push('/spell/' + this.spell.name)
|
||||||
},
|
},
|
||||||
toggle (want) {
|
toggle () {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'CHANGE_CHOSEN',
|
type: 'CHANGE_CHOSEN',
|
||||||
data: {
|
data: {
|
||||||
want,
|
want: !this.checked,
|
||||||
name: this.spell.name
|
name: this.spell.name
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -76,4 +69,18 @@ export default {
|
||||||
<style scoped lang="stylus">
|
<style scoped lang="stylus">
|
||||||
.item-secondary
|
.item-secondary
|
||||||
width: 50px
|
width: 50px
|
||||||
|
height: 50px
|
||||||
|
margin: 0
|
||||||
|
padding: 12px
|
||||||
|
.bookmark
|
||||||
|
transition: transform .25s ease
|
||||||
|
&:hover,
|
||||||
|
&:target
|
||||||
|
.bookmark
|
||||||
|
transform: scale(1.5)
|
||||||
|
.bookmark:not(.checked)
|
||||||
|
color: yellow !important
|
||||||
|
&:active
|
||||||
|
.bookmark:not(.checked)
|
||||||
|
color: deeppink !important
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,26 +1,25 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="spell-list-container">
|
<div class="spell-list-container">
|
||||||
<nav-filter></nav-filter>
|
<nav-filter></nav-filter>
|
||||||
<section class="spell-list list striped no-border" id="spell_list">
|
<section
|
||||||
|
class="spell-list list striped no-border"
|
||||||
|
id="spell_list"
|
||||||
|
>
|
||||||
<label
|
<label
|
||||||
is="spell-item"
|
is="spell-item"
|
||||||
class="item two-lines item-link"
|
class="item two-lines item-link"
|
||||||
v-for="spell in pagedSpells"
|
v-for="spell in filteredSpells"
|
||||||
|
:key="spell.name"
|
||||||
|
:ref="spell.name"
|
||||||
:spell="spell"
|
:spell="spell"
|
||||||
>
|
>
|
||||||
</label>
|
</label>
|
||||||
<q-pagination
|
|
||||||
class="text-center"
|
|
||||||
v-model="state.page"
|
|
||||||
:max="numPages"
|
|
||||||
></q-pagination>
|
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import { Utils } from 'quasar'
|
|
||||||
import Query from 'json-query-chain'
|
import Query from 'json-query-chain'
|
||||||
import Filter from './Filter'
|
import Filter from './Filter'
|
||||||
import SpellItem from './Spellitem'
|
import SpellItem from './Spellitem'
|
||||||
|
@ -31,43 +30,21 @@ Vue.component('spell-item', SpellItem)
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return { state }
|
||||||
state,
|
|
||||||
perPage: 0
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
props: [
|
props: [ 'spells' ],
|
||||||
'spells'
|
|
||||||
],
|
|
||||||
mounted () {
|
mounted () {
|
||||||
this.$nextTick(() => {
|
let lastSpellPosition = this.$refs[this.state.lastSpell][0].$el.offsetTop
|
||||||
window.addEventListener('resize', this.newPerPage)
|
let scrollingPageElement = document.getElementsByClassName('layout-view')[0]
|
||||||
})
|
scrollingPageElement.scrollTo(0, lastSpellPosition)
|
||||||
this.calculateNewPage()
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
newPerPage: Utils.debounce(function () {
|
|
||||||
this.calculateNewPage()
|
|
||||||
}, 100),
|
|
||||||
calculateNewPage () {
|
|
||||||
let fontSize = 14
|
|
||||||
this.perPage = Math.floor(window.innerHeight / (fontSize * 5)) - 4
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
numPages () {
|
|
||||||
return Math.ceil(this.filteredSpells.length / this.perPage)
|
|
||||||
},
|
|
||||||
filteredSpells () {
|
filteredSpells () {
|
||||||
return new Query(this.spells)
|
let spells = this.spells
|
||||||
|
return new Query(spells)
|
||||||
.search('name', this.state.search)
|
.search('name', this.state.search)
|
||||||
.sort(this.state.sortBy)
|
.sort(this.state.sortBy)
|
||||||
.results
|
.results
|
||||||
},
|
|
||||||
pagedSpells () {
|
|
||||||
return new Query(this.filteredSpells)
|
|
||||||
.paginate(this.state.page, this.perPage)
|
|
||||||
.results
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
src/store.js
12
src/store.js
|
@ -5,11 +5,12 @@ export let state = {
|
||||||
loaded: false,
|
loaded: false,
|
||||||
data: []
|
data: []
|
||||||
},
|
},
|
||||||
|
indexedSpells: [],
|
||||||
chosen: [],
|
chosen: [],
|
||||||
search: '',
|
search: '',
|
||||||
sortBy: 'name',
|
sortBy: 'name',
|
||||||
previousSortBy: 'name',
|
previousSortBy: 'name',
|
||||||
page: 1
|
lastSpell: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dispatch (action) {
|
export function dispatch (action) {
|
||||||
|
@ -17,6 +18,15 @@ export function dispatch (action) {
|
||||||
case 'SPELLS_RESOLVED':
|
case 'SPELLS_RESOLVED':
|
||||||
state.spells = action.data
|
state.spells = action.data
|
||||||
break
|
break
|
||||||
|
case 'SPELLS_CREATE_INDEX':
|
||||||
|
state.indexedSpells = action.data.map(spell => {
|
||||||
|
return {
|
||||||
|
name: spell.name,
|
||||||
|
classes: spell.classes,
|
||||||
|
level: spell.level
|
||||||
|
}
|
||||||
|
})
|
||||||
|
break
|
||||||
case 'LOAD_LOCAL_CHOSEN' :
|
case 'LOAD_LOCAL_CHOSEN' :
|
||||||
state.chosen = LocalStorage.get.item('chosen').split(',')
|
state.chosen = LocalStorage.get.item('chosen').split(',')
|
||||||
break
|
break
|
||||||
|
|
Loading…
Add table
Reference in a new issue