22 * WordPress dependencies 
33 */ 
44import  {  __ ,  sprintf  }  from  '@wordpress/i18n' ; 
5- import  {  useState  }  from  '@wordpress/element' ; 
5+ import  {  useState ,   useEffect  }  from  '@wordpress/element' ; 
66import  {  useSelect ,  useDispatch  }  from  '@wordpress/data' ; 
77import  {  store  as  noticesStore  }  from  '@wordpress/notices' ; 
88import  { 
@@ -60,25 +60,47 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
6060
6161	const  {  createErrorNotice }  =  useDispatch (  noticesStore  ) ; 
6262
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+ 		} ; 
66101
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  ]  ) ; 
82104
83105	const  handleUpdateClick  =  ( )  =>  { 
84106		postUpdateThemeMetadata (  theme  ) 
@@ -152,6 +174,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
152174				< Spacer  /> 
153175				< TextControl 
154176					__nextHasNoMarginBottom 
177+ 					__next40pxDefaultSize 
155178					disabled 
156179					label = {  __ (  'Theme name' ,  'create-block-theme'  )  } 
157180					value = {  theme . name  } 
@@ -170,6 +193,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
170193				/> 
171194				< TextControl 
172195					__nextHasNoMarginBottom 
196+ 					__next40pxDefaultSize 
173197					label = {  __ (  'Theme URI' ,  'create-block-theme'  )  } 
174198					value = {  theme . uri  } 
175199					onChange = {  (  value  )  => 
@@ -182,6 +206,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
182206				/> 
183207				< TextControl 
184208					__nextHasNoMarginBottom 
209+ 					__next40pxDefaultSize 
185210					label = {  __ (  'Author' ,  'create-block-theme'  )  } 
186211					value = {  theme . author  } 
187212					onChange = {  (  value  )  => 
@@ -194,6 +219,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
194219				/> 
195220				< TextControl 
196221					__nextHasNoMarginBottom 
222+ 					__next40pxDefaultSize 
197223					label = {  __ (  'Author URI' ,  'create-block-theme'  )  } 
198224					value = {  theme . author_uri  } 
199225					onChange = {  (  value  )  => 
@@ -206,6 +232,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
206232				/> 
207233				< TextControl 
208234					__nextHasNoMarginBottom 
235+ 					__next40pxDefaultSize 
209236					label = {  __ (  'Version' ,  'create-block-theme'  )  } 
210237					value = {  theme . version  } 
211238					onChange = {  (  value  )  => 
@@ -218,6 +245,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
218245				/> 
219246				< SelectControl 
220247					__nextHasNoMarginBottom 
248+ 					__next40pxDefaultSize 
221249					label = {  __ ( 
222250						'Minimum WordPress version' , 
223251						'create-block-theme' 
@@ -233,6 +261,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
233261				/> 
234262				< FormTokenField 
235263					__nextHasNoMarginBottom 
264+ 					__next40pxDefaultSize 
236265					label = {  __ (  'Theme tags' ,  'create-block-theme'  )  } 
237266					value = { 
238267						theme . tags_custom  ? theme . tags_custom . split (  ', '  )  : [ ] 
0 commit comments