- 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) {
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
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
if (!this.school_id) {
this.getInitialSpells()
} else {
this.getInitialSchoolSpells()
}
},
mounted() {
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) {