Преглед изворни кода

:recycle: using destructured dispatch to pass api limits

tags/0.9.0
J пре 4 година
родитељ
комит
d0a942b05f

+ 3
- 1
vue-theme/src/components/sidebars/events.vue Прегледај датотеку

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

+ 8
- 5
vue-theme/src/pages/index.vue Прегледај датотеку

56
 
56
 
57
             // Limit the amount of posts because we
57
             // Limit the amount of posts because we
58
             // only need the most recent
58
             // only need the most recent
59
-            const paramLimit = { limit: 1 }
60
-
59
+            const params = { limit: 1 }
60
+            console.log(action)
61
             // We try and fetch EVERYTHING except
61
             // We try and fetch EVERYTHING except
62
             // for EVENTS and EXHIBITIONS
62
             // for EVENTS and EXHIBITIONS
63
             if (!omit.includes(type)) {
63
             if (!omit.includes(type)) {
64
-                this.$store.dispatch(action, null, paramLimit)
64
+                this.$store.dispatch(action, { sortType: null, params })
65
             } else {
65
             } else {
66
                 // Only grab the current or upcoming on load
66
                 // Only grab the current or upcoming on load
67
                 const eventsOrExhibitions = await this.$store.dispatch(
67
                 const eventsOrExhibitions = await this.$store.dispatch(
68
                     action,
68
                     action,
69
-                    sortTypes.currentAndUpcoming,
69
+                    { 
70
+                        sortType: sortTypes.currentAndUpcoming,
71
+                        params
72
+                    }
70
                 )
73
                 )
71
                 // If no current or upcoming, get past events
74
                 // If no current or upcoming, get past events
72
                 // to fill in the blanks
75
                 // to fill in the blanks
73
                 if (eventsOrExhibitions.length < 1) {
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 Прегледај датотеку

83
 
83
 
84
             // Don't dispatch if there's no type
84
             // Don't dispatch if there's no type
85
             if (this.type && this.dispatchName) {
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
                 if (this.type == 'event') {
88
                 if (this.type == 'event') {
89
                     this.$store.dispatch(
89
                     this.$store.dispatch(
90
                         'getAllExhibitions',
90
                         'getAllExhibitions',
91
-                        sortTypes.currentAndUpcoming,
92
-                        params
91
+                        {
92
+                            sortType: sortTypes.currentAndUpcoming,
93
+                            params 
94
+                        }
93
                     )
95
                     )
94
                 }
96
                 }
95
                 if (this.type == 'exhibition') {
97
                 if (this.type == 'exhibition') {
96
                     this.$store.dispatch(
98
                     this.$store.dispatch(
97
                         'getAllEvents',
99
                         'getAllEvents',
98
-                        sortTypes.currentAndUpcoming,
99
-                        params
100
+                        {
101
+                            sortType: sortTypes.currentAndUpcoming,
102
+                            params 
103
+                        }
100
                     )
104
                     )
101
                 }
105
                 }
102
             }
106
             }
112
             const page = this.allPages.filter(
116
             const page = this.allPages.filter(
113
                 page => page.slug == type + 's',
117
                 page => page.slug == type + 's',
114
             )[0]
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
             if (
126
             if (
118
                 page.hero &&
127
                 page.hero &&
119
                 JSON.parse(page.hero) &&
128
                 JSON.parse(page.hero) &&

+ 4
- 3
vue-theme/src/store/modules/artist.js Прегледај датотеку

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

+ 4
- 3
vue-theme/src/store/modules/episode.js Прегледај датотеку

20
     getAllEpisodes({ commit }, sortType) {
20
     getAllEpisodes({ commit }, sortType) {
21
         commit('CLEAR_EPISODES')
21
         commit('CLEAR_EPISODES')
22
         commit('EPISODES_LOADED', false)
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
     getSingleEpisode({ commit }, id) {
29
     getSingleEpisode({ commit }, id) {

+ 3
- 3
vue-theme/src/store/modules/event.js Прегледај датотеку

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

+ 3
- 3
vue-theme/src/store/modules/exhibition.js Прегледај датотеку

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

+ 4
- 3
vue-theme/src/store/modules/page.js Прегледај датотеку

17
 const actions = {
17
 const actions = {
18
     async getAllPages({ commit }, sortType) {
18
     async getAllPages({ commit }, sortType) {
19
         commit('PAGES_LOADED', false)
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
     getSinglePage({ commit }, id) {
26
     getSinglePage({ commit }, id) {

+ 3
- 3
vue-theme/src/store/modules/post.js Прегледај датотеку

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

+ 7
- 8
vue-theme/src/utils/api.js Прегледај датотеку

8
 }
8
 }
9
 
9
 
10
 export default {
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
             return axios
16
             return axios
14
-                .get(SETTINGS.API_BASE_PATH + `sort/${type}/${sortType}`)
17
+                .get(SETTINGS.API_BASE_PATH + `sort/${type}/${sort}${query}`)
15
                 .then(response => {
18
                 .then(response => {
16
                     cb(response.data)
19
                     cb(response.data)
17
                     return response.data
20
                     return response.data
20
                     cb(e)
23
                     cb(e)
21
                 })
24
                 })
22
         } else {
25
         } else {
23
-            let query = `${type}`
24
-            if(params && params.limit) {
25
-                query = `${type}?limit=${params.limit}`
26
-            }
27
             return axios
26
             return axios
28
-                .get(SETTINGS.API_BASE_PATH + query)
27
+                .get(SETTINGS.API_BASE_PATH + `${type}${query}`)
29
                 .then(response => {
28
                 .then(response => {
30
                     cb(response.data)
29
                     cb(response.data)
31
                     return response.data
30
                     return response.data

Loading…
Откажи
Сачувај