PluginProbe
Faust.js / 0.7.7
Faust.js v0.7.7
1.8.12 1.8.11 1.4.1 1.8.0 1.8.8 1.8.9 trunk 0.7.0 0.7.1 0.7.10 0.7.11 0.7.3 0.7.4 0.7.5 0.7.6 0.7.7 0.7.8 0.7.9 0.8.0 0.8.1 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 All 40 releases
faustwp / includes / settings / assets / js / wpgraphql-install.js

wpgraphql-install.js in Faust.js 0.7.7, at includes/settings/assets/js/wpgraphql-install.js

74 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Handles WPGraphQL plugin installation at Settings → Headless.
3 */
4 faustwp.installWPGraphQL = (() => {
5 const $button = document.getElementById('faustwp-button-install-graphql');
6 const $spinner = document.querySelector('.get-started .spinner');
7 const $status = document.querySelector('.get-started .error-message');
8
9 // Attaches event listeners.
10 function init() {
11 $button.onclick = (event) => {
12 event.preventDefault();
13 installWPGraphQL().then((result) => {
14 if (result.status === 'active') {
15 update('complete');
16 } else {
17 update('failed', faustwp.strings.failed);
18 }
19 }).catch(result => {
20 update('failed', result.message || faustwp.strings.failed);
21 });
22 }
23 }
24
25 // Installs and activates the WPGraphQL plugin.
26 async function installWPGraphQL() {
27 update('installing');
28
29 // Default to install and activate.
30 const request = {
31 path: '/wp/v2/plugins',
32 method: 'POST',
33 data: {slug: 'wp-graphql', status: 'active'}
34 }
35
36 // Just activate the plugin if it is already installed.
37 if (faustwp.wpgraphqlIsInstalled) {
38 request.path = '/wp/v2/plugins/wp-graphql/wp-graphql';
39 request.data = {status: 'active'};
40 }
41
42 return await wp.apiFetch(request);
43 }
44
45 // Updates the button and spinner.
46 function update(state = 'installing', error = '') {
47 switch (state) {
48 case 'installing':
49 wp.a11y.speak(faustwp.strings.installing, 'polite');
50 $button.innerHTML = faustwp.strings.installing;
51 $button.disabled = true;
52 $spinner.style.visibility = 'visible';
53 $status.innerHTML = '';
54 break;
55 case 'complete':
56 wp.a11y.speak(faustwp.strings.active, 'polite');
57 $button.innerHTML = `☑️ ${faustwp.strings.active}`;
58 $spinner.style.visibility = 'hidden';
59 break;
60 case 'failed':
61 wp.a11y.speak(error || faustwp.strings.failed, 'polite');
62 $button.innerHTML = faustwp.strings.default;
63 $button.disabled = false;
64 $spinner.style.visibility = 'hidden';
65 $status.innerHTML = error;
66 break;
67 }
68 }
69
70 return {init: init}
71 })();
72
73 faustwp.installWPGraphQL.init();
74