PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.8.3
GenerateBlocks v1.8.3
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / dashboard.js
generateblocks / src Last commit date
block-context 2 years ago blocks 2 years ago components 2 years ago extend 2 years ago hoc 2 years ago hooks 2 years ago shared 2 years ago utils 2 years ago blocks.js 2 years ago dashboard.js 2 years ago dashboard.scss 4 years ago
dashboard.js
264 lines
1 /**
2 * WordPress dependencies
3 */
4 import {
5 __,
6 } from '@wordpress/i18n';
7
8 import {
9 BaseControl,
10 Button,
11 PanelBody,
12 PanelRow,
13 Placeholder,
14 Spinner,
15 ToggleControl,
16 SelectControl,
17 TextControl,
18 } from '@wordpress/components';
19
20 import {
21 render,
22 Component,
23 Fragment,
24 } from '@wordpress/element';
25
26 import apiFetch from '@wordpress/api-fetch';
27
28 import {
29 applyFilters,
30 } from '@wordpress/hooks';
31
32 /**
33 * Internal dependencies
34 */
35 import './dashboard.scss';
36
37 class App extends Component {
38 constructor() {
39 super( ...arguments );
40
41 this.state = {
42 isAPILoaded: false,
43 isAPISaving: false,
44 isRegeneratingCSS: false,
45 settings: generateBlocksSettings.settings,
46 };
47
48 this.getSetting = this.getSetting.bind( this );
49 this.updateSettings = this.updateSettings.bind( this );
50 }
51
52 componentDidMount() {
53 this.setState( {
54 isAPILoaded: true,
55 } );
56 }
57
58 getSetting( name, defaultVal ) {
59 let result = defaultVal;
60
61 if ( 'undefined' !== typeof this.state.settings[ name ] ) {
62 result = this.state.settings[ name ];
63 }
64
65 return result;
66 }
67
68 updateSettings( e ) {
69 this.setState( { isAPISaving: true } );
70 const message = e.target.nextElementSibling;
71
72 apiFetch( {
73 path: '/generateblocks/v1/settings',
74 method: 'POST',
75 data: {
76 settings: this.state.settings,
77 },
78 } ).then( ( result ) => {
79 this.setState( { isAPISaving: false } );
80 message.classList.add( 'gblocks-action-message--show' );
81 message.textContent = result.response;
82
83 if ( ! result.success || ! result.response ) {
84 message.classList.add( 'gblocks-action-message--error' );
85 } else {
86 setTimeout( function() {
87 message.classList.remove( 'gblocks-action-message--show' );
88 }, 3000 );
89 }
90 } );
91 }
92
93 render() {
94 if ( ! this.state.isAPILoaded ) {
95 return (
96 <Placeholder className="gblocks-settings-placeholder">
97 <Spinner />
98 </Placeholder>
99 );
100 }
101
102 return (
103 <Fragment>
104 <div className="generateblocks-settings-main">
105 { applyFilters( 'generateblocks.dashboard.beforeSettings', '', this ) }
106
107 <PanelBody
108 title={ __( 'Settings', 'generateblocks' ) }
109 >
110 <div className="gblocks-dashboard-panel-row-wrapper">
111 <PanelRow className="gblocks-container-width">
112 <div className="gblocks-units">px</div>
113
114 <TextControl
115 type="number"
116 label={ __( 'Global max-width', 'generateblocks' ) }
117 help={ !! generateBlocksSettings.gpContainerWidth
118 ? __( 'The global max-width is set by GeneratePress in the Customizer.', 'generateblocks' )
119 : __( 'The global max-width value you can use in your blocks.', 'generateblocks' )
120 }
121 disabled={ !! generateBlocksSettings.gpContainerWidth }
122 value={ generateBlocksSettings.gpContainerWidth || this.getSetting( 'container_width' ) }
123 onChange={ ( value ) => {
124 this.setState( {
125 settings: {
126 ...this.state.settings,
127 container_width: value,
128 },
129 } );
130 } }
131 />
132
133 { !! generateBlocksSettings.gpContainerWidthLink &&
134 <a href={ generateBlocksSettings.gpContainerWidthLink } target="_blank" rel="noopener noreferrer" style={ { fontSize: '12px' } }>
135 { __( 'Go to option →', 'generateblocks' ) }
136 </a>
137 }
138 </PanelRow>
139
140 <PanelRow className="gblocks-css-print-method">
141 <SelectControl
142 label={ __( 'CSS Print Method', 'generateblocks' ) }
143 help={ __( 'Generating your CSS in external files is better for overall performance.', 'generateblocks' ) }
144 value={ this.getSetting( 'css_print_method' ) }
145 options={ [
146 { label: __( 'External File', 'generateblocks' ), value: 'file' },
147 { label: __( 'Inline Embedding', 'generateblocks' ), value: 'inline' },
148 ] }
149 onChange={ ( value ) => {
150 this.setState( {
151 settings: {
152 ...this.state.settings,
153 css_print_method: value,
154 },
155 } );
156 } }
157 />
158 </PanelRow>
159
160 { 'file' === this.getSetting( 'css_print_method' ) &&
161 <PanelRow>
162 <BaseControl
163 id="gblocks-regenerate-css"
164 className="gblocks-regenerate-css"
165 help={ __( 'Force your external CSS files to regenerate next time their page is loaded.', 'generateblocks' ) }
166 >
167 <div className="gblocks-action-button">
168 <Button
169 isSecondary
170 onClick={ ( e ) => {
171 this.setState( { isRegeneratingCSS: true } );
172 const message = e.target.nextElementSibling;
173
174 apiFetch( {
175 path: '/generateblocks/v1/regenerate_css_files',
176 method: 'POST',
177 } ).then( ( result ) => {
178 this.setState( { isRegeneratingCSS: false } );
179 message.classList.add( 'gblocks-action-message--show' );
180 message.textContent = result.response;
181
182 if ( ! result.success || ! result.response ) {
183 message.classList.add( 'gblocks-action-message--error' );
184 } else {
185 setTimeout( function() {
186 message.classList.remove( 'gblocks-action-message--show' );
187 }, 3000 );
188 }
189 } );
190 } }
191 >
192 { this.state.isRegeneratingCSS && <Spinner /> }
193 { ! this.state.isRegeneratingCSS && __( 'Regenerate CSS Files', 'generateblocks' ) }
194 </Button>
195
196 <span className="gblocks-action-message"></span>
197 </div>
198 </BaseControl>
199 </PanelRow>
200 }
201
202 <PanelRow>
203 <ToggleControl
204 label={ __( 'Sync Responsive Previews', 'generateblocks' ) }
205 help={ __( 'Sync our responsive preview controls with the editor responsive previews.', 'generateblocks' ) }
206 checked={ this.getSetting( 'sync_responsive_previews' ) }
207 onChange={ ( value ) => {
208 this.setState( {
209 settings: {
210 ...this.state.settings,
211 sync_responsive_previews: value,
212 },
213 } );
214 } }
215 />
216 </PanelRow>
217
218 <PanelRow>
219 <ToggleControl
220 label={ __( 'Disable Google Fonts', 'generateblocks' ) }
221 help={ __( 'Prevent Google Fonts from being called on your website and remove them from the font family lists.', 'generateblocks' ) }
222 checked={ this.getSetting( 'disable_google_fonts' ) }
223 onChange={ ( value ) => {
224 this.setState( {
225 settings: {
226 ...this.state.settings,
227 disable_google_fonts: value,
228 },
229 } );
230 } }
231 />
232 </PanelRow>
233
234 { applyFilters( 'generateblocks.dashboard.settings', '', this ) }
235
236 <div className="gblocks-action-button">
237 <Button
238 isPrimary
239 disabled={ this.state.isAPISaving }
240 onClick={ ( e ) => this.updateSettings( e ) }
241 >
242 { this.state.isAPISaving && <Spinner /> }
243 { ! this.state.isAPISaving && __( 'Save' ) }
244 </Button>
245
246 <span className="gblocks-action-message"></span>
247 </div>
248 </div>
249 </PanelBody>
250
251 { applyFilters( 'generateblocks.dashboard.afterSettings', '', this ) }
252 </div>
253 </Fragment>
254 );
255 }
256 }
257
258 window.addEventListener( 'DOMContentLoaded', () => {
259 render(
260 <App />,
261 document.getElementById( 'gblocks-block-default-settings' )
262 );
263 } );
264