Explorar el Código

:recycle: using destructured dispatch to pass api limits

tags/0.9.0
J hace 4 años
padre
commit
d0a942b05f

+ 3
- 1
vue-theme/src/components/sidebars/events.vue Ver fichero

@@ -34,7 +34,9 @@ export default {
34 34
         async getPosts() {
35 35
             const upcoming = this.$store.dispatch(
36 36
                 `getAllEvents`,
37
-                sortTypes.currentAndUpcoming,
37
+                {
38
+                    sortType: sortTypes.currentAndUpcoming
39
+                }
38 40
             )
39 41
             if (upcoming.length < 1) {
40 42
                 // this.listType = 'past'

+ 8
- 5
vue-theme/src/pages/index.vue Ver fichero

@@ -56,22 +56,25 @@ export default {
56 56
 
57 57
             // Limit the amount of posts because we
58 58
             // only need the most recent
59
-            const paramLimit = { limit: 1 }
60
-
59
+            const params = { limit: 1 }
60
+            console.log(action)
61 61
             // We try and fetch EVERYTHING except
62 62
             // for EVENTS and EXHIBITIONS
63 63
             if (!omit.includes(type)) {
64
-                this.$store.dispatch(action, null, paramLimit)
64
+                this.$store.dispatch(action, { sortType: null, params })
65 65
             } else {
66 66
                 // Only grab the current or upcoming on load
67 67
                 const eventsOrExhibitions = await this.$store.dispatch(
68 68
                     action,
69
-                    sortTypes.currentAndUpcoming,
69
+                    { 
70
+                        sortType: sortTypes.currentAndUpcoming,
71
+                        params
72
+                    }
70 73
                 )
71 74
                 // If no current or upcoming, get past events
72 75
                 // to fill in the blanks
73 76
                 if (eventsOrExhibitions.length < 1) {
74
-                    this.$store.dispatch(action, sortTypes.past, paramLimit)
77
+                    this.$store.dispatch(action, { sortType: sortTypes.past, params })
75 78
                 }
76 79
             }
77 80
         }

+ 15
- 6
vue-theme/src/pages/list.vue Ver fichero

@@ -83,20 +83,24 @@ export default {
83 83
 
84 84
             // Don't dispatch if there's no type
85 85
             if (this.type && this.dispatchName) {
86
-                this.$store.dispatch(this.dispatchName, sort, params)
86
+                this.$store.dispatch(this.dispatchName, { sortType: sort, params })
87 87
 
88 88
                 if (this.type == 'event') {
89 89
                     this.$store.dispatch(
90 90
                         'getAllExhibitions',
91
-                        sortTypes.currentAndUpcoming,
92
-                        params
91
+                        {
92
+                            sortType: sortTypes.currentAndUpcoming,
93
+                            params 
94
+                        }
93 95
                     )
94 96
                 }
95 97
                 if (this.type == 'exhibition') {
96 98
                     this.$store.dispatch(
97 99
                         'getAllEvents',
98
-                        sortTypes.currentAndUpcoming,
99
-                        params
100
+                        {
101
+                            sortType: sortTypes.currentAndUpcoming,
102
+                            params 
103
+                        }
100 104
                     )
101 105
                 }
102 106
             }
@@ -112,8 +116,13 @@ export default {
112 116
             const page = this.allPages.filter(
113 117
                 page => page.slug == type + 's',
114 118
             )[0]
119
+            const blankHero = { url: null, heroType: null }
120
+            // Clear the hero and bail
121
+            if(!page) return this.$store.commit('SET_HERO', blankHero)
115 122
 
116
-            let json = { url: page.featured, heroType: 'image' }
123
+            blankHero.url = page.featured
124
+            blankHero.heroType = 'image'
125
+            let json = hero = blankHero
117 126
             if (
118 127
                 page.hero &&
119 128
                 JSON.parse(page.hero) &&

+ 4
- 3
vue-theme/src/store/modules/artist.js Ver fichero

@@ -17,13 +17,14 @@ const getters = {
17 17
 }
18 18
 
19 19
 const actions = {
20
-    getAllArtists({ commit }, sortType, params) {
20
+    getAllArtists({ commit }, { sortType, params }) {
21 21
         commit('CLEAR_ARTISTS')
22 22
         commit('ARTISTS_LOADED', false)
23
-        return api.getByType('artist', sortType, artists => {
23
+        const storeFetch = (artists => {
24 24
             commit('STORE_FETCHED_ARTISTS', { artists })
25 25
             commit('ARTISTS_LOADED', true)
26
-        }, params)
26
+        })
27
+        return api.getByType({ type: 'artist', sort: sortType, params, cb: storeFetch })
27 28
     },
28 29
     getSingleArtist({ commit }, id) {
29 30
         commit('CLEAR_SINGLE_ARTISTS')

+ 4
- 3
vue-theme/src/store/modules/episode.js Ver fichero

@@ -20,9 +20,10 @@ const actions = {
20 20
     getAllEpisodes({ commit }, sortType) {
21 21
         commit('CLEAR_EPISODES')
22 22
         commit('EPISODES_LOADED', false)
23
-        return api.getByType('episode', sortType, episodes => {
24
-            commit('STORE_FETCHED_EPISODES', { episodes })
25
-            commit('EPISODES_LOADED', true)
23
+        return api.getByType({ type: 'episode', sort: sortType, cb: episodes => {
24
+                commit('STORE_FETCHED_EPISODES', { episodes })
25
+                commit('EPISODES_LOADED', true)
26
+            }
26 27
         })
27 28
     },
28 29
     getSingleEpisode({ commit }, id) {

+ 3
- 3
vue-theme/src/store/modules/event.js Ver fichero

@@ -24,13 +24,13 @@ const getters = {
24 24
 }
25 25
 
26 26
 const actions = {
27
-    getAllEvents({ commit }, sortType, params) {
27
+    getAllEvents({ commit }, { sortType, params }) {
28 28
         commit('CLEAR_EVENTS')
29 29
         commit('EVENTS_LOADED', false)
30
-        return api.getByType('event', sortType, events => {
30
+        return api.getByType({ type: 'event', sort: sortType, cb: events => {
31 31
             commit('STORE_FETCHED_EVENTS', { events })
32 32
             commit('EVENTS_LOADED', true)
33
-        }, params)
33
+        }, params })
34 34
     },
35 35
     getSingleEvent({ commit }, id) {
36 36
         commit('CLEAR_SINGLE_EVENTS')

+ 3
- 3
vue-theme/src/store/modules/exhibition.js Ver fichero

@@ -26,13 +26,13 @@ const getters = {
26 26
 }
27 27
 
28 28
 const actions = {
29
-    getAllExhibitions({ commit }, sortType, params) {
29
+    getAllExhibitions({ commit },{ sortType, params }) {
30 30
         commit('CLEAR_EXHIBITIONS')
31 31
         commit('EXHIBITIONS_LOADED', false)
32
-        return api.getByType('exhibition', sortType, exhibitions => {
32
+        return api.getByType({ type: 'exhibition', sort: sortType, cb: exhibitions => {
33 33
             commit('STORE_FETCHED_EXHIBITIONS', { exhibitions })
34 34
             commit('EXHIBITIONS_LOADED', true)
35
-        }, params)
35
+        }, params })
36 36
     },
37 37
     getSingleExhibition({ commit }, id) {
38 38
         commit('CLEAR_SINGLE_EXHIBITIONS')

+ 4
- 3
vue-theme/src/store/modules/page.js Ver fichero

@@ -17,9 +17,10 @@ const getters = {
17 17
 const actions = {
18 18
     async getAllPages({ commit }, sortType) {
19 19
         commit('PAGES_LOADED', false)
20
-        return await api.getByType('page', sortType, pages => {
21
-            commit('STORE_FETCHED_PAGES', { pages })
22
-            commit('PAGES_LOADED', true)
20
+        return await api.getByType({ type: 'page', sort: sortType, cb: pages => {
21
+                commit('STORE_FETCHED_PAGES', { pages })
22
+                commit('PAGES_LOADED', true)
23
+            }
23 24
         })
24 25
     },
25 26
     getSinglePage({ commit }, id) {

+ 3
- 3
vue-theme/src/store/modules/post.js Ver fichero

@@ -12,13 +12,13 @@ const getters = {
12 12
 }
13 13
 
14 14
 const actions = {
15
-    getAllPosts({ commit }, sortType, params) {
15
+    getAllPosts({ commit },{ sortType, params }) {
16 16
         commit('CLEAR_POSTS')
17 17
         commit('POSTS_LOADED', false)
18
-        return api.getByType('post', sortType, posts => {
18
+        return api.getByType({ type: 'post', sort: sortType, cb: posts => {
19 19
             commit('STORE_FETCHED_POSTS', { posts })
20 20
             commit('POSTS_LOADED', true)
21
-        }, params)
21
+        }, params })
22 22
     },
23 23
     getSinglePost({ commit }, id) {
24 24
         commit('CLEAR_SINGLE_POSTS')

+ 7
- 8
vue-theme/src/utils/api.js Ver fichero

@@ -8,10 +8,13 @@ const SETTINGS = {
8 8
 }
9 9
 
10 10
 export default {
11
-    getByType(type, sortType, cb, params) {
12
-        if (sortType && Object.values(sortTypes).includes(sortType)) {
11
+    getByType({ type, sort, params, cb }) {
12
+        let query = params && params.limit ? `?limit=${params.limit}`: ''
13
+        console.log('params')
14
+        console.log(params)
15
+        if (sort && Object.values(sortTypes).includes(sort)) {
13 16
             return axios
14
-                .get(SETTINGS.API_BASE_PATH + `sort/${type}/${sortType}`)
17
+                .get(SETTINGS.API_BASE_PATH + `sort/${type}/${sort}${query}`)
15 18
                 .then(response => {
16 19
                     cb(response.data)
17 20
                     return response.data
@@ -20,12 +23,8 @@ export default {
20 23
                     cb(e)
21 24
                 })
22 25
         } else {
23
-            let query = `${type}`
24
-            if(params && params.limit) {
25
-                query = `${type}?limit=${params.limit}`
26
-            }
27 26
             return axios
28
-                .get(SETTINGS.API_BASE_PATH + query)
27
+                .get(SETTINGS.API_BASE_PATH + `${type}${query}`)
29 28
                 .then(response => {
30 29
                     cb(response.data)
31 30
                     return response.data

Loading…
Cancelar
Guardar