Преглед изворни кода

:bug: fixed block flag for gallery

tags/0.9.0
J пре 5 година
родитељ
комит
22edc71a04
3 измењених фајлова са 45 додато и 53 уклоњено
  1. 12
    25
      vue-theme/src/pages/list.vue
  2. 24
    28
      vue-theme/src/pages/single.vue
  3. 9
    0
      vue-theme/src/utils/helpers.js

+ 12
- 25
vue-theme/src/pages/list.vue Прегледај датотеку

@@ -28,6 +28,8 @@
28 28
 import { mapGetters } from 'vuex'
29 29
 import sidebar from '@/components/sidebars/sidebar'
30 30
 
31
+import { convertTitleCase, typeFromRoute } from '@/utils/helpers'
32
+
31 33
 export default {
32 34
     props: {
33 35
         sidebar: {
@@ -37,9 +39,7 @@ export default {
37 39
             type: String
38 40
         }
39 41
     },
40
-    components: {
41
-        sidebar: sidebar
42
-    },
42
+    components: { sidebar },
43 43
     computed: {
44 44
         ...mapGetters({
45 45
             allPages: 'allPages',
@@ -54,19 +54,11 @@ export default {
54 54
             allEpisodes: 'allEpisodes',
55 55
             allEpisodesLoaded: 'allEpisodesLoaded',
56 56
         }),
57
-        allLoaded() {
58
-            const flags = []
59
-            flags.push(this.allPagesLoaded)
60
-            flags.push(this.allPostsLoaded)
61
-            flags.push(this.allArtistsLoaded)
62
-            flags.push(this.allEpisodesLoaded)
63
-            return flags.every(Boolean)
64
-        },
65 57
         type() { // Checks for type and fixes Episodes route edge case 
66
-            return this.$route.params.type ? this.$route.params.type : this.$route.fullPath.slice(1)
58
+            return typeFromRoute(this.$route)
67 59
         },
68 60
         posts() {
69
-            let type = this.convertTitleCase(this.type)
61
+            let type = convertTitleCase(this.type)
70 62
             
71 63
             // We're override the API to sort by date
72 64
             // because items are returned by ID
@@ -79,20 +71,9 @@ export default {
79 71
             return this.sortBy ? this[`all${type}`] : sortedByRecent
80 72
         },
81 73
     },
82
-    methods: {
83
-        convertTitleCase(type) {
84
-            return type.charAt(0).toUpperCase() + type.slice(1)
85
-        }
86
-    },
87
-    created() {
88
-        let type = this.convertTitleCase(this.type)
89
-        
90
-        this.$store.dispatch(`getAll${type}`, this.sortBy)
91
-        this.$store.commit('SET_HERO', type)
92
-    },
93 74
     watch: {
94 75
         $route(to, from){
95
-            let type = this.convertTitleCase(to.path.slice(1))
76
+            let type = convertTitleCase(to.path.slice(1))
96 77
 
97 78
             // Accounts for the sort-by in URL case 
98 79
             let dispatchName = this.sortBy ? `getAll${type.split('/')[0]}` : `getAll${type}`
@@ -102,6 +83,12 @@ export default {
102 83
                 this.$store.commit('SET_HERO', type)
103 84
             }
104 85
         }
86
+    },
87
+    created() {
88
+        let type = convertTitleCase(this.type)
89
+        
90
+        this.$store.dispatch(`getAll${type}`, this.sortBy)
91
+        this.$store.commit('SET_HERO', type)
105 92
     }
106 93
 }
107 94
 </script>

+ 24
- 28
vue-theme/src/pages/single.vue Прегледај датотеку

@@ -19,16 +19,15 @@ import { mapGetters } from 'vuex'
19 19
 import sidebar from '@/components/sidebars/sidebar'
20 20
 import gallery from '@/components/gallery/'
21 21
 
22
+import { convertTitleCase, typeFromRoute } from '@/utils/helpers'
23
+
22 24
 export default {
23 25
     props: {
24 26
         sidebar: {
25 27
             type: Boolean
26 28
         }
27 29
     },
28
-    components: {
29
-        sidebar: sidebar,
30
-        gallery: gallery
31
-    },
30
+    components: { sidebar, gallery },
32 31
     data() {
33 32
         return {
34 33
             images: [], 
@@ -58,10 +57,10 @@ export default {
58 57
             return flags.every(Boolean)
59 58
         },
60 59
         type() { // Checks for type and fixes Episodes route edge case 
61
-            return this.$route.params.type ? this.$route.params.type : this.$route.fullPath.slice(1)
60
+            return typeFromRoute(this.$route)
62 61
         },
63 62
         posts() {
64
-            let type = this.convertTitleCase(this.type)
63
+            let type = convertTitleCase(this.type)
65 64
             
66 65
             if(!type) return []
67 66
             
@@ -73,38 +72,33 @@ export default {
73 72
         }
74 73
     },
75 74
     methods: {
76
-        convertTitleCase(type) {
77
-            return type.charAt(0).toUpperCase() + type.slice(1)
78
-        },
79 75
         pageBlocks(posts) {
80
-            if(this.images.length < 1) return []
76
+            if(!posts) return []
81 77
             return posts[this.$route.params.slug].blocks.map(block => {
82 78
                 if(block) return block
83 79
             })
84 80
         },
85 81
         checkForImages(posts) {
86 82
             if(Object.keys(posts).length == 0) return
87
-
83
+            console.log(posts)
88 84
             this.pageBlocks(posts).forEach(block => {
89
-                if(!block) return
90
-
85
+                console.log(block)
91 86
                 const doc = new DOMParser().parseFromString(block, 'text/html')
92 87
                 const gallery = doc.querySelectorAll('.blocks-gallery-item img')
93
-                
94
-                // add captions
95
-                if(gallery.length) {
96
-                    this.images = [].slice.call(gallery).map(
97
-                        item => { return item.src }
98
-                    )
99
-                }
88
+
89
+                if(!gallery || gallery.length < 1) return
90
+
91
+                this.images = [].slice.call(gallery).map(item => { 
92
+                    return item.src
93
+                })
100 94
             })
101 95
         },
102 96
         checkAndSetHero(posts) {
103 97
             const post = posts[this.$route.params.slug]
104
-            if(post && post.hero){
105
-                const json = JSON.parse(post.hero)
106
-                this.$store.commit('SET_HERO', json)
107
-            }
98
+            if(!post || ! post.hero) return
99
+
100
+            const json = JSON.parse(post.hero)
101
+            this.$store.commit('SET_HERO', json)
108 102
         }
109 103
     },
110 104
     watch: {
@@ -116,16 +110,18 @@ export default {
116 110
             
117 111
             // Gottas be on the next render tick
118 112
             this.$nextTick(() => {
119
-                const blocks = this.pageBlocks(newVal)
120 113
                 let gallery
121
-                blocks.forEach(block => {
114
+                this.pageBlocks(newVal).forEach(block => {
115
+                    if(!block) return
122 116
                     gallery = document.querySelectorAll('.blocks-gallery-item figure')
123 117
                 })
124 118
                 
125 119
                 if(!gallery || gallery.length < 1) return
126 120
 
127 121
                 gallery.forEach((item, i) => {
128
-                    item.addEventListener('mouseup', event => { this.fullscreengallery = i })
122
+                    item.addEventListener('mouseup', event => { 
123
+                        this.fullscreengallery = i
124
+                    })
129 125
                 })
130 126
             })
131 127
             
@@ -133,7 +129,7 @@ export default {
133 129
     },
134 130
     created() {
135 131
         if(!this.allLoaded) {
136
-            let type = this.convertTitleCase(this.$route.params.type)
132
+            let type = convertTitleCase(this.$route.params.type)
137 133
             console.log('Retrieving...', type)
138 134
             this.$store.dispatch(`getAll${type}`)
139 135
         }

+ 9
- 0
vue-theme/src/utils/helpers.js Прегледај датотеку

@@ -0,0 +1,9 @@
1
+const convertTitleCase = (type) => {
2
+    return type.charAt(0).toUpperCase() + type.slice(1)
3
+}
4
+
5
+const typeFromRoute = (route) => {
6
+    return route.params.type ? route.params.type : route.fullPath.slice(1)
7
+}
8
+
9
+export { convertTitleCase, typeFromRoute }

Loading…
Откажи
Сачувај