Sfoglia il codice sorgente

:recycle: adjusting calls for random | changing template to accept random from stroe

tags/0.9.0
J 4 anni fa
parent
commit
53e0d0253a

+ 8
- 9
vue-theme/src/pages/index.vue Vedi File

@@ -10,7 +10,7 @@
10 10
             ul.flipped(:class="[`sticky-${Object.keys(allSticky).length}`]")
11 11
                 //- if sticky
12 12
                 li.shadow(v-for="sticky in allSticky")
13
-                    card(:content="sticky" :type="`${sticky.type}s`")
13
+                    card(:content="sticky" :type="`${sticky.type}`")
14 14
         
15 15
         //- firstRow: ['episodes', 'exhibitions', 'events', 'shorts', 'posts'], exceprt on episodes only.
16 16
         section
@@ -21,14 +21,14 @@
21 21
         //- secondRow: 'artists', // This is only ONE post, excerpt on artist
22 22
         section.max
23 23
             ul.w-max
24
-                li.shadow(v-for="post in [randomPostOfType(secondRow)]")
25
-                    card(v-if="post" :content="post" :type="`${post.type}s`" :wide="true")
26
-
24
+                li.shadow(v-for="post in randomPosts.filter(p => p.type == secondRow)")
25
+                    card(v-if="post" :content="post" :type="`${post.type}`" :wide="true")
26
+        
27 27
         //- (thirdRow) firstRow.flipped: ['guides', 'objects', 'techniques', 'talks', 'center'], exceprt on guides only
28 28
         section
29 29
             ul.flipped
30 30
                 li.shadow(v-for="type in thirdRow")
31
-                    .random--wrapper(v-for="post in [randomPostOfType(type)]")
31
+                     .random--wrapper(v-for="post in randomPosts.filter(p => p.type == type)")
32 32
                         card(:content="post" :type="type")
33 33
 </template>
34 34
 
@@ -71,8 +71,7 @@ export default {
71 71
                 }
72 72
             }
73 73
         }
74
-        this.$store.dispatch('getRandom', ['episode', 'exhibition', 'event', 'artist', 'post'])
75
-        
74
+        await this.$store.dispatch('getRandomPosts', ['episode', 'exhibition', 'event', 'artist', 'post'])
76 75
         this.checkAndSetHero('welcome')
77 76
     },
78 77
     methods: {
@@ -95,7 +94,7 @@ export default {
95 94
         },
96 95
         firstPostOfType(type) {
97 96
             return Object.values(this[`all${convertTitleCase(type)}s`])[0]
98
-        }
97
+        },
99 98
     },
100 99
 }
101 100
 </script>
@@ -130,7 +129,7 @@ export default {
130 129
         &.stickies
131 130
             margin: 0 0 2% 0
132 131
         &.max 
133
-            margin: 1.5% 0 2% 0
132
+            margin: 35px 0 20px
134 133
         ul
135 134
             display: grid
136 135
             grid-template-columns: 

+ 3
- 0
vue-theme/src/pages/mixin-post-types.js Vedi File

@@ -22,6 +22,9 @@ getterHelper[`pastEvents`] = `pastEvents`
22 22
 getterHelper[`upcomingAndCurrentExhibitions`] = `upcomingAndCurrentExhibitions`
23 23
 getterHelper[`pastExhibitions`] = `pastExhibitions`
24 24
 
25
+getterHelper[`randomPosts`] = `randomPosts`
26
+getterHelper[`randomPostsLoaded`] = `randomPostsLoaded`
27
+
25 28
 const stateHelper = {}
26 29
 for (let type of postTypes) {
27 30
     stateHelper[type] = type

+ 10
- 13
vue-theme/src/store/actions.js Vedi File

@@ -1,15 +1,12 @@
1 1
 import api from '../utils/api'
2 2
 
3
-// for global actions
4
-export default {
5
-    getRandom({ commit }, types) {
6
-        commit('CLEAR_RANDOM')
7
-        commit('RANDOM_LOADED', false)
8
-        return api.getRandom(types, sortType, randomPosts => {
9
-            console.log('randomPosts')
10
-            console.log(randomPosts)
11
-            commit('STORE_FETCHED_RANDOM', { randomPosts })
12
-            commit('RANDOM_LOADED', true)
13
-        })
14
-    }
15
-}
3
+const getRandomPosts = async ({ commit }, types) => {
4
+    commit('CLEAR_RANDOM')
5
+    commit('RANDOM_LOADED', false)
6
+    return await api.getRandom(types, randomPosts => {
7
+        commit('STORE_FETCHED_RANDOM', { randomPosts })
8
+        commit('RANDOM_LOADED', true)
9
+    })
10
+}
11
+
12
+export { getRandomPosts } 

+ 4
- 5
vue-theme/src/store/getters.js Vedi File

@@ -1,5 +1,4 @@
1
-// For global getters
2
-export default {
3
-    randomPosts: state => state.randomPosts,
4
-    randomPostsLoaded: state => state.randomPostsLoaded,
5
-}
1
+const randomPosts = state => state.randomPosts
2
+const randomPostsLoaded = state => state.randomPostsLoaded
3
+
4
+export { randomPosts, randomPostsLoaded }

+ 5
- 5
vue-theme/src/utils/api.js Vedi File

@@ -51,13 +51,13 @@ export default {
51 51
                 cb(e)
52 52
             })
53 53
     },
54
-    getRandom(types, cb) {
55
-        const randomPosts = []
56
-        for(type in types) {
57
-            axios
54
+    async getRandom(types, cb) {
55
+        let randomPosts = []
56
+        for(let type of types) {
57
+            await axios
58 58
                 .get(SETTINGS.API_BASE_PATH + `${type}?orderby=rand&limit=1`)
59 59
                 .then(response => {
60
-                    randomPosts.push(response.data)
60
+                    randomPosts = [...response.data, ...randomPosts]
61 61
                 })
62 62
         }
63 63
         cb(randomPosts)

Loading…
Annulla
Salva