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

:bug: clearing dom before rebuilding nodes in rblock

tags/0.9.0
J пре 5 година
родитељ
комит
3476bc5b1f

+ 33
- 16
vue-theme/src/components/content-block/block-recursive.vue Прегледај датотеку

@@ -3,6 +3,8 @@
3 3
 </template>
4 4
 
5 5
 <script>
6
+let treeToAppend = null
7
+
6 8
 export default {
7 9
     name: 'rblock',
8 10
     props: {
@@ -10,6 +12,7 @@ export default {
10 12
     },
11 13
     data() {
12 14
         return {
15
+            isLoading: true,
13 16
             id: null,
14 17
             root: null,
15 18
             treeDepth: 0,
@@ -62,25 +65,39 @@ export default {
62 65
 
63 66
             this.treeDepth--
64 67
         },
65
-    },
66
-    mounted() {
67
-        if(typeof this.block !== 'object' || this.block.hasOwnProperty('gallery')) return
68
+        buildBlocks() {
69
+            if(typeof this.block !== 'object' || this.block.hasOwnProperty('gallery')) return
68 70
 
69
-        // Add the top-level blocks to the document tree
70
-        const tree = new DocumentFragment()
71
-        this.root = document.createElement('div')
72
-        // console.log(this.block)
73
-        this.root.classList.add('wp-block-columns')
74
-        tree.appendChild(this.root)
75
-
76
-        // Loop over all the nodes and append children
77
-        for(const block of this.block) {
78
-            this.processBlock(block, this.root)
79
-        }
71
+            // Add the top-level blocks to the document tree
72
+            treeToAppend = new DocumentFragment()
73
+            this.root = document.createElement('div')
74
+            // console.log(this.block)
75
+            this.root.classList.add('wp-block-columns')
76
+            treeToAppend.appendChild(this.root)
80 77
 
78
+            // Loop over all the nodes and append children
79
+            if(this.block.length == 1) {
80
+                for(const block of this.block) {
81
+                    this.processBlock(block, this.root)
82
+                }
83
+            }
84
+            else {
85
+                console.warn('more than one block in here')
86
+            }
87
+        },
88
+    },
89
+    mounted() {
81 90
         // Append the final product to DOM
82
-        document.getElementById(`block-${this.$.uid}`).appendChild(tree)
83
-
91
+        this.buildBlocks()
92
+        document.getElementById(`block-${this.$.uid}`).innerHTML = ''
93
+        document.getElementById(`block-${this.$.uid}`).appendChild(treeToAppend)
94
+    },
95
+    watch: {
96
+        block(newVal, oldVal) {
97
+            this.buildBlocks()
98
+            document.getElementById(`block-${this.$.uid}`).innerHTML = ''
99
+            document.getElementById(`block-${this.$.uid}`).appendChild(treeToAppend)
100
+        }
84 101
     }
85 102
 }
86 103
 </script>

+ 5
- 5
vue-theme/src/components/content-block/block.vue Прегледај датотеку

@@ -12,10 +12,10 @@ figure.block.embed(v-if="block[0].blockName == 'core/embed'")
12 12
 
13 13
 //- Block clicking on certain block elements
14 14
 //- so we can choose when to open the gallery
15
-rblock(v-else-if="typeof block === 'object'" :block="block" @click.prevent.stop="openGallery")
15
+rblock(:block="block" @click.prevent.stop="openGallery")
16 16
 
17
-.block.single(v-else)
18
-    .single--content(v-html="block")
17
+//- .block.single(v-else)
18
+//-     .single--content(v-html="block")
19 19
 </template>
20 20
 
21 21
 <script>
@@ -28,10 +28,10 @@ export default {
28 28
     },
29 29
     methods: {
30 30
         fixYoutubeUrl(url) {
31
-            let videoUid = url.split('https://youtu.be/').filter(pieces => pieces.length > 0)[0]
31
+            let videoUid = url.split('https://youtu.be/')[1]
32 32
 
33 33
             if(!videoUid) {
34
-                videoUid = url.split('https://www.youtube.com/watch?v=').filter(pieces => pieces.length > 0)[0]
34
+                videoUid = url.split('https://www.youtube.com/watch?v=')[1]
35 35
             }
36 36
 
37 37
             return `https://www.youtube.com/embed/${videoUid}`

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

@@ -72,15 +72,17 @@ export default {
72 72
 
73 73
             let sort = this.sortBy ? this.sortBy : this.$route.path.split('/').pop()
74 74
             
75
-            console.log('trying to sort by:, sort')
75
+            console.log('trying to sort by:', sort)
76
+            console.log('includes:', Object.values(sortTypes).includes(sort))
76 77
 
77
-            // Seperate sorting from post slugs
78
-            if(sort && Object.values(sortTypes).includes(sort)) { 
79
-                // Don't dispatch if there's no type
80
-                if(this.type) {
81
-                    this.$store.dispatch(this.dispatchName, sort)
82
-                }
78
+            // Is this a sort type?
79
+            if(this.type !== sort || !Object.values(sortTypes).includes(sort)) sort = null
80
+            
81
+            // Don't dispatch if there's no type
82
+            if(this.type) {
83
+                this.$store.dispatch(this.dispatchName, sort)
83 84
             }
85
+            
84 86
             if(this.$store.state.hero.url !== type) this.$store.commit('SET_HERO', type)
85 87
         }
86 88
     },
@@ -88,6 +90,7 @@ export default {
88 90
         $route(to, from){
89 91
             let type = convertTitleCase(this.type)
90 92
             let sort = this.sortBy ? this.sortBy : to.path.split('/').pop()
93
+            
91 94
             if(!this[`all${type}Loaded`] || sort) this.setHeroAndGetPosts()
92 95
         }
93 96
     },

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

@@ -18,7 +18,7 @@
18 18
 
19 19
         block.post-single.block-wrapper(v-for="(block, index) in post.blocks" :block="block" @open-gallery="openGallery" :key="`block-${index}`")
20 20
 
21
-        credits(v-if="type === 'episodes'" :post="post")
21
+        credits(v-if="type === 'episodes' && post" :post="post")
22 22
 
23 23
     sidebar(v-if="sidebar" :type="`${type}`" layout="single")
24 24
         .shadow(v-if="Object.keys(p2pPostsByType).length" v-for="p2pPostType in Object.keys(p2pPostsByType)")
@@ -153,6 +153,9 @@ export default {
153 153
              * !: posts watcher fires when this finishes
154 154
              */
155 155
             let type = convertTitleCase(this.type)
156
+            
157
+            if(!this.$store.state[this.type]) return 
158
+
156 159
             let allPostsOfType = this.$store.state[this.type].all
157 160
 
158 161
             /**

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