diff options
author | Lukas Eipert <leipert@gitlab.com> | 2019-07-29 18:04:00 +0200 |
---|---|---|
committer | Lukas Eipert <leipert@gitlab.com> | 2019-07-29 18:04:00 +0200 |
commit | 5246626d2cf8bb23e4fb9a7172542573a6e17ba3 (patch) | |
tree | e195e651912acd6f769e86327302de2c888f3c77 /app/assets/javascripts/pdf | |
parent | 6d3b203dd8c0d18535b62eb65054342a5c9cd96c (diff) | |
download | gitlab-ce-5246626d2cf8bb23e4fb9a7172542573a6e17ba3.tar.gz |
Simplify pdf.js logicsh-fix-pdfjs-page-ordering
Instead of complicated splicing, we can simply return all pages.
Promise.all will take care of the correct ordering for us.
Diffstat (limited to 'app/assets/javascripts/pdf')
-rw-r--r-- | app/assets/javascripts/pdf/index.vue | 22 | ||||
-rw-r--r-- | app/assets/javascripts/pdf/page/index.vue | 4 |
2 files changed, 11 insertions, 15 deletions
diff --git a/app/assets/javascripts/pdf/index.vue b/app/assets/javascripts/pdf/index.vue index a0142df0806..2b468aa5744 100644 --- a/app/assets/javascripts/pdf/index.vue +++ b/app/assets/javascripts/pdf/index.vue @@ -14,7 +14,6 @@ export default { }, data() { return { - loading: false, pages: [], }; }, @@ -37,23 +36,18 @@ export default { return pdfjsLib .getDocument(this.document) .then(this.renderPages) - .then(() => this.$emit('pdflabload')) - .catch(error => this.$emit('pdflaberror', error)) - .then(() => { - // Trigger a Vue update: https://vuejs.org/v2/guide/list.html#Caveats - this.pages.splice(this.pages.length); - this.loading = false; + .then(pages => { + this.pages = pages; + this.$emit('pdflabload'); + }) + .catch(error => { + this.$emit('pdflaberror', error); }); }, renderPages(pdf) { const pagePromises = []; - this.loading = true; for (let num = 1; num <= pdf.numPages; num += 1) { - pagePromises.push( - pdf.getPage(num).then(p => { - this.pages[p.pageIndex] = p; - }), - ); + pagePromises.push(pdf.getPage(num)); } return Promise.all(pagePromises); }, @@ -65,8 +59,8 @@ export default { <div v-if="hasPDF" class="pdf-viewer"> <page v-for="(page, index) in pages" + v-if="page" :key="index" - :v-if="!loading" :page="page" :number="index + 1" /> diff --git a/app/assets/javascripts/pdf/page/index.vue b/app/assets/javascripts/pdf/page/index.vue index f16aaca6cd7..d933fdf220a 100644 --- a/app/assets/javascripts/pdf/page/index.vue +++ b/app/assets/javascripts/pdf/page/index.vue @@ -39,7 +39,9 @@ export default { .then(() => { this.rendering = false; }) - .catch(error => this.$emit('pdflaberror', error)); + .catch(error => { + this.$emit('pdflaberror', error); + }); }, }; </script> |