- Fixed methods of spell list

This commit is contained in:
Alexis
2020-06-29 16:18:26 +02:00
parent 60c179f357
commit 293451288d
2 changed files with 28 additions and 2 deletions

View File

@@ -8,5 +8,8 @@ export default {
}, },
getOne(id) { getOne(id) {
return api.get(`${resource}/${id}`) return api.get(`${resource}/${id}`)
},
getSpellsFromOne(id) {
return api.get(`${resource}/${id}/spells`)
} }
} }

View File

@@ -79,6 +79,7 @@ import AddSpellCard from "./add-spell-card"
// API // API
import { RepositoryFactory } from "~/api/repositories" import { RepositoryFactory } from "~/api/repositories"
const Spells = RepositoryFactory.get('spells') const Spells = RepositoryFactory.get('spells')
const Schools = RepositoryFactory.get('schools')
export default { export default {
name: 'spellslist', name: 'spellslist',
@@ -107,10 +108,16 @@ export default {
}, },
beforeMount() { beforeMount() {
this.spells = this.computedSpells this.spells = this.computedSpells
if (!this.school_id) {
this.getInitialSpells() this.getInitialSpells()
} else {
this.getInitialSchoolSpells()
}
}, },
mounted() { mounted() {
if (!this.school_id) {
this.scroll() this.scroll()
}
}, },
methods: { methods: {
getInitialSpells() { getInitialSpells() {
@@ -129,6 +136,22 @@ export default {
console.log(err) 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() { scroll() {
window.onscroll = () => { window.onscroll = () => {
if (((window.innerHeight + window.scrollY) - document.body.offsetHeight) >= -1) { if (((window.innerHeight + window.scrollY) - document.body.offsetHeight) >= -1) {