infinite loading of text using flattoc is ok #764

This commit is contained in:
2020-07-23 11:32:20 +02:00
parent 3ecbf45e2f
commit ff80ee4618
3 changed files with 23 additions and 16 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ export default {
// }, // },
methods: { methods: {
parsePagesToOptions (p, i = 0, l = 0) { parsePagesToOptions (p, i = 0, l = 0) {
console.log('EdPagination parsePagesToOptions', p) // console.log('EdPagination parsePagesToOptions', p)
for (var j = 0; j < p.length; j++) { for (var j = 0; j < p.length; j++) {
// if it is just a section without page like a volume // if it is just a section without page like a volume
if (p[j].text) { if (p[j].text) {
+21 -14
View File
@@ -36,7 +36,7 @@
<div id="text"> <div id="text">
<template v-if="texts.length"> <template v-if="texts.length">
<infinite-loading <infinite-loading
v-if="center_scrolled" v-if="flattoc && center_scrolled"
:identifier="textid" :identifier="textid"
direction="top" direction="top"
:distance="inifinite_load_distance" :distance="inifinite_load_distance"
@@ -53,7 +53,7 @@
@onLeaveLink="onLeaveLink" @onLeaveLink="onLeaveLink"
/> />
<infinite-loading <infinite-loading
v-if="toc" v-if="flattoc"
:identifier="textid" :identifier="textid"
@infinite="nextText" @infinite="nextText"
/> />
@@ -123,11 +123,13 @@ export default {
reftoscrollto: null, reftoscrollto: null,
// //
toc: null, toc: null,
flattoc: null,
// //
pagination: null pagination: null
}), }),
computed: { computed: {
...mapState({ ...mapState({
corpusLoaded: state => state.Corpus.corpusLoaded,
editionslist: state => state.Corpus.editionslist, editionslist: state => state.Corpus.editionslist,
editionsbyuuid: state => state.Corpus.editionsbyuuid editionsbyuuid: state => state.Corpus.editionsbyuuid
}) })
@@ -177,7 +179,7 @@ export default {
} }
// wait for editions list from Corpus Store if not already loaded // wait for editions list from Corpus Store if not already loaded
if (!this.editionslist.length) { if (!this.corpusLoaded) {
// this.getCorpuses() // this.getCorpuses()
// subsribe to store to get the editionbyuuid list // subsribe to store to get the editionbyuuid list
// https://dev.to/viniciuskneves/watch-for-vuex-state-changes-2mgj // https://dev.to/viniciuskneves/watch-for-vuex-state-changes-2mgj
@@ -188,8 +190,9 @@ export default {
this.title = this.metainfotitle = state.Corpus.editionsbyuuid[this.editionid].title this.title = this.metainfotitle = state.Corpus.editionsbyuuid[this.editionid].title
} }
if (mutation.type === 'Corpus/setTocs') { if (mutation.type === 'Corpus/setTocs') {
// console.log('Edition state.Coprus.editionsbyuuid', this.editionid, state.Corpus.editionsbyuuid) console.log('Edition Corpus/setTocs', this.editionid, state.Corpus.editionsbyuuid)
this.toc = state.Corpus.editionsbyuuid[this.editionid].toc this.toc = state.Corpus.editionsbyuuid[this.editionid].toc
this.flattoc = state.Corpus.editionsbyuuid[this.editionid].flattoc
// if no textid in new route (e.g. edition front) // if no textid in new route (e.g. edition front)
// but we have toc // but we have toc
// get the first item // get the first item
@@ -202,8 +205,10 @@ export default {
} }
}) })
} else { } else {
// console.log('');
this.title = this.metainfotitle = this.editionsbyuuid[this.editionid].title this.title = this.metainfotitle = this.editionsbyuuid[this.editionid].title
this.toc = this.editionsbyuuid[this.editionid].toc this.toc = this.editionsbyuuid[this.editionid].toc
this.flattoc = this.editionsbyuuid[this.editionid].flattoc
// if no textid in new route (e.g. edition front) // if no textid in new route (e.g. edition front)
// but we have toc // but we have toc
// get the first item // get the first item
@@ -240,10 +245,10 @@ export default {
.catch((error) => { .catch((error) => {
console.warn('Issue with getTextContent', error) console.warn('Issue with getTextContent', error)
Promise.reject(error) Promise.reject(error)
this.$router.replace({ // this.$router.replace({
name: 'notfound', // name: 'notfound',
query: { fullpath: this.$route.path } // query: { fullpath: this.$route.path }
}) // })
}) })
}, },
onCenterScrolled (e) { onCenterScrolled (e) {
@@ -254,17 +259,19 @@ export default {
this.indexitem = null this.indexitem = null
}, },
nextText ($state) { nextText ($state) {
console.log('infinite loading nextText()', this.texts[this.texts.length - 1].content.itemAfterUuid, $state) console.log('infinite loading nextText()')
if (this.texts[this.texts.length - 1].content.itemAfterUuid) { let indexofnext = this.flattoc.indexOf(this.textsuuids[this.textsuuids.length - 1]) + 1
this.getTextContent(this.texts[this.texts.length - 1].content.itemAfterUuid, $state, 'next') if (indexofnext < this.flattoc.length) {
this.getTextContent(this.flattoc[indexofnext], $state, 'next')
} else { } else {
$state.complete() $state.complete()
} }
}, },
prevText ($state) { prevText ($state) {
console.log('infinite loading prevText()', this.texts[0].content.itemBeforeUuid, $state) console.log('infinite loading prevText()')
if (this.texts[0].content.itemBeforeUuid) { let indexofprev = this.flattoc.indexOf(this.textsuuids[0]) - 1
this.getTextContent(this.texts[0].content.itemBeforeUuid, $state, 'prev') if (indexofprev >= 0) {
this.getTextContent(this.flattoc[indexofprev], $state, 'prev')
} else { } else {
$state.complete() $state.complete()
} }
+1 -1
View File
@@ -54,7 +54,7 @@ export default {
// console.log('buildFlatTocs', i, eduuid) // console.log('buildFlatTocs', i, eduuid)
state.editionsbyuuid[eduuid].flattoc = [] state.editionsbyuuid[eduuid].flattoc = []
recurseFlatToc(state, eduuid, state.editionsbyuuid[eduuid].toc) recurseFlatToc(state, eduuid, state.editionsbyuuid[eduuid].toc)
console.log('buildFlatTocs DONE', eduuid, state.editionsbyuuid[eduuid].flattoc) // console.log('buildFlatTocs DONE', eduuid, state.editionsbyuuid[eduuid].flattoc)
}) })
}, },
setPaginations (state, paginationslist) { setPaginations (state, paginationslist) {