Ver código fonte

:sparkles: big commit | created single post endpoint to load blocks serperately

tags/0.9.0
TOJ 5 anos atrás
pai
commit
3b84e1567f

+ 2
- 2
plugins/cia-endpoints/cia-end-points.php Ver arquivo

@@ -37,13 +37,13 @@ add_action( 'rest_api_init', function () {
37 37
      */
38 38
     $episode_controller = new Make_Endpoint_For('episode');
39 39
     $episode_controller->register_custom_route('episodes');
40
-    
40
+
41 41
     $artist_controller = new Make_Endpoint_For('artist');
42 42
     $artist_controller->register_custom_route('artists');
43 43
 
44 44
     $event_controller = new Make_Endpoint_For('event');
45 45
     $event_controller->register_custom_route('events');
46
-    
46
+
47 47
     $exhibition_controller = new Make_Endpoint_For('exhibition');
48 48
     $exhibition_controller->register_custom_route('exhibitions');
49 49
 

+ 47
- 16
plugins/cia-endpoints/includes/class.make-endpoint.php Ver arquivo

@@ -19,18 +19,29 @@ class Make_Endpoint_For extends WP_REST_Controller {
19 19
         register_rest_route( $namespace, '/' . $route, [
20 20
             array(
21 21
                 'methods'  => WP_REST_Server::READABLE,
22
-                'callback' => array( $this, 'get_items' )
22
+                'callback' => array( $this, 'get_all_items' )
23 23
             ),
24 24
         ]);
25 25
         register_rest_route( $namespace, '/' . $route . '/(?P<id>[\d]+)', [
26 26
             array(
27 27
                 'methods'  => WP_REST_Server::READABLE,
28
-                'callback' => array( $this, 'get_items' )
28
+                'callback' => array( $this, 'get_single_item' )
29 29
             ),
30 30
         ]);
31 31
     }
32
+    public function get_single_item( $request ) {
33
+        $args = array(
34
+            'numberposts' => 1,
35
+            'post_type' => $this->post_type
36
+        );
32 37
 
33
-    public function get_items( $request ) {
38
+        $params = $request->get_params();
39
+        if(intval($params['limit']) > 0) { $args['numberposts'] = intval($params['limit']); }
40
+        if(intval($params['id']) > 0) { $args['include'] = array($params['id']); }
41
+
42
+        return new WP_REST_Response( $this->prepare_single_item_for_response($args), 200 );
43
+    }
44
+    public function get_all_items( $request ) {
34 45
         $args = array(
35 46
             'numberposts' => -1,
36 47
             'post_type' => $this->post_type,
@@ -48,7 +59,7 @@ class Make_Endpoint_For extends WP_REST_Controller {
48 59
         // !: Add order asc/desc
49 60
         // !: Add orderby
50 61
 
51
-        return new WP_REST_Response( $this->prepare_item_for_response($args), 200 );
62
+        return new WP_REST_Response( $this->prepare_all_items_for_response($args), 200 );
52 63
     }
53 64
 
54 65
     private function _getAttachments($item, $galleries) {
@@ -75,8 +86,7 @@ class Make_Endpoint_For extends WP_REST_Controller {
75 86
         }
76 87
         return $attachment_map;
77 88
     }
78
-
79
-    public function prepare_item_for_response( $args ) {
89
+    public function prepare_single_item_for_response( $args ) {
80 90
         $collection = array();
81 91
 
82 92
         // https://developer.wordpress.org/reference/functions/get_posts/
@@ -84,18 +94,39 @@ class Make_Endpoint_For extends WP_REST_Controller {
84 94
             $filtered = default_post_format( $item );
85 95
 
86 96
             // Get those Block!
87
-            // $filtered[blocks] = get_rearrange_blocks(
88
-            //     parse_blocks( $item->post_content )
89
-            // );
97
+            $filtered[blocks] = get_rearrange_blocks(
98
+                parse_blocks( $item->post_content )
99
+            );
90 100
 
91 101
             // Galleries From blocks
92
-            // $media_ids = array();
93
-            // foreach ( get_attached_media( '', $item->ID ) as $attached_media ):
94
-            //     array_push($media_ids, $attached_media->ID);
95
-            // endforeach;
96
-            // $filtered[galleries] = get_ids_from_gallery_block(
97
-            //     parse_blocks( $item->post_content )
98
-            // );
102
+            $media_ids = array();
103
+            foreach ( get_attached_media( '', $item->ID ) as $attached_media ):
104
+                array_push($media_ids, $attached_media->ID);
105
+            endforeach;
106
+            $filtered[galleries] = get_ids_from_gallery_block(
107
+                parse_blocks( $item->post_content )
108
+            );
109
+
110
+            // Find all image info
111
+            $filtered[attached] = $this->_getAttachments( $item, $filtered[galleries] );
112
+
113
+            // For your hero URL
114
+            $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
115
+
116
+            // $filtered[relatedto] = p2p_related_to( $item->ID, $item->post_type );
117
+
118
+            $collection[$item->ID] = $filtered;
119
+        }
120
+        wp_reset_postdata();
121
+
122
+        return $collection;
123
+    }
124
+    public function prepare_all_items_for_response( $args ) {
125
+        $collection = array();
126
+
127
+        // https://developer.wordpress.org/reference/functions/get_posts/
128
+        foreach( get_posts($args) as $item ) {
129
+            $filtered = default_post_format( $item );
99 130
 
100 131
             // Find all image info
101 132
             $filtered[attached] = $this->_getAttachments( $item, $filtered[galleries] );

+ 16
- 69
vue-theme/package-lock.json Ver arquivo

@@ -8,6 +8,7 @@
8 8
       "version": "1.0.0",
9 9
       "license": "UNLICENSED",
10 10
       "dependencies": {
11
+        "chokidar": "^3.5.1",
11 12
         "compression-webpack-plugin": "^3.1.0",
12 13
         "vue": "^3.0.5",
13 14
         "vue-router": "^4.0.2",
@@ -1953,8 +1954,6 @@
1953 1954
       "version": "3.1.1",
1954 1955
       "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz",
1955 1956
       "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==",
1956
-      "dev": true,
1957
-      "optional": true,
1958 1957
       "dependencies": {
1959 1958
         "normalize-path": "^3.0.0",
1960 1959
         "picomatch": "^2.0.4"
@@ -2323,8 +2322,6 @@
2323 2322
       "version": "2.1.0",
2324 2323
       "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.1.0.tgz",
2325 2324
       "integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==",
2326
-      "dev": true,
2327
-      "optional": true,
2328 2325
       "engines": {
2329 2326
         "node": ">=8"
2330 2327
       }
@@ -2735,15 +2732,12 @@
2735 2732
       }
2736 2733
     },
2737 2734
     "node_modules/chokidar": {
2738
-      "version": "3.5.0",
2739
-      "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.0.tgz",
2740
-      "integrity": "sha512-JgQM9JS92ZbFR4P90EvmzNpSGhpPBGBSj10PILeDyYFwp4h2/D9OM03wsJ4zW1fEp4ka2DGrnUeD7FuvQ2aZ2Q==",
2741
-      "dev": true,
2742
-      "optional": true,
2735
+      "version": "3.5.1",
2736
+      "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.1.tgz",
2737
+      "integrity": "sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw==",
2743 2738
       "dependencies": {
2744 2739
         "anymatch": "~3.1.1",
2745 2740
         "braces": "~3.0.2",
2746
-        "fsevents": "~2.3.1",
2747 2741
         "glob-parent": "~5.1.0",
2748 2742
         "is-binary-path": "~2.1.0",
2749 2743
         "is-glob": "~4.0.1",
@@ -2752,14 +2746,15 @@
2752 2746
       },
2753 2747
       "engines": {
2754 2748
         "node": ">= 8.10.0"
2749
+      },
2750
+      "optionalDependencies": {
2751
+        "fsevents": "~2.3.1"
2755 2752
       }
2756 2753
     },
2757 2754
     "node_modules/chokidar/node_modules/braces": {
2758 2755
       "version": "3.0.2",
2759 2756
       "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
2760 2757
       "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
2761
-      "dev": true,
2762
-      "optional": true,
2763 2758
       "dependencies": {
2764 2759
         "fill-range": "^7.0.1"
2765 2760
       },
@@ -2771,8 +2766,6 @@
2771 2766
       "version": "7.0.1",
2772 2767
       "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
2773 2768
       "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
2774
-      "dev": true,
2775
-      "optional": true,
2776 2769
       "dependencies": {
2777 2770
         "to-regex-range": "^5.0.1"
2778 2771
       },
@@ -2784,8 +2777,6 @@
2784 2777
       "version": "7.0.0",
2785 2778
       "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
2786 2779
       "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
2787
-      "dev": true,
2788
-      "optional": true,
2789 2780
       "engines": {
2790 2781
         "node": ">=0.12.0"
2791 2782
       }
@@ -2794,8 +2785,6 @@
2794 2785
       "version": "5.0.1",
2795 2786
       "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
2796 2787
       "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
2797
-      "dev": true,
2798
-      "optional": true,
2799 2788
       "dependencies": {
2800 2789
         "is-number": "^7.0.0"
2801 2790
       },
@@ -4760,7 +4749,6 @@
4760 4749
       "version": "2.3.1",
4761 4750
       "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.1.tgz",
4762 4751
       "integrity": "sha512-YR47Eg4hChJGAB1O3yEAOkGO+rlzutoICGqGo9EZ4lKWokzZRSyIW1QmTzqjtw8MJdj9srP869CuWw/hyzSiBw==",
4763
-      "dev": true,
4764 4752
       "optional": true,
4765 4753
       "os": [
4766 4754
         "darwin"
@@ -4854,8 +4842,6 @@
4854 4842
       "version": "5.1.1",
4855 4843
       "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz",
4856 4844
       "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==",
4857
-      "dev": true,
4858
-      "optional": true,
4859 4845
       "dependencies": {
4860 4846
         "is-glob": "^4.0.1"
4861 4847
       },
@@ -5439,8 +5425,6 @@
5439 5425
       "version": "2.1.0",
5440 5426
       "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
5441 5427
       "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
5442
-      "dev": true,
5443
-      "optional": true,
5444 5428
       "dependencies": {
5445 5429
         "binary-extensions": "^2.0.0"
5446 5430
       },
@@ -5551,7 +5535,6 @@
5551 5535
       "version": "2.1.1",
5552 5536
       "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
5553 5537
       "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=",
5554
-      "dev": true,
5555 5538
       "engines": {
5556 5539
         "node": ">=0.10.0"
5557 5540
       }
@@ -5569,7 +5552,6 @@
5569 5552
       "version": "4.0.1",
5570 5553
       "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz",
5571 5554
       "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==",
5572
-      "dev": true,
5573 5555
       "dependencies": {
5574 5556
         "is-extglob": "^2.1.1"
5575 5557
       },
@@ -6388,7 +6370,6 @@
6388 6370
       "version": "3.0.0",
6389 6371
       "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
6390 6372
       "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
6391
-      "dev": true,
6392 6373
       "engines": {
6393 6374
         "node": ">=0.10.0"
6394 6375
       }
@@ -6793,8 +6774,6 @@
6793 6774
       "version": "2.2.2",
6794 6775
       "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz",
6795 6776
       "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==",
6796
-      "dev": true,
6797
-      "optional": true,
6798 6777
       "engines": {
6799 6778
         "node": ">=8.6"
6800 6779
       }
@@ -8263,8 +8242,6 @@
8263 8242
       "version": "3.5.0",
8264 8243
       "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.5.0.tgz",
8265 8244
       "integrity": "sha512-cMhu7c/8rdhkHXWsY+osBhfSy0JikwpHK/5+imo+LpeasTF8ouErHrlYkwT0++njiyuDvc7OFY5T3ukvZ8qmFQ==",
8266
-      "dev": true,
8267
-      "optional": true,
8268 8245
       "dependencies": {
8269 8246
         "picomatch": "^2.2.1"
8270 8247
       },
@@ -9606,7 +9583,6 @@
9606 9583
       "dev": true,
9607 9584
       "dependencies": {
9608 9585
         "source-map": "~0.5.1",
9609
-        "uglify-to-browserify": "~1.0.0",
9610 9586
         "yargs": "~3.10.0"
9611 9587
       },
9612 9588
       "bin": {
@@ -10117,10 +10093,8 @@
10117 10093
       "integrity": "sha512-9P3MWk6SrKjHsGkLT2KHXdQ/9SNkyoJbabxnKOoJepsvJjJG8uYTR3yTPxPQvNDI3w4Nz1xnE0TLHK4RIVe/MQ==",
10118 10094
       "dev": true,
10119 10095
       "dependencies": {
10120
-        "chokidar": "^3.4.1",
10121 10096
         "graceful-fs": "^4.1.2",
10122
-        "neo-async": "^2.5.0",
10123
-        "watchpack-chokidar2": "^2.0.1"
10097
+        "neo-async": "^2.5.0"
10124 10098
       },
10125 10099
       "optionalDependencies": {
10126 10100
         "chokidar": "^3.4.1",
@@ -10503,7 +10477,6 @@
10503 10477
         "anymatch": "^2.0.0",
10504 10478
         "async-each": "^1.0.1",
10505 10479
         "braces": "^2.3.2",
10506
-        "fsevents": "^1.2.7",
10507 10480
         "glob-parent": "^3.1.0",
10508 10481
         "inherits": "^2.0.3",
10509 10482
         "is-binary-path": "^1.0.0",
@@ -12829,8 +12802,6 @@
12829 12802
       "version": "3.1.1",
12830 12803
       "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz",
12831 12804
       "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==",
12832
-      "dev": true,
12833
-      "optional": true,
12834 12805
       "requires": {
12835 12806
         "normalize-path": "^3.0.0",
12836 12807
         "picomatch": "^2.0.4"
@@ -13141,9 +13112,7 @@
13141 13112
     "binary-extensions": {
13142 13113
       "version": "2.1.0",
13143 13114
       "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.1.0.tgz",
13144
-      "integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==",
13145
-      "dev": true,
13146
-      "optional": true
13115
+      "integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ=="
13147 13116
     },
13148 13117
     "bluebird": {
13149 13118
       "version": "3.7.2",
@@ -13514,11 +13483,9 @@
13514 13483
       }
13515 13484
     },
13516 13485
     "chokidar": {
13517
-      "version": "3.5.0",
13518
-      "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.0.tgz",
13519
-      "integrity": "sha512-JgQM9JS92ZbFR4P90EvmzNpSGhpPBGBSj10PILeDyYFwp4h2/D9OM03wsJ4zW1fEp4ka2DGrnUeD7FuvQ2aZ2Q==",
13520
-      "dev": true,
13521
-      "optional": true,
13486
+      "version": "3.5.1",
13487
+      "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.1.tgz",
13488
+      "integrity": "sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw==",
13522 13489
       "requires": {
13523 13490
         "anymatch": "~3.1.1",
13524 13491
         "braces": "~3.0.2",
@@ -13534,8 +13501,6 @@
13534 13501
           "version": "3.0.2",
13535 13502
           "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
13536 13503
           "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
13537
-          "dev": true,
13538
-          "optional": true,
13539 13504
           "requires": {
13540 13505
             "fill-range": "^7.0.1"
13541 13506
           }
@@ -13544,8 +13509,6 @@
13544 13509
           "version": "7.0.1",
13545 13510
           "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
13546 13511
           "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
13547
-          "dev": true,
13548
-          "optional": true,
13549 13512
           "requires": {
13550 13513
             "to-regex-range": "^5.0.1"
13551 13514
           }
@@ -13553,16 +13516,12 @@
13553 13516
         "is-number": {
13554 13517
           "version": "7.0.0",
13555 13518
           "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
13556
-          "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
13557
-          "dev": true,
13558
-          "optional": true
13519
+          "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
13559 13520
         },
13560 13521
         "to-regex-range": {
13561 13522
           "version": "5.0.1",
13562 13523
           "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
13563 13524
           "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
13564
-          "dev": true,
13565
-          "optional": true,
13566 13525
           "requires": {
13567 13526
             "is-number": "^7.0.0"
13568 13527
           }
@@ -15206,7 +15165,6 @@
15206 15165
       "version": "2.3.1",
15207 15166
       "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.1.tgz",
15208 15167
       "integrity": "sha512-YR47Eg4hChJGAB1O3yEAOkGO+rlzutoICGqGo9EZ4lKWokzZRSyIW1QmTzqjtw8MJdj9srP869CuWw/hyzSiBw==",
15209
-      "dev": true,
15210 15168
       "optional": true
15211 15169
     },
15212 15170
     "function-bind": {
@@ -15279,8 +15237,6 @@
15279 15237
       "version": "5.1.1",
15280 15238
       "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz",
15281 15239
       "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==",
15282
-      "dev": true,
15283
-      "optional": true,
15284 15240
       "requires": {
15285 15241
         "is-glob": "^4.0.1"
15286 15242
       }
@@ -15760,8 +15716,6 @@
15760 15716
       "version": "2.1.0",
15761 15717
       "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
15762 15718
       "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
15763
-      "dev": true,
15764
-      "optional": true,
15765 15719
       "requires": {
15766 15720
         "binary-extensions": "^2.0.0"
15767 15721
       }
@@ -15845,8 +15799,7 @@
15845 15799
     "is-extglob": {
15846 15800
       "version": "2.1.1",
15847 15801
       "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
15848
-      "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=",
15849
-      "dev": true
15802
+      "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI="
15850 15803
     },
15851 15804
     "is-fullwidth-code-point": {
15852 15805
       "version": "2.0.0",
@@ -15858,7 +15811,6 @@
15858 15811
       "version": "4.0.1",
15859 15812
       "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz",
15860 15813
       "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==",
15861
-      "dev": true,
15862 15814
       "requires": {
15863 15815
         "is-extglob": "^2.1.1"
15864 15816
       }
@@ -16540,8 +16492,7 @@
16540 16492
     "normalize-path": {
16541 16493
       "version": "3.0.0",
16542 16494
       "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
16543
-      "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
16544
-      "dev": true
16495
+      "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA=="
16545 16496
     },
16546 16497
     "normalize-range": {
16547 16498
       "version": "0.1.2",
@@ -16863,9 +16814,7 @@
16863 16814
     "picomatch": {
16864 16815
       "version": "2.2.2",
16865 16816
       "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz",
16866
-      "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==",
16867
-      "dev": true,
16868
-      "optional": true
16817
+      "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg=="
16869 16818
     },
16870 16819
     "pify": {
16871 16820
       "version": "4.0.1",
@@ -18117,8 +18066,6 @@
18117 18066
       "version": "3.5.0",
18118 18067
       "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.5.0.tgz",
18119 18068
       "integrity": "sha512-cMhu7c/8rdhkHXWsY+osBhfSy0JikwpHK/5+imo+LpeasTF8ouErHrlYkwT0++njiyuDvc7OFY5T3ukvZ8qmFQ==",
18120
-      "dev": true,
18121
-      "optional": true,
18122 18069
       "requires": {
18123 18070
         "picomatch": "^2.2.1"
18124 18071
       }

+ 1
- 0
vue-theme/package.json Ver arquivo

@@ -40,6 +40,7 @@
40 40
     "webpack-dev-server": "^3.11.1"
41 41
   },
42 42
   "dependencies": {
43
+    "chokidar": "^3.5.1",
43 44
     "compression-webpack-plugin": "^3.1.0",
44 45
     "vue": "^3.0.5",
45 46
     "vue-router": "^4.0.2",

+ 11
- 4
vue-theme/src/pages/mixin-post-types.js Ver arquivo

@@ -1,5 +1,5 @@
1 1
 import { convertTitleCase } from '@/utils/helpers'
2
-import { mapGetters } from 'vuex'
2
+import { mapGetters, mapState } from 'vuex'
3 3
 /**
4 4
  * A list of custom post types used to dispatch vuex actions
5 5
  * This makes ALL post type modules available for the
@@ -22,13 +22,20 @@ const postTypes = [
22 22
 const getterHelper = {}
23 23
 for(let type of postTypes) {
24 24
     const capitalized = convertTitleCase(type)
25
-    getterHelper[`all${capitalized}s`] = `all${capitalized}s` 
26
-    getterHelper[`all${capitalized}sLoaded`] = `all${capitalized}sLoaded` 
25
+    getterHelper[`all${capitalized}sBySlug`] = `all${capitalized}sBySlug`
26
+    getterHelper[`all${capitalized}s`] = `all${capitalized}s`
27
+    getterHelper[`all${capitalized}sLoaded`] = `all${capitalized}sLoaded`
28
+}
29
+
30
+const stateHelper = {}
31
+for(let type of postTypes) {
32
+    stateHelper[type] = type
27 33
 }
28 34
 
29 35
 const postTypeGetters = {
30 36
     computed: {
31
-        ...mapGetters(getterHelper)
37
+        ...mapGetters(getterHelper),
38
+        ...mapState(stateHelper)
32 39
     }
33 40
 }
34 41
 

+ 24
- 29
vue-theme/src/pages/single.vue Ver arquivo

@@ -13,7 +13,7 @@
13 13
 
14 14
     sidebar(v-if="sidebar" :type="`${type}`")
15 15
         .shadow
16
-            h1.t-up single slot 
16
+            h1.t-up single slot
17 17
             div
18 18
                 p body whatever
19 19
 </template>
@@ -25,12 +25,13 @@ import block from '@/components/content-block/block'
25 25
 
26 26
 import { postTypeGetters } from './mixin-post-types'
27 27
 
28
-import { convertTitleCase, typeFromRoute } from '@/utils/helpers'
28
+import { convertTitleCase, dePluralize, typeFromRoute } from '@/utils/helpers'
29 29
 
30 30
 export default {
31 31
     components: { sidebar, gallery, block },
32 32
     props: {
33
-        sidebar: { type: Boolean }
33
+        sidebar: { type: Boolean },
34
+        id: { type: Number }
34 35
     },
35 36
     mixins: [postTypeGetters],
36 37
     data() {
@@ -41,30 +42,20 @@ export default {
41 42
         }
42 43
     },
43 44
     computed: {
44
-        type() { // Checks for type and fixes Episodes route edge case 
45
+        type() { // Checks for type and fixes Episodes route edge case
45 46
             return typeFromRoute(this.$route)
46 47
         },
47 48
         /**
48 49
          * We get the actual post data using the slug
49 50
          */
50 51
         post() {
51
-            return this.posts[this.$route.params.slug]
52
-        },
53
-        /**
54
-         * We grab posts using the type derived from
55
-         * the route (See typeFromRoute() helper) and
56
-         * create a map keyed by post slug 
57
-         */
58
-        posts() {
59
-            let type = convertTitleCase(this.type)
60
-            
61
-            if(!type) return []
62
-            
63
-            // Return list keyed by slug
64
-            return Object.values(this[`all${type}`]).reduce((postsMap, post) => { 
65
-                postsMap[post.slug] = post
66
-                return postsMap
67
-            }, {})
52
+            const type = dePluralize(this.type)
53
+
54
+            // State not a getter!
55
+            const typeState = this[type]
56
+            if(!typeState[type]) return
57
+
58
+            return Object.values(typeState[type])[0]
68 59
         },
69 60
 
70 61
         idsForGallery() {
@@ -102,7 +93,7 @@ export default {
102 93
          * is set. We also need to set the activeImageID
103 94
          * to the image clicked
104 95
          * @param {number} galleryIndex
105
-         * @param {string} imageID 
96
+         * @param {string} imageID
106 97
          */
107 98
         openGallery(galleryIndex, imageID) {
108 99
             this.activeGalleryIndex = galleryIndex
@@ -113,10 +104,9 @@ export default {
113 104
          * Everytime the posts object changes
114 105
          * we use this to set a new HERO
115 106
          * in vuex
116
-         * @param {object} posts 
107
+         * @param {object} posts
117 108
          */
118
-        checkAndSetHero(posts) {
119
-            const post = posts[this.$route.params.slug]
109
+        checkAndSetHero(post) {
120 110
             if(!post || !post.hero) return
121 111
 
122 112
             const json = JSON.parse(post.hero)
@@ -131,11 +121,11 @@ export default {
131 121
         },
132 122
     },
133 123
     watch: {
134
-        posts(newVal, oldVal) {
124
+        post(newVal, oldVal) {
135 125
             this.checkAndSetHero(newVal)
136 126
         }
137 127
     },
138
-    created() {
128
+    async created() {
139 129
         /**
140 130
          * Conditionally load based on post type
141 131
          * which is derived from the route
@@ -143,9 +133,14 @@ export default {
143 133
          */
144 134
         let type = convertTitleCase(this.type)
145 135
         if(!this[`all${type}Loaded`] && type) {
146
-            // console.log('Retrieving...', type)
147
-            this.$store.dispatch(`getAll${type}`)
136
+            const res = await this.$store.dispatch(`getAll${type}`)
137
+            const post = Object.values(res).filter(post => post.slug == this.$route.params.slug)[0]
138
+            this.$store.dispatch(`getSingle${dePluralize(type)}`, post.id)
139
+        } else {
140
+            const post = Object.values(this.$store.state[this.type].all).filter(post => post.slug == this.$route.params.slug)[0]
141
+            this.$store.dispatch(`getSingle${dePluralize(type)}`, post.id)
148 142
         }
143
+
149 144
     }
150 145
 }
151 146
 </script>

+ 17
- 20
vue-theme/src/store/modules/artist.js Ver arquivo

@@ -1,47 +1,44 @@
1 1
 import api from '../../utils/api'
2 2
 
3 3
 const state = {
4
-    all: {},
4
+    all: [],
5 5
     loaded: false,
6 6
     artist: null,
7 7
 }
8 8
 
9 9
 const getters = {
10 10
     allArtists: state => state.all,
11
-    allArtistsLoaded: state => state.loaded,
12
-    artist: state => id => {
13
-        let field = typeof id === 'number' ? 'id' : 'slug'
14
-        let artist = state.all.filter(artist => artist[field] === id)
15
-        return (artist[0]) ? artist[0] : false
16
-    },
17
-    artistContent: state => id => {
18
-        let field = typeof id === 'number' ? 'id' : 'slug'
19
-        let artist = state.all.filter(artist => artist[field] === id)
20
-        return (artist[0]) ? artist[0].content.rendered : false
21
-    },
22
-    someArtists: state => limit => {
23
-        if (state.all.length < 1) return false
24
-
25
-        let all = [...state.all]
26
-
27
-        return all.splice(0, Math.min(limit, state.all.length))
28
-    },
11
+    allArtistsBySlug: state => Object.values(state.all).reduce((bySlug, artist) => {
12
+        bySlug[artist.slug] = artist
13
+        return bySlug
14
+    }, {}),
15
+    allArtistsLoaded: state => state.loaded
29 16
 }
30 17
 
31 18
 const actions = {
32 19
     getAllArtists({ commit }, sortType) {
33 20
         commit('CLEAR_ARTISTS')
34 21
         commit('ARTISTS_LOADED', false)
35
-        api.getByType('artists', sortType, artists => {
22
+        return api.getByType('artists', sortType, artists => {
36 23
             commit('STORE_FETCHED_ARTISTS', { artists })
37 24
             commit('ARTISTS_LOADED', true)
38 25
         })
26
+    },
27
+    getSingleArtist({ commit }, slug) {
28
+        commit('CLEAR_SINGLE_ARTIST')
29
+        commit('ARTISTS_LOADED', false)
30
+        api.getSingleType('artists', slug,  artist => {
31
+            commit('STORE_FETCHED_SINGLE_ARTIST', artist)
32
+            commit('ARTISTS_LOADED', true)
33
+        })
39 34
     }
40 35
 }
41 36
 
42 37
 const mutations = {
43 38
     STORE_FETCHED_ARTISTS(state, { artists }) { state.all = artists },
39
+    STORE_FETCHED_SINGLE_ARTIST(state, artist) { state.artist = artist },
44 40
     CLEAR_ARTISTS(state) { state.all = [] },
41
+    CLEAR_SINGLE_ARTIST(state) { state.artist = null },
45 42
     ARTISTS_LOADED(state, val) { state.loaded = val },
46 43
 }
47 44
 

+ 13
- 19
vue-theme/src/store/modules/episode.js Ver arquivo

@@ -9,38 +9,32 @@ const state = {
9 9
 const getters = {
10 10
     allEpisodes: state => state.all,
11 11
     allEpisodesLoaded: state => state.loaded,
12
-    episode: state => id => {
13
-        let field = typeof id === 'number' ? 'id' : 'slug'
14
-        let episode = state.all.filter(episode => episode[field] === id)
15
-        return (episode[0]) ? episode[0] : false
16
-    },
17
-    episodeContent: state => id => {
18
-        let field = typeof id === 'number' ? 'id' : 'slug'
19
-        let episode = state.all.filter(episode => episode[field] === id)
20
-
21
-        return (episode[0]) ? episode[0].content.rendered : false
22
-    },
23
-    someEpisodes: state => limit => {
24
-        if (state.all.length < 1) return false
25
-
26
-        let all = [...state.all]
27
-
28
-        return all.splice(0, Math.min(limit, state.all.length))
29
-    },
30 12
 }
31 13
 
32 14
 const actions = {
33 15
     getAllEpisodes({ commit }, sortType) {
16
+        commit('CLEAR_EPISODES')
34 17
         commit('EPISODES_LOADED', false)
35
-        api.getByType('episodes', sortType, episodes => {
18
+        return api.getByType('episodes', sortType, episodes => {
36 19
             commit('STORE_FETCHED_EPISODES', { episodes })
37 20
             commit('EPISODES_LOADED', true)
38 21
         })
22
+    },
23
+    getSingleEpisode({ commit }, slug) {
24
+        commit('CLEAR_SINGLE_EPISODE')
25
+        commit('EPISODES_LOADED', false)
26
+        api.getSingleType('episodes', slug,  episode => {
27
+            commit('STORE_FETCHED_SINGLE_EPISODE', episode)
28
+            commit('EPISODES_LOADED', true)
29
+        })
39 30
     }
40 31
 }
41 32
 
42 33
 const mutations = {
43 34
     STORE_FETCHED_EPISODES(state, { episodes }) { state.all = episodes },
35
+    STORE_FETCHED_SINGLE_EPISODE(state, episode) { state.episode = episode },
36
+    CLEAR_EPISODES(state) { state.all = [] },
37
+    CLEAR_SINGLE_EPISODE(state) { state.episode = null },
44 38
     EPISODES_LOADED(state, val) { state.loaded = val },
45 39
 }
46 40
 

+ 10
- 3
vue-theme/src/utils/api.js Ver arquivo

@@ -1,6 +1,6 @@
1 1
 import axios from 'axios'
2 2
 
3
-const SETTINGS = { 
3
+const SETTINGS = {
4 4
     LOADING_SEGMENTS: 2,
5 5
     API_BASE_PATH: '/wp-json/craft/v2/',
6 6
     API_MEDIA_PATH: '/wp-json/wp/v2/media/',
@@ -9,17 +9,24 @@ const SETTINGS = {
9 9
 export default {
10 10
     getByType(type, sortType, cb) {
11 11
         if (sortType) {
12
-            axios.get(SETTINGS.API_BASE_PATH + `sort/${type}/${sortType}`).then(response => {
12
+            return axios.get(SETTINGS.API_BASE_PATH + `sort/${type}/${sortType}`).then(response => {
13 13
                 cb(response.data)
14
+                return response.data
14 15
             }).catch(e => { cb(e) })
15 16
         }
16 17
 
17 18
         else {
18
-            axios.get(SETTINGS.API_BASE_PATH + `${type}`).then(response => {
19
+            return axios.get(SETTINGS.API_BASE_PATH + `${type}`).then(response => {
19 20
                 cb(response.data)
21
+                return response.data
20 22
             }).catch(e => { cb(e) })
21 23
         }
22 24
     },
25
+    getSingleType(type, id, cb) {
26
+        axios.get(SETTINGS.API_BASE_PATH + `${type}/${id}`).then(response => {
27
+            cb(response.data)
28
+        }).catch(e => { cb(e) })
29
+    },
23 30
     getSingleMedia(id, cb) {
24 31
         axios.get(SETTINGS.API_MEDIA_PATH + `${id}`).then(response => {
25 32
             cb(response.data)

+ 7
- 2
vue-theme/src/utils/helpers.js Ver arquivo

@@ -3,8 +3,13 @@ const convertTitleCase = (type) => {
3 3
     return type.charAt(0).toUpperCase() + type.slice(1)
4 4
 }
5 5
 
6
+const dePluralize = type => {
7
+    return type[type.length - 1] === 's' ? type.slice(0, -1) : type
8
+}
9
+
6 10
 const typeFromRoute = (route) => {
7
-    return route.params.type ? route.params.type : route.fullPath.slice(1)
11
+    const type = route.params.type ? route.params.type : route.fullPath.slice(1)
12
+    return type
8 13
 }
9 14
 
10 15
 const sortTypes = {
@@ -13,4 +18,4 @@ const sortTypes = {
13 18
     material: 'by-material',
14 19
 }
15 20
 
16
-export { convertTitleCase, typeFromRoute, sortTypes }
21
+export { convertTitleCase, dePluralize, typeFromRoute, sortTypes }

Carregando…
Cancelar
Salvar