Skip to content

Commit

Permalink
Don't fetch theme after activation
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Dec 1, 2023
1 parent 267a4e7 commit 0c35547
Showing 1 changed file with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,31 @@ export const usePreviewingTheme = () => {
select( 'core' );
return currentlyPreviewingTheme();
}, [] );
const previewingThemeId =
( previewingThemeSlug as string )?.split( '/' )?.[ 1 ] || previewingThemeSlug;
const [ previewingThemeName, setPreviewingThemeName ] = useState< string >(
previewingThemeSlug as string
);
const [ previewingThemeType, setPreviewingThemeType ] = useState< string >();
const [ previewingTheme, setPreviewingTheme ] = useState< Theme | undefined >( undefined );

const previewingThemeName = previewingTheme?.name || previewingThemeSlug;
const previewingThemeType = previewingTheme ? getThemeType( previewingTheme ) : undefined;
const previewingThemeTypeDisplay =
previewingThemeType === WOOCOMMERCE_THEME ? 'WooCommerce' : 'Premium';

useEffect( () => {
wpcom.req
.get( `/themes/${ previewingThemeId }`, { apiVersion: '1.2' } )
.then( ( theme: Theme ) => {
const name = theme?.name;
if ( name ) {
setPreviewingThemeName( name );
}
return theme;
} )
.then( ( theme: Theme ) => {
const type = getThemeType( theme );
if ( ! type ) {
return;
}
setPreviewingThemeType( type );
} )
.catch( () => {
// do nothing
} );
const previewingThemeId =
( previewingThemeSlug as string )?.split( '/' )?.[ 1 ] || previewingThemeSlug;

if ( previewingThemeId ) {
wpcom.req
.get( `/themes/${ previewingThemeId }`, { apiVersion: '1.2' } )
.then( ( theme: Theme ) => {
setPreviewingTheme( theme );
} )
.catch( () => {
// do nothing
} );
} else {
setPreviewingTheme( undefined );
}
return;
}, [ previewingThemeId ] );
}, [ previewingThemeSlug ] );

return {
name: previewingThemeName,
Expand Down

0 comments on commit 0c35547

Please sign in to comment.