2
2
* WordPress dependencies
3
3
*/
4
4
import { __ , sprintf } from '@wordpress/i18n' ;
5
- import { useState } from '@wordpress/element' ;
5
+ import { useState , useEffect } from '@wordpress/element' ;
6
6
import { useSelect , useDispatch } from '@wordpress/data' ;
7
7
import { store as noticesStore } from '@wordpress/notices' ;
8
8
import {
@@ -60,25 +60,47 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
60
60
61
61
const { createErrorNotice } = useDispatch ( noticesStore ) ;
62
62
63
- useSelect ( async ( select ) => {
64
- const themeData = select ( 'core' ) . getCurrentTheme ( ) ;
65
- const readmeData = await fetchReadmeData ( ) ;
63
+ const themeData = useSelect (
64
+ ( select ) => select ( 'core' ) . getCurrentTheme ( ) ,
65
+ [ ]
66
+ ) ;
67
+
68
+ useEffect ( ( ) => {
69
+ if ( ! themeData ) {
70
+ return ;
71
+ }
72
+
73
+ const fetchData = async ( ) => {
74
+ try {
75
+ const readmeData = await fetchReadmeData ( ) ;
76
+ setTheme ( {
77
+ name : themeData . name . raw ,
78
+ description : themeData . description . raw ,
79
+ uri : themeData . theme_uri . raw ,
80
+ version : themeData . version ,
81
+ requires_wp : themeData . requires_wp ,
82
+ author : themeData . author . raw ,
83
+ author_uri : themeData . author_uri . raw ,
84
+ tags_custom : themeData . tags . rendered ,
85
+ screenshot : themeData . screenshot ,
86
+ recommended_plugins : readmeData . recommended_plugins ,
87
+ font_credits : readmeData . fonts ,
88
+ image_credits : readmeData . images ,
89
+ } ) ;
90
+ } catch ( error ) {
91
+ createErrorNotice (
92
+ error . message ||
93
+ __ (
94
+ 'Failed to fetch theme data.' ,
95
+ 'create-block-theme'
96
+ ) ,
97
+ { type : 'snackbar' }
98
+ ) ;
99
+ }
100
+ } ;
66
101
67
- setTheme ( {
68
- name : themeData . name . raw ,
69
- description : themeData . description . raw ,
70
- uri : themeData . theme_uri . raw ,
71
- version : themeData . version ,
72
- requires_wp : themeData . requires_wp ,
73
- author : themeData . author . raw ,
74
- author_uri : themeData . author_uri . raw ,
75
- tags_custom : themeData . tags . rendered ,
76
- screenshot : themeData . screenshot ,
77
- recommended_plugins : readmeData . recommended_plugins ,
78
- font_credits : readmeData . fonts ,
79
- image_credits : readmeData . images ,
80
- } ) ;
81
- } , [ ] ) ;
102
+ fetchData ( ) ;
103
+ } , [ themeData , createErrorNotice ] ) ;
82
104
83
105
const handleUpdateClick = ( ) => {
84
106
postUpdateThemeMetadata ( theme )
@@ -152,6 +174,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
152
174
< Spacer />
153
175
< TextControl
154
176
__nextHasNoMarginBottom
177
+ __next40pxDefaultSize
155
178
disabled
156
179
label = { __ ( 'Theme name' , 'create-block-theme' ) }
157
180
value = { theme . name }
@@ -170,6 +193,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
170
193
/>
171
194
< TextControl
172
195
__nextHasNoMarginBottom
196
+ __next40pxDefaultSize
173
197
label = { __ ( 'Theme URI' , 'create-block-theme' ) }
174
198
value = { theme . uri }
175
199
onChange = { ( value ) =>
@@ -182,6 +206,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
182
206
/>
183
207
< TextControl
184
208
__nextHasNoMarginBottom
209
+ __next40pxDefaultSize
185
210
label = { __ ( 'Author' , 'create-block-theme' ) }
186
211
value = { theme . author }
187
212
onChange = { ( value ) =>
@@ -194,6 +219,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
194
219
/>
195
220
< TextControl
196
221
__nextHasNoMarginBottom
222
+ __next40pxDefaultSize
197
223
label = { __ ( 'Author URI' , 'create-block-theme' ) }
198
224
value = { theme . author_uri }
199
225
onChange = { ( value ) =>
@@ -206,6 +232,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
206
232
/>
207
233
< TextControl
208
234
__nextHasNoMarginBottom
235
+ __next40pxDefaultSize
209
236
label = { __ ( 'Version' , 'create-block-theme' ) }
210
237
value = { theme . version }
211
238
onChange = { ( value ) =>
@@ -218,6 +245,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
218
245
/>
219
246
< SelectControl
220
247
__nextHasNoMarginBottom
248
+ __next40pxDefaultSize
221
249
label = { __ (
222
250
'Minimum WordPress version' ,
223
251
'create-block-theme'
@@ -233,6 +261,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
233
261
/>
234
262
< FormTokenField
235
263
__nextHasNoMarginBottom
264
+ __next40pxDefaultSize
236
265
label = { __ ( 'Theme tags' , 'create-block-theme' ) }
237
266
value = {
238
267
theme . tags_custom ? theme . tags_custom . split ( ', ' ) : [ ]
0 commit comments