浏览代码

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

tags/0.9.0
J 4 年前
父节点
当前提交
53e0d0253a

+ 8
- 9
vue-theme/src/pages/index.vue 查看文件

10
             ul.flipped(:class="[`sticky-${Object.keys(allSticky).length}`]")
10
             ul.flipped(:class="[`sticky-${Object.keys(allSticky).length}`]")
11
                 //- if sticky
11
                 //- if sticky
12
                 li.shadow(v-for="sticky in allSticky")
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
         //- firstRow: ['episodes', 'exhibitions', 'events', 'shorts', 'posts'], exceprt on episodes only.
15
         //- firstRow: ['episodes', 'exhibitions', 'events', 'shorts', 'posts'], exceprt on episodes only.
16
         section
16
         section
21
         //- secondRow: 'artists', // This is only ONE post, excerpt on artist
21
         //- secondRow: 'artists', // This is only ONE post, excerpt on artist
22
         section.max
22
         section.max
23
             ul.w-max
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
         //- (thirdRow) firstRow.flipped: ['guides', 'objects', 'techniques', 'talks', 'center'], exceprt on guides only
27
         //- (thirdRow) firstRow.flipped: ['guides', 'objects', 'techniques', 'talks', 'center'], exceprt on guides only
28
         section
28
         section
29
             ul.flipped
29
             ul.flipped
30
                 li.shadow(v-for="type in thirdRow")
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
                         card(:content="post" :type="type")
32
                         card(:content="post" :type="type")
33
 </template>
33
 </template>
34
 
34
 
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
         this.checkAndSetHero('welcome')
75
         this.checkAndSetHero('welcome')
77
     },
76
     },
78
     methods: {
77
     methods: {
95
         },
94
         },
96
         firstPostOfType(type) {
95
         firstPostOfType(type) {
97
             return Object.values(this[`all${convertTitleCase(type)}s`])[0]
96
             return Object.values(this[`all${convertTitleCase(type)}s`])[0]
98
-        }
97
+        },
99
     },
98
     },
100
 }
99
 }
101
 </script>
100
 </script>
130
         &.stickies
129
         &.stickies
131
             margin: 0 0 2% 0
130
             margin: 0 0 2% 0
132
         &.max 
131
         &.max 
133
-            margin: 1.5% 0 2% 0
132
+            margin: 35px 0 20px
134
         ul
133
         ul
135
             display: grid
134
             display: grid
136
             grid-template-columns: 
135
             grid-template-columns: 

+ 3
- 0
vue-theme/src/pages/mixin-post-types.js 查看文件

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

+ 10
- 13
vue-theme/src/store/actions.js 查看文件

1
 import api from '../utils/api'
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 查看文件

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 查看文件

51
                 cb(e)
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
                 .get(SETTINGS.API_BASE_PATH + `${type}?orderby=rand&limit=1`)
58
                 .get(SETTINGS.API_BASE_PATH + `${type}?orderby=rand&limit=1`)
59
                 .then(response => {
59
                 .then(response => {
60
-                    randomPosts.push(response.data)
60
+                    randomPosts = [...response.data, ...randomPosts]
61
                 })
61
                 })
62
         }
62
         }
63
         cb(randomPosts)
63
         cb(randomPosts)

正在加载...
取消
保存