Browse Source

:sparkles: turning on shorts, guides, objects, publications

:sparkles: adding new types to frontend

:recycle: added new types to store
tags/0.9.0
J 4 years ago
parent
commit
db7a9b9f43

+ 20
- 2
plugins/cia-endpoints/cia-end-points.php View File

@@ -26,10 +26,8 @@ add_action( 'rest_api_init', function () {
26 26
      */
27 27
     $page_controller = new Make_Endpoint_For('page');
28 28
     $page_controller->register_custom_route('page');
29
-
30 29
     $media_controller = new Make_Endpoint_For('media');
31 30
     $media_controller->register_custom_route('media');
32
-
33 31
     $post_controller = new Make_Endpoint_For('post');
34 32
     $post_controller->register_custom_route('post');
35 33
 
@@ -48,6 +46,18 @@ add_action( 'rest_api_init', function () {
48 46
     $exhibition_controller = new Make_Endpoint_For('exhibition');
49 47
     $exhibition_controller->register_custom_route('exhibition');
50 48
 
49
+    $guide_controller = new Make_Endpoint_For('guide');
50
+    $guide_controller->register_custom_route('guide');
51
+
52
+    $short_controller = new Make_Endpoint_For('short');
53
+    $short_controller->register_custom_route('short');
54
+
55
+    $object_controller = new Make_Endpoint_For('object');
56
+    $object_controller->register_custom_route('object');
57
+
58
+    $publication_controller = new Make_Endpoint_For('publication');
59
+    $publication_controller->register_custom_route('publication');
60
+
51 61
     $sticky_controller = new Make_Sticky_Endpoint();
52 62
     $sticky_controller->register_custom_route('sticky');
53 63
 
@@ -95,6 +105,14 @@ add_filter('wp_rest_cache/allowed_endpoints', function () {
95 105
         $allowed_endpoints['craft/v2'][] = 'exhibition';
96 106
     if ( !isset($allowed_endpoints['craft/v2']) || !in_array('artist', $allowed_endpoints['craft/v2']) )
97 107
         $allowed_endpoints['craft/v2'][] = 'artist';
108
+    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('guide', $allowed_endpoints['craft/v2']) )
109
+        $allowed_endpoints['craft/v2'][] = 'guide';
110
+    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('short', $allowed_endpoints['craft/v2']) )
111
+        $allowed_endpoints['craft/v2'][] = 'short';
112
+    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('object', $allowed_endpoints['craft/v2']) )
113
+        $allowed_endpoints['craft/v2'][] = 'object';
114
+    if ( !isset($allowed_endpoints['craft/v2']) || !in_array('publication', $allowed_endpoints['craft/v2']) )
115
+        $allowed_endpoints['craft/v2'][] = 'publication';
98 116
 
99 117
     return $allowed_endpoints;
100 118
 }, 10, 1);

+ 4
- 4
plugins/cia-post-types/includes/custom-types.php View File

@@ -5,12 +5,12 @@
5 5
             'episode',
6 6
             'event',
7 7
             'exhibition',
8
-            // 'guide',
9
-            // 'short',
8
+            'guide',
9
+            'short',
10
+            'object',
11
+            'publication',
10 12
             // 'talk',
11 13
             // 'technique',
12
-            // 'object',
13
-            // 'publication',
14 14
             // 'profile',
15 15
             // 'product'
16 16
         ];

+ 8
- 0
vue-theme/src/store/index.js View File

@@ -11,6 +11,10 @@ import artist from './modules/artist'
11 11
 import episode from './modules/episode'
12 12
 import event from './modules/event'
13 13
 import exhibition from './modules/exhibition'
14
+import short from './modules/short'
15
+import guide from './modules/guide'
16
+import object from './modules/object'
17
+import publication from './modules/publication'
14 18
 import sticky from './modules/sticky'
15 19
 
16 20
 const debug = process.env.NODE_ENV !== 'production'
@@ -89,6 +93,10 @@ const store = new Vuex.Store({
89 93
         episode,
90 94
         event,
91 95
         exhibition,
96
+        short,
97
+        guide,
98
+        object,
99
+        publication,
92 100
         sticky,
93 101
     },
94 102
     strict: debug,

+ 70
- 0
vue-theme/src/store/modules/guide.js View File

@@ -0,0 +1,70 @@
1
+import api from '../../utils/api'
2
+
3
+const state = {
4
+    all: [],
5
+    loaded: false,
6
+    singledGuide: null,
7
+}
8
+
9
+const getters = {
10
+    allGuides: state => state.all,
11
+    allGuidesBySlug: state =>
12
+        Object.values(state.all).reduce((bySlug, guide) => {
13
+            bySlug[guide.slug] = guide
14
+            return bySlug
15
+        }, {}),
16
+    allGuidesLoaded: state => state.loaded,
17
+}
18
+
19
+const actions = {
20
+    getAllGuides({ commit }, { sortType, params }) {
21
+        commit('CLEAR_GUIDES')
22
+        commit('GUIDES_LOADED', false)
23
+        const storeFetch = (guides => {
24
+            let repacked = guides
25
+            commit('STORE_FETCHED_GUIDES', { guides: repacked })
26
+            commit('GUIDES_LOADED', true)
27
+        })
28
+        return api.getByType({ type: 'guide', sort: sortType, params, cb: storeFetch })
29
+    },
30
+    getMoreGuides({ commit }, { sortType, params }) {
31
+        const storeFetch = (guides => {
32
+            let repacked = guides
33
+            commit('ADD_TO_FETCHED_GUIDES', { guides: repacked })
34
+            commit('GUIDES_LOADED', true)
35
+        })
36
+        return api.getByType({ type: 'guide', sort: sortType, params, cb: storeFetch })
37
+    },
38
+    getSingleGuide({ commit }, id) {
39
+        commit('CLEAR_SINGLE_GUIDES')
40
+        commit('GUIDES_LOADED', false)
41
+
42
+        api.getSingleType('guide', id, guide => {
43
+            commit('STORE_FETCHED_SINGLE_GUIDE', guide)
44
+            commit('GUIDES_LOADED', true)
45
+        })
46
+    },
47
+}
48
+
49
+const mutations = {
50
+    ADD_TO_FETCHED_GUIDES(state, { guides }) {
51
+        state.all = [...state.all, ...guides]
52
+    },
53
+    STORE_FETCHED_GUIDES(state, { guides }) {
54
+        state.all = guides
55
+    },
56
+    STORE_FETCHED_SINGLE_GUIDE(state, guide) {
57
+        state.singledGuide = guide
58
+    },
59
+    CLEAR_GUIDES(state) {
60
+        state.all = []
61
+    },
62
+    CLEAR_SINGLE_GUIDES(state) {
63
+        state.singledGuide = null
64
+    },
65
+    GUIDES_LOADED(state, val) {
66
+        state.loaded = val
67
+    },
68
+}
69
+
70
+export default { state, getters, actions, mutations }

+ 70
- 0
vue-theme/src/store/modules/object.js View File

@@ -0,0 +1,70 @@
1
+import api from '../../utils/api'
2
+
3
+const state = {
4
+    all: [],
5
+    loaded: false,
6
+    singledObject: null,
7
+}
8
+
9
+const getters = {
10
+    allObjects: state => state.all,
11
+    allObjectsBySlug: state =>
12
+        Object.values(state.all).reduce((bySlug, object) => {
13
+            bySlug[object.slug] = object
14
+            return bySlug
15
+        }, {}),
16
+    allObjectsLoaded: state => state.loaded,
17
+}
18
+
19
+const actions = {
20
+    getAllObjects({ commit }, { sortType, params }) {
21
+        commit('CLEAR_OBJECTS')
22
+        commit('OBJECTS_LOADED', false)
23
+        const storeFetch = (objects => {
24
+            let repacked = objects
25
+            commit('STORE_FETCHED_OBJECTS', { objects: repacked })
26
+            commit('OBJECTS_LOADED', true)
27
+        })
28
+        return api.getByType({ type: 'object', sort: sortType, params, cb: storeFetch })
29
+    },
30
+    getMoreObjects({ commit }, { sortType, params }) {
31
+        const storeFetch = (objects => {
32
+            let repacked = objects
33
+            commit('ADD_TO_FETCHED_OBJECTS', { objects: repacked })
34
+            commit('OBJECTS_LOADED', true)
35
+        })
36
+        return api.getByType({ type: 'object', sort: sortType, params, cb: storeFetch })
37
+    },
38
+    getSingleObject({ commit }, id) {
39
+        commit('CLEAR_SINGLE_OBJECTS')
40
+        commit('OBJECTS_LOADED', false)
41
+
42
+        api.getSingleType('object', id, object => {
43
+            commit('STORE_FETCHED_SINGLE_OBJECT', object)
44
+            commit('OBJECTS_LOADED', true)
45
+        })
46
+    },
47
+}
48
+
49
+const mutations = {
50
+    ADD_TO_FETCHED_OBJECTS(state, { objects }) {
51
+        state.all = [...state.all, ...objects]
52
+    },
53
+    STORE_FETCHED_OBJECTS(state, { objects }) {
54
+        state.all = objects
55
+    },
56
+    STORE_FETCHED_SINGLE_OBJECT(state, object) {
57
+        state.singledObject = object
58
+    },
59
+    CLEAR_OBJECTS(state) {
60
+        state.all = []
61
+    },
62
+    CLEAR_SINGLE_OBJECTS(state) {
63
+        state.singledObject = null
64
+    },
65
+    OBJECTS_LOADED(state, val) {
66
+        state.loaded = val
67
+    },
68
+}
69
+
70
+export default { state, getters, actions, mutations }

+ 70
- 0
vue-theme/src/store/modules/publication.js View File

@@ -0,0 +1,70 @@
1
+import api from '../../utils/api'
2
+
3
+const state = {
4
+    all: [],
5
+    loaded: false,
6
+    singledPublication: null,
7
+}
8
+
9
+const getters = {
10
+    allPublications: state => state.all,
11
+    allPublicationsBySlug: state =>
12
+        Publication.values(state.all).reduce((bySlug, publication) => {
13
+            bySlug[publication.slug] = publication
14
+            return bySlug
15
+        }, {}),
16
+    allPublicationsLoaded: state => state.loaded,
17
+}
18
+
19
+const actions = {
20
+    getAllPublications({ commit }, { sortType, params }) {
21
+        commit('CLEAR_PUBLICATIONS')
22
+        commit('PUBLICATIONS_LOADED', false)
23
+        const storeFetch = (publications => {
24
+            let repacked = publications
25
+            commit('STORE_FETCHED_PUBLICATIONS', { publications: repacked })
26
+            commit('PUBLICATIONS_LOADED', true)
27
+        })
28
+        return api.getByType({ type: 'publication', sort: sortType, params, cb: storeFetch })
29
+    },
30
+    getMorePublications({ commit }, { sortType, params }) {
31
+        const storeFetch = (publications => {
32
+            let repacked = publications
33
+            commit('ADD_TO_FETCHED_PUBLICATIONS', { publications: repacked })
34
+            commit('PUBLICATIONS_LOADED', true)
35
+        })
36
+        return api.getByType({ type: 'publication', sort: sortType, params, cb: storeFetch })
37
+    },
38
+    getSinglePublication({ commit }, id) {
39
+        commit('CLEAR_SINGLE_PUBLICATIONS')
40
+        commit('PUBLICATIONS_LOADED', false)
41
+
42
+        api.getSingleType('publication', id, publication => {
43
+            commit('STORE_FETCHED_SINGLE_PUBLICATION', publication)
44
+            commit('PUBLICATIONS_LOADED', true)
45
+        })
46
+    },
47
+}
48
+
49
+const mutations = {
50
+    ADD_TO_FETCHED_PUBLICATIONS(state, { publications }) {
51
+        state.all = [...state.all, ...publications]
52
+    },
53
+    STORE_FETCHED_PUBLICATIONS(state, { publications }) {
54
+        state.all = publications
55
+    },
56
+    STORE_FETCHED_SINGLE_PUBLICATION(state, publication) {
57
+        state.singledPublication = publication
58
+    },
59
+    CLEAR_PUBLICATIONS(state) {
60
+        state.all = []
61
+    },
62
+    CLEAR_SINGLE_PUBLICATIONS(state) {
63
+        state.singledPublication = null
64
+    },
65
+    PUBLICATIONS_LOADED(state, val) {
66
+        state.loaded = val
67
+    },
68
+}
69
+
70
+export default { state, getters, actions, mutations }

+ 70
- 0
vue-theme/src/store/modules/short.js View File

@@ -0,0 +1,70 @@
1
+import api from '../../utils/api'
2
+
3
+const state = {
4
+    all: [],
5
+    loaded: false,
6
+    singleShort: null,
7
+}
8
+
9
+const getters = {
10
+    allShorts: state => state.all,
11
+    allShortsBySlug: state =>
12
+        Object.values(state.all).reduce((bySlug, short) => {
13
+            bySlug[short.slug] = short
14
+            return bySlug
15
+        }, {}),
16
+    allShortsLoaded: state => state.loaded,
17
+}
18
+
19
+const actions = {
20
+    getAllShorts({ commit }, { sortType, params }) {
21
+        commit('CLEAR_SHORTS')
22
+        commit('SHORTS_LOADED', false)
23
+        const storeFetch = (shorts => {
24
+            let repacked = shorts
25
+            commit('STORE_FETCHED_SHORTS', { shorts: repacked })
26
+            commit('SHORTS_LOADED', true)
27
+        })
28
+        return api.getByType({ type: 'short', sort: sortType, params, cb: storeFetch })
29
+    },
30
+    getMoreShorts({ commit }, { sortType, params }) {
31
+        const storeFetch = (shorts => {
32
+            let repacked = shorts
33
+            commit('ADD_TO_FETCHED_SHORTS', { shorts: repacked })
34
+            commit('SHORTS_LOADED', true)
35
+        })
36
+        return api.getByType({ type: 'short', sort: sortType, params, cb: storeFetch })
37
+    },
38
+    getSingleShort({ commit }, id) {
39
+        commit('CLEAR_SINGLE_SHORTS')
40
+        commit('SHORTS_LOADED', false)
41
+
42
+        api.getSingleType('short', id, short => {
43
+            commit('STORE_FETCHED_SINGLE_SHORT', short)
44
+            commit('SHORTS_LOADED', true)
45
+        })
46
+    },
47
+}
48
+
49
+const mutations = {
50
+    ADD_TO_FETCHED_SHORTS(state, { shorts }) {
51
+        state.all = [...state.all, ...shorts]
52
+    },
53
+    STORE_FETCHED_SHORTS(state, { shorts }) {
54
+        state.all = shorts
55
+    },
56
+    STORE_FETCHED_SINGLE_SHORT(state, short) {
57
+        state.singledShort = short
58
+    },
59
+    CLEAR_SHORTS(state) {
60
+        state.all = []
61
+    },
62
+    CLEAR_SINGLE_SHORTS(state) {
63
+        state.singledShort = null
64
+    },
65
+    SHORTS_LOADED(state, val) {
66
+        state.loaded = val
67
+    },
68
+}
69
+
70
+export default { state, getters, actions, mutations }

+ 4
- 0
vue-theme/src/utils/helpers.js View File

@@ -28,6 +28,10 @@ const postTypes = [
28 28
     'event',
29 29
     'post',
30 30
     'page',
31
+    'short',
32
+    'guide',
33
+    'object',
34
+    'publication',
31 35
 ]
32 36
 
33 37
 const ytThumbnail = (url, desiredSize) => {

+ 21
- 0
vue-theme/src/utils/intersection.js View File

@@ -0,0 +1,21 @@
1
+class IntersectionHandler {
2
+    constructor() {
3
+        this.el = null
4
+        this.observer = null
5
+    }
6
+    setEl(el) {
7
+        this.el = el
8
+    }
9
+    setObserver(onIntersect) {
10
+        this.observer = new IntersectionObserver(onIntersect, {
11
+            threshold: 0.80
12
+        })
13
+    }
14
+    start() {
15
+        this.observer.observe(this.el)
16
+    }
17
+}
18
+
19
+const intersectionHandler = new IntersectionHandler()
20
+
21
+export { intersectionHandler }

Loading…
Cancel
Save