Kaynağa Gözat

:recyle: cleaning up cruft | fixing up home page | adding better comments

tags/0.9.0
j 5 yıl önce
ebeveyn
işleme
cd6bce14fb

+ 4
- 11
vue-theme/src/app.vue Dosyayı Görüntüle

@@ -8,21 +8,14 @@
8 8
 </template>
9 9
 
10 10
 <script>
11
-import navigation from '@/components/navigation/navigation'
12
-import hero from '@/components/hero'
13
-import footer from '@/components/footer'
11
+import ciaNav from '@/components/navigation/navigation'
12
+import ciaHero from '@/components/hero'
13
+import ciaFooter from '@/components/footer'
14 14
 
15 15
 import '@/sss'
16 16
 
17 17
 export default {
18
-    components: {
19
-        'cia-nav': navigation,
20
-        'cia-hero': hero,
21
-        'cia-footer': footer,
22
-    },
23
-    data () {
24
-        return {}
25
-    }
18
+    components: { ciaNav, ciaHero, ciaFooter }
26 19
 }
27 20
 </script>
28 21
 

+ 12
- 14
vue-theme/src/pages/index.vue Dosyayı Görüntüle

@@ -3,29 +3,27 @@
3 3
 .page--index.f-row.between
4 4
     article.f-grow
5 5
         .f-row
6
-            section(v-if="allEpisodesLoaded && allEpisodes.length").shadow
6
+            section(v-if="allEpisodesLoaded").shadow
7 7
                 router-link(:to="`./episodes`")
8 8
                     h4.t-cap episodes
9
-                router-link(:to="{ path: `/episodes/${Object.values(allEpisodes)[0].slug}` }")
10
-                    p {{ Object.values(allEpisodes)[0].title }}
9
+                    p(v-if="Object.values(allEpisodes).length > 0") {{ Object.values(allEpisodes)[0].slug }}
10
+                    p(v-else) no episodes
11 11
 
12
-            section(v-if="allArtistsLoaded && allArtists.length").shadow
12
+            section(v-if="allArtistsLoaded").shadow
13 13
                 router-link(:to="`./artists`")
14 14
                     h4.t-cap artists
15
-                router-link(:to="{ path: `/artists/${Object.values(allArtists)[0].slug}` }")
16
-                    p {{ Object.values(allArtists)[0].title }}
17
-                    
18
-            section(v-if="allPagesLoaded && allPages.length").shadow
15
+                    p(v-if="Object.values(allArtists).length > 0") {{ Object.values(allArtists)[0].slug}}
16
+                    p(v-else) no artists
17
+
18
+            section(v-if="allPagesLoaded").shadow
19 19
                 h4.t-cap pages
20
-                router-link(:to="{ path: `/pages/${Object.values(allPages)[0].slug}` }")
21
-                    p {{ Object.values(allPages)[0].title }}
22
-        
20
+                    p(v-if="Object.values(allPages).length > 0") {{ Object.values(allPages)[0].slug }}
21
+                    p(v-else) no pages
23 22
         .f-row
24
-            section(v-if="allPostsLoaded && allPosts.length").shadow
23
+            section(v-if="allPostsLoaded").shadow
25 24
                 router-link(:to="`./posts`")
26 25
                     h4.t-cap posts
27
-                router-link(:to="{ path: `/posts/${Object.values(allPosts)[0].slug}` }")
28
-                    p {{ Object.values(allPosts)[0].title }}
26
+                    p(v-if="Object.values(allPosts).length > 0") {{ Object.values(allPosts)[0].slug }}
29 27
      
30 28
         .f-row
31 29
             footer.f-row

+ 49
- 17
vue-theme/src/pages/single.vue Dosyayı Görüntüle

@@ -13,7 +13,7 @@
13 13
                     li(v-for="(imageID, j) in post.galleries[block.gallery].ids" :class="`gallery-${i}--image-${j+1}`" :key="`block-${i}-${j}`")
14 14
                         img(@click="openGallery(i - 1, imageID)" :src="post.attached[imageID]['thumbnail']")
15 15
                         button(@click="openGallery(i - 1, imageID)") gallery: {{ i }} image: {{ imageID }}
16
-                //- Fullscreen gallery
16
+                //- Fullscreen gallery component for every gallery block
17 17
                 gallery(
18 18
                     v-if="activeGalleryIndex == (i - 1)"
19 19
                     :activeImageIndex="activeImageIndex"
@@ -21,7 +21,7 @@
21 21
                     :images="imagesInGallery"
22 22
                 )
23 23
 
24
-            //- Just a regular block
24
+            //- Just a regular block (html or img)
25 25
             .block(v-else v-html="block")
26 26
 
27 27
     sidebar(v-if="sidebar" :type="`${type}`")
@@ -40,22 +40,17 @@ import { convertTitleCase, typeFromRoute } from '@/utils/helpers'
40 40
 
41 41
 export default {
42 42
     props: {
43
-        sidebar: {
44
-            type: Boolean
45
-        }
43
+        sidebar: { type: Boolean }
46 44
     },
47 45
     components: { sidebar, gallery },
48 46
     data() {
49 47
         return {
50
-            images: [], 
48
+            // Gallery control
51 49
             activeGalleryIndex: -1,
52 50
             activeImageID: -1
53 51
         }
54 52
     },
55 53
     computed: {
56
-        post() {
57
-            return this.posts[this.$route.params.slug]
58
-        },
59 54
         ...mapGetters({
60 55
             allPages: 'allPages',
61 56
             allPagesLoaded: 'allPagesLoaded',
@@ -72,6 +67,18 @@ export default {
72 67
         type() { // Checks for type and fixes Episodes route edge case 
73 68
             return typeFromRoute(this.$route)
74 69
         },
70
+
71
+        /**
72
+         * We get the actual post data using the slug
73
+         */
74
+        post() {
75
+            return this.posts[this.$route.params.slug]
76
+        },
77
+        /**
78
+         * We grab posts using the type derived from
79
+         * the route (See typeFromRoute() helper) and
80
+         * create a map keyed by post slug 
81
+         */
75 82
         posts() {
76 83
             let type = convertTitleCase(this.type)
77 84
             
@@ -83,9 +90,19 @@ export default {
83 90
                 return postsMap
84 91
             }, {})
85 92
         },
93
+
94
+        /**
95
+         * We need a convenient way to get all the images
96
+         * broken down by gallery. We use the active gallery
97
+         * image IDs to create a map. We match the ID to the
98
+         * image size and url information returned by post.attached
99
+         */
86 100
         imagesInGallery() {
87 101
             if(!this.activeGalleryIndex < 0) return {}
88
-            
102
+            // Create a map of images by their ID
103
+            // {
104
+            //     imageId: { 'thumbnail': url, 'large': url }
105
+            // }
89 106
             return this.post.galleries[this.activeGalleryIndex].ids.reduce((imageMap, id) => {
90 107
                 imageMap[id] = this.post.attached[id]
91 108
                 return imageMap
@@ -96,10 +113,25 @@ export default {
96 113
         }
97 114
     },
98 115
     methods: {
116
+        /**
117
+         * We set the active gallery to the index.
118
+         * Everything kicks off when activeGallery
119
+         * is set. We also need to set the activeImageID
120
+         * to the image clicked
121
+         * @param {number} galleryIndex
122
+         * @param {string} imageID 
123
+         */
99 124
         openGallery(galleryIndex, imageID) {
100 125
             this.activeGalleryIndex = galleryIndex
101 126
             this.activeImageID = imageID ? imageID : 0
102 127
         },
128
+
129
+        /**
130
+         * Everytime the posts object changes
131
+         * we use this to set a new HERO
132
+         * in vuex
133
+         * @param {object} posts 
134
+         */
103 135
         checkAndSetHero(posts) {
104 136
             const post = posts[this.$route.params.slug]
105 137
             if(!post || !post.hero) return
@@ -110,19 +142,19 @@ export default {
110 142
     },
111 143
     watch: {
112 144
         posts(newVal, oldVal) {
113
-            // Loads images from the DOM
114
-            // this.checkForImages(newVal)
115
-            
116 145
             this.checkAndSetHero(newVal)
117 146
         }
118 147
     },
119 148
     created() {
120
-        let type = convertTitleCase(this.$route.params.type)
121
-        
122
-        if(!this[`all{type}Loaded`]) {
149
+        /**
150
+         * Conditionally load based on post type
151
+         * which is derived from the route
152
+         * !: posts watcher fires when this finishes
153
+         */
154
+        let type = convertTitleCase(this.type)
155
+        if(!this[`all${type}Loaded`]) {
123 156
             // console.log('Retrieving...', type)
124 157
             this.$store.dispatch(`getAll${type}`)
125
-            // posts watcher will fire after this
126 158
         }
127 159
     }
128 160
 }

+ 1
- 3
vue-theme/src/store/index.js Dosyayı Görüntüle

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

+ 0
- 35
vue-theme/src/store/modules/media.js Dosyayı Görüntüle

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

+ 0
- 4
vue-theme/src/utils/post-types.js Dosyayı Görüntüle

@@ -1,4 +0,0 @@
1
-export default [
2
-    'posts',
3
-    'pages'
4
-]

Loading…
İptal
Kaydet