From 894532668eff27e054192fc5b7ff6479c105c0d6 Mon Sep 17 00:00:00 2001 From: Joe Wroten Date: Fri, 12 May 2017 15:53:43 -0500 Subject: [PATCH] Refactored to do all search queries in same file --- src/components/Index.vue | 22 +++------------- src/components/Spellitem.vue | 1 - src/components/Spelllist.vue | 50 +++++++++++++++++++----------------- 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/components/Index.vue b/src/components/Index.vue index f27c8fc..2c114d0 100644 --- a/src/components/Index.vue +++ b/src/components/Index.vue @@ -12,7 +12,9 @@
@@ -22,27 +24,12 @@ import { Loading, Dialog } from 'quasar' import Vue from 'vue' import 'whatwg-fetch' -import Query from '../query' import { state, dispatch } from '../store' import SpellList from './Spelllist' Vue.component('spell-list', SpellList) export default { - computed: { - spells () { - if (this.state.spells.data.length === 0) { - return [] - } - - let sortBy = this.search.length >= 3 ? 'sortScore' : 'name' - - return new Query(this.state.spells.data) - .search('name', this.search, 5) - .sort(sortBy) - .results - } - }, data () { return { state, @@ -78,6 +65,3 @@ export default { } } - - diff --git a/src/components/Spellitem.vue b/src/components/Spellitem.vue index 133e644..b8c0b54 100644 --- a/src/components/Spellitem.vue +++ b/src/components/Spellitem.vue @@ -22,7 +22,6 @@ export default { return this.level + this.schoolCapitalized + '\n' + this.spell.name }, schoolCapitalized () { - debugger return this.spell.school.charAt(0).toUpperCase() + this.spell.school.slice(1) } }, diff --git a/src/components/Spelllist.vue b/src/components/Spelllist.vue index b010196..cc42325 100644 --- a/src/components/Spelllist.vue +++ b/src/components/Spelllist.vue @@ -56,21 +56,15 @@ import SpellItem from './Spellitem' Vue.component('spell-item', SpellItem) export default { - computed: { - pageMax () { - let trueMax = this.spells.length / this.perPage - return trueMax < 1 ? 1 : trueMax - }, - pagedSpells () { - return new Query(this.sortedSpells) - .paginate(this.page, this.perPage) - .results - }, - sortedSpells () { - return this.spells - // return new Query(this.spells) - // .sort(this.sortBy) - // .results + props: [ + 'spells', + 'search' + ], + data () { + return { + perPage: 10, + page: 1, + sortBy: 'name' } }, watch: { @@ -80,14 +74,24 @@ export default { } } }, - props: [ - 'spells' - ], - data () { - return { - perPage: 10, - page: 1, - sortBy: 'name' + computed: { + pageMax () { + let trueMax = this.filteredSpells.length / this.perPage + return trueMax < 1 ? 1 : trueMax + }, + dynamicSortBy () { + return this.search.length >= 3 ? 'sortScore' : 'name' + }, + pagedSpells () { + return new Query(this.filteredSpells) + .paginate(this.page, this.perPage) + .results + }, + filteredSpells () { + return new Query(this.spells) + .search('name', this.search, 5) + .sort(this.dynamicSortBy) + .results } } }