Parcourir la source

:bug: fixed race condition in gallery parsing

tags/0.9.0
J il y a 5 ans
Parent
révision
8b8b0ba07b

+ 13
- 10
vue-theme/src/pages/list.vue Voir le fichier

29
 import { mapGetters } from 'vuex'
29
 import { mapGetters } from 'vuex'
30
 import sidebar from '@/components/sidebars/sidebar'
30
 import sidebar from '@/components/sidebars/sidebar'
31
 
31
 
32
-import { convertTitleCase, typeFromRoute } from '@/utils/helpers'
32
+import { convertTitleCase, typeFromRoute, sortTypes } from '@/utils/helpers'
33
 
33
 
34
 export default {
34
 export default {
35
     props: {
35
     props: {
81
 
81
 
82
             // Accounts for the sort-by in URL case 
82
             // Accounts for the sort-by in URL case 
83
             let dispatchName = this.sortBy ? `getAll${type.split('/')[0]}` : `getAll${type}`
83
             let dispatchName = this.sortBy ? `getAll${type.split('/')[0]}` : `getAll${type}`
84
-            this.$store.dispatch(dispatchName, this.sortBy)
85
             
84
             
85
+            // Seperate sorting from post slugs
86
+            if(Object.values(sortTypes).indexOf(this.sortBy) >= 0) {
87
+                this.$store.dispatch(dispatchName, this.sortBy)
88
+            }
86
             if(this.$store.state.hero.url !== type) {
89
             if(this.$store.state.hero.url !== type) {
87
                 this.$store.commit('SET_HERO', type)
90
                 this.$store.commit('SET_HERO', type)
88
             }
91
             }
93
         
96
         
94
         this.$store.dispatch(`getAll${type}`, this.sortBy)
97
         this.$store.dispatch(`getAll${type}`, this.sortBy)
95
         this.$store.commit('SET_HERO', type)
98
         this.$store.commit('SET_HERO', type)
96
-        console.log(this.isGrid)
97
     }
99
     }
98
 }
100
 }
99
 </script>
101
 </script>
100
 
102
 
101
 <style lang="postcss">
103
 <style lang="postcss">
102
-article
103
-    .is-grid
104
-        display: flex
105
-        flex-direction: row
106
-        section
107
-            width: 33%
108
-
104
+.page--list
105
+    article
106
+        .is-grid
107
+            display: flex
108
+            flex-direction: row
109
+            flex-wrap: wrap
110
+            section
111
+                width: 33%
109
 </style>
112
 </style>

+ 5
- 6
vue-theme/src/pages/single.vue Voir le fichier

73
     },
73
     },
74
     methods: {
74
     methods: {
75
         pageBlocks(posts) {
75
         pageBlocks(posts) {
76
-            if(!posts || !posts[this.$route.params.slug]) return []
76
+            if(!posts || !posts[this.$route.params.slug] || !posts[this.$route.params.slug].blocks ) return []
77
+            
77
             return posts[this.$route.params.slug].blocks.map(block => {
78
             return posts[this.$route.params.slug].blocks.map(block => {
78
                 if(block) return block
79
                 if(block) return block
79
             })
80
             })
80
         },
81
         },
81
         checkForImages(posts) {
82
         checkForImages(posts) {
82
             if(Object.keys(posts).length == 0) return
83
             if(Object.keys(posts).length == 0) return
83
-            console.log(posts)
84
             this.pageBlocks(posts).forEach(block => {
84
             this.pageBlocks(posts).forEach(block => {
85
-                console.log(block)
86
                 const doc = new DOMParser().parseFromString(block, 'text/html')
85
                 const doc = new DOMParser().parseFromString(block, 'text/html')
87
                 const gallery = doc.querySelectorAll('.blocks-gallery-item img')
86
                 const gallery = doc.querySelectorAll('.blocks-gallery-item img')
88
 
87
 
128
         }
127
         }
129
     },
128
     },
130
     created() {
129
     created() {
131
-        if(!this.allLoaded) {
132
-            let type = convertTitleCase(this.$route.params.type)
133
-            console.log('Retrieving...', type)
130
+        let type = convertTitleCase(this.$route.params.type)
131
+        if(!this[`all{type}Loaded`]) {
132
+            // console.log('Retrieving...', type)
134
             this.$store.dispatch(`getAll${type}`)
133
             this.$store.dispatch(`getAll${type}`)
135
         }
134
         }
136
     }
135
     }

+ 3
- 2
vue-theme/src/utils/api.js Voir le fichier

7
 
7
 
8
 export default {
8
 export default {
9
     getByType(type, sortType, cb) {
9
     getByType(type, sortType, cb) {
10
-        console.log('sortType:', sortType)
11
         if (sortType) {
10
         if (sortType) {
12
             axios.get(SETTINGS.API_BASE_PATH + `sort/${type}/${sortType}`).then(response => {
11
             axios.get(SETTINGS.API_BASE_PATH + `sort/${type}/${sortType}`).then(response => {
13
                 cb(response.data)
12
                 cb(response.data)
14
             }).catch(e => { cb(e) })
13
             }).catch(e => { cb(e) })
15
-        } else {
14
+        }
15
+
16
+        else {
16
             axios.get(SETTINGS.API_BASE_PATH + `${type}`).then(response => {
17
             axios.get(SETTINGS.API_BASE_PATH + `${type}`).then(response => {
17
                 cb(response.data)
18
                 cb(response.data)
18
             }).catch(e => { cb(e) })
19
             }).catch(e => { cb(e) })

+ 7
- 1
vue-theme/src/utils/helpers.js Voir le fichier

6
     return route.params.type ? route.params.type : route.fullPath.slice(1)
6
     return route.params.type ? route.params.type : route.fullPath.slice(1)
7
 }
7
 }
8
 
8
 
9
-export { convertTitleCase, typeFromRoute }
9
+const sortTypes = {
10
+    alpha: 'by-alpha',
11
+    recent: 'by-recent',
12
+    material: 'by-material',
13
+}
14
+
15
+export { convertTitleCase, typeFromRoute, sortTypes }

Chargement…
Annuler
Enregistrer