Quellcode durchsuchen

:poop: starting to redo galleries based on new endpoints

tags/0.9.0
j vor 5 Jahren
Ursprung
Commit
389b4536d4

+ 16
- 20
vue-theme/src/pages/single.vue Datei anzeigen

@@ -5,10 +5,18 @@
5 5
     article.f-grow.shadow
6 6
         header
7 7
             h1 {{ type }}:{{ $route.params.slug }} single
8
+            p {{galleries}}
9
+            p categories: 
10
+                span(v-for="category in posts[$route.params.slug].categories") {{ category }} 
8 11
         section(v-if="posts[$route.params.slug]")
9 12
             h4 {{ posts[$route.params.slug].title }}
10
-            .block-wrapper(v-for="block in posts[$route.params.slug].blocks" v-html="block")
11
-    
13
+            .block-wrapper(v-for="block in posts[$route.params.slug].blocks")
14
+                    .block(v-if="typeof block === 'object'")
15
+                        p gallery {{ block.gallery + 1 }}: 
16
+                        ul
17
+                            li(v-for="imageID in posts[$route.params.slug].galleries[block.gallery].ids") image: {{ imageID }}
18
+                    .block(v-else v-html="block")
19
+
12 20
     sidebar(v-if="sidebar" :type="`${type}`")
13 21
         .shadow
14 22
             h1.t-up single slot
@@ -53,6 +61,10 @@ export default {
53 61
         type() { // Checks for type and fixes Episodes route edge case 
54 62
             return typeFromRoute(this.$route)
55 63
         },
64
+        galleries() {
65
+            if(!this.posts || !this.$route || !this.posts[this.$route.params.slug]) return
66
+            return this.posts[this.$route.params.slug].galleries[block.gallery].ids
67
+        },
56 68
         posts() {
57 69
             let type = convertTitleCase(this.type)
58 70
             
@@ -100,28 +112,12 @@ export default {
100 112
             this.checkForImages(newVal)
101 113
             
102 114
             this.checkAndSetHero(newVal)
103
-            
104
-            // Gottas be on the next render tick
105
-            this.$nextTick(() => {
106
-                let gallery
107
-                this.pageBlocks(newVal).forEach(block => {
108
-                    if(!block) return
109
-                    gallery = document.querySelectorAll('.blocks-gallery-item figure')
110
-                })
111
-                
112
-                if(!gallery || gallery.length < 1) return
113
-
114
-                gallery.forEach((item, i) => {
115
-                    item.addEventListener('mouseup', event => { 
116
-                        this.fullscreengallery = i
117
-                    })
118
-                })
119
-            })
120
-            
115
+            console.log(this.galleries)
121 116
         }
122 117
     },
123 118
     created() {
124 119
         let type = convertTitleCase(this.$route.params.type)
120
+
125 121
         if(!this[`all{type}Loaded`]) {
126 122
             // console.log('Retrieving...', type)
127 123
             this.$store.dispatch(`getAll${type}`)

+ 3
- 2
vue-theme/src/store/index.js Datei anzeigen

@@ -9,7 +9,7 @@ import page from './modules/page'
9 9
 import post from './modules/post'
10 10
 import artist from './modules/artist'
11 11
 import episode from './modules/episode'
12
-
12
+import media from './modules/media'
13 13
 
14 14
 const debug = process.env.NODE_ENV !== 'production'
15 15
 
@@ -45,7 +45,8 @@ const store = new Vuex.Store({
45 45
       post,
46 46
       page,
47 47
       artist,
48
-      episode
48
+      episode,
49
+      media
49 50
   },
50 51
   strict: debug,
51 52
 })

+ 32
- 0
vue-theme/src/store/modules/media.js Datei anzeigen

@@ -0,0 +1,32 @@
1
+import api from '../../utils/api'
2
+
3
+const state = {
4
+    all: {},
5
+    loaded: false,
6
+}
7
+
8
+const getters = {
9
+    allArtists: state => state.all,
10
+    allArtistsLoaded: state => state.loaded,
11
+}
12
+
13
+const actions = {
14
+    getMediaById({ commit }, ids) {
15
+        commit('CLEAR_MEDIA')
16
+        commit('MEDIA_LOADED', false)
17
+        ids.forEach(id => {
18
+            api.getSingleMedia(id, media => {
19
+                commit('STORE_FETCHED_MEDIA', { media })
20
+            })
21
+        })
22
+        commit('MEDIA_LOADED', true) 
23
+    }
24
+}
25
+
26
+const mutations = {
27
+    STORE_FETCHED_MEDIA(state, { media }) { state.all = media },
28
+    CLEAR_MEDIA(state) { state.all = [] },
29
+    MEDIA_LOADED(state, val) { state.loaded = val },
30
+}
31
+
32
+export default { state, getters, actions, mutations }

+ 7
- 0
vue-theme/src/utils/api.js Datei anzeigen

@@ -3,6 +3,7 @@ import axios from 'axios'
3 3
 const SETTINGS = { 
4 4
     LOADING_SEGMENTS: 2,
5 5
     API_BASE_PATH: '/wp-json/craft/v2/',
6
+    API_MEDIA_PATH: '/wp-json/wp/v2/media/',
6 7
 }
7 8
 
8 9
 export default {
@@ -19,6 +20,12 @@ export default {
19 20
             }).catch(e => { cb(e) })
20 21
         }
21 22
     },
23
+    getSingleMedia(id) {
24
+        axios.get(SETTINGS.API_MEDIA_PATH + `${id}`).then(response => {
25
+            cb(response.data)
26
+        }).catch(e => { cb(e) })
27
+    },
28
+
22 29
     getPosts(limit = 5, cb) {
23 30
         axios
24 31
         .get(SETTINGS.API_BASE_PATH + 'posts')

Laden…
Abbrechen
Speichern