From 293451288d6e755d4b414e5fbae9ed41efa2c733 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Mon, 29 Jun 2020 16:18:26 +0200 Subject: [PATCH] - Fixed methods of spell list --- client/src/api/schoolsRepository.js | 3 +++ client/src/components/spells/spells-list.vue | 27 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/client/src/api/schoolsRepository.js b/client/src/api/schoolsRepository.js index 62ea04b..dd0529f 100644 --- a/client/src/api/schoolsRepository.js +++ b/client/src/api/schoolsRepository.js @@ -8,5 +8,8 @@ export default { }, getOne(id) { return api.get(`${resource}/${id}`) + }, + getSpellsFromOne(id) { + return api.get(`${resource}/${id}/spells`) } } \ No newline at end of file diff --git a/client/src/components/spells/spells-list.vue b/client/src/components/spells/spells-list.vue index d177a1b..4c8d047 100644 --- a/client/src/components/spells/spells-list.vue +++ b/client/src/components/spells/spells-list.vue @@ -79,6 +79,7 @@ import AddSpellCard from "./add-spell-card" // API import { RepositoryFactory } from "~/api/repositories" const Spells = RepositoryFactory.get('spells') +const Schools = RepositoryFactory.get('schools') export default { name: 'spellslist', @@ -107,10 +108,16 @@ export default { }, beforeMount() { this.spells = this.computedSpells - this.getInitialSpells() + if (!this.school_id) { + this.getInitialSpells() + } else { + this.getInitialSchoolSpells() + } }, mounted() { - this.scroll() + if (!this.school_id) { + this.scroll() + } }, methods: { getInitialSpells() { @@ -129,6 +136,22 @@ export default { console.log(err) }) }, + getInitialSchoolSpells() { + Schools.getSpellsFromOne(this.school_id) + .then(v => { + this.loading = true + let spells = this.computedSpells + spells.push(v.data.spells) + this.spells = spells[0] + }) + .then(() => { + this.currentIndex++ + this.loading = false + }) + .catch(err => { + console.log(err) + }) + }, scroll() { window.onscroll = () => { if (((window.innerHeight + window.scrollY) - document.body.offsetHeight) >= -1) {