Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/admin-landing-page.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import "../node_modules/@wordpress/base-styles/mixins";
@include wordpress-admin-schemes();
@use "../node_modules/@wordpress/base-styles/mixins";
@include mixins.wordpress-admin-schemes();


.create-block-theme {
Expand Down
33 changes: 20 additions & 13 deletions src/editor-sidebar/create-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import { generateWpVersions } from '../utils/generate-versions';
const WP_MINIMUM_VERSIONS = generateWpVersions( WP_VERSION ); // eslint-disable-line no-undef

export const CreateThemePanel = ( { createType } ) => {
const { createErrorNotice } = useDispatch( noticesStore );
const { createErrorNotice, createSuccessNotice } =
useDispatch( noticesStore );

const [ theme, setTheme ] = useState( {
name: '',
Expand All @@ -58,14 +59,16 @@ export const CreateThemePanel = ( { createType } ) => {
const handleCreateBlankClick = () => {
createBlankTheme( theme )
.then( () => {
// eslint-disable-next-line no-alert
window.alert(
createSuccessNotice(
__(
'Theme created successfully. The editor will now reload.',
'create-block-theme'
)
),
{ type: 'snackbar' }
);
window.location.reload();
setTimeout( () => {
window.location.reload();
}, 1000 );
} )
.catch( ( error ) => {
const errorMessage =
Expand All @@ -81,14 +84,16 @@ export const CreateThemePanel = ( { createType } ) => {
const handleCloneClick = () => {
createClonedTheme( theme )
.then( () => {
// eslint-disable-next-line no-alert
window.alert(
createSuccessNotice(
__(
'Theme cloned successfully. The editor will now reload.',
'create-block-theme'
)
),
{ type: 'snackbar' }
);
window.location.reload();
setTimeout( () => {
window.location.reload();
}, 1000 );
} )
.catch( ( error ) => {
const errorMessage =
Expand All @@ -104,14 +109,16 @@ export const CreateThemePanel = ( { createType } ) => {
const handleCreateChildClick = () => {
createChildTheme( theme )
.then( () => {
// eslint-disable-next-line no-alert
window.alert(
createSuccessNotice(
__(
'Child theme created successfully. The editor will now reload.',
'create-block-theme'
)
),
{ type: 'snackbar' }
);
window.location.reload();
setTimeout( () => {
window.location.reload();
}, 1000 );
} )
.catch( ( error ) => {
const errorMessage =
Expand Down
13 changes: 8 additions & 5 deletions src/editor-sidebar/create-variation-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const PREFERENCE_SCOPE = 'create-block-theme';
const PREFERENCE_KEY = 'create-variation';

export const CreateVariationPanel = () => {
const { createErrorNotice } = useDispatch( noticesStore );
const { createErrorNotice, createSuccessNotice } =
useDispatch( noticesStore );

const [ theme, setTheme ] = useState( {
name: '',
Expand Down Expand Up @@ -62,14 +63,16 @@ export const CreateVariationPanel = () => {

postCreateThemeVariation( variationPreferences )
.then( () => {
// eslint-disable-next-line no-alert
window.alert(
createSuccessNotice(
__(
'Theme variation created successfully. The editor will now reload.',
'create-block-theme'
)
),
{ type: 'snackbar' }
);
window.location.reload();
setTimeout( () => {
window.location.reload();
}, 1000 );
} )
.catch( ( error ) => {
const errorMessage =
Expand Down
12 changes: 8 additions & 4 deletions src/editor-sidebar/editor-preferences-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as preferencesStore } from '@wordpress/preferences';
import { store as noticesStore } from '@wordpress/notices';
import {
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
__experimentalVStack as VStack,
Expand Down Expand Up @@ -32,17 +33,20 @@ export const EditorPreferencesPanel = () => {
);

const { set: setPreference } = useDispatch( preferencesStore );
const { createSuccessNotice } = useDispatch( noticesStore );

const handleToggle = ( value ) => {
setPreference( PREFERENCE_SCOPE, PREFERENCE_KEY, value );
// eslint-disable-next-line no-alert
window.alert(
createSuccessNotice(
__(
'Preference updated. The editor will now reload.',
'create-block-theme'
)
),
{ type: 'snackbar' }
);
window.location.reload();
setTimeout( () => {
window.location.reload();
}, 1000 );
};

return (
Expand Down
16 changes: 10 additions & 6 deletions src/editor-sidebar/reset-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function ResetTheme() {
}, [] );

const { set: setPreferences } = useDispatch( preferencesStore );
const { createErrorNotice } = useDispatch( noticesStore );
const { createErrorNotice, createSuccessNotice } =
useDispatch( noticesStore );
const [ isConfirmDialogOpen, setIsConfirmDialogOpen ] = useState( false );

const handleTogglePreference = ( key ) => {
Expand All @@ -59,20 +60,23 @@ function ResetTheme() {
try {
await resetTheme( preferences );
toggleConfirmDialog();
// eslint-disable-next-line no-alert
window.alert(
createSuccessNotice(
__(
'Theme reset successfully. The editor will now reload.',
'create-block-theme'
)
),
{ type: 'snackbar' }
);
window.location.reload();
setTimeout( () => {
window.location.reload();
}, 1000 );
} catch ( error ) {
createErrorNotice(
__(
'An error occurred while resetting the theme.',
'create-block-theme'
)
),
{ type: 'snackbar' }
);
}
};
Expand Down
41 changes: 22 additions & 19 deletions src/editor-sidebar/save-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export const SaveThemePanel = () => {
};
}, [] );

const { createErrorNotice } = useDispatch( noticesStore );
const { createErrorNotice, createSuccessNotice } =
useDispatch( noticesStore );
const { set: setPreference } = useDispatch( preferencesStore );

const handleTogglePreference = ( key ) => {
Expand All @@ -64,29 +65,31 @@ export const SaveThemePanel = () => {
},
} )
.then( () => {
// eslint-disable-next-line no-alert
window.alert(
createSuccessNotice(
__(
'Theme saved successfully. The editor will now reload.',
'create-block-theme'
)
),
{ type: 'snackbar' }
);

const searchParams = new URLSearchParams(
window?.location?.search
);
// If user is editing a pattern and savePatterns is true, redirect back to the patterns page.
if (
preference.savePatterns &&
searchParams.get( 'postType' ) === 'wp_block' &&
searchParams.get( 'postId' )
) {
window.location =
'/wp-admin/site-editor.php?postType=wp_block';
} else {
// If user is not editing a pattern, reload the editor.
window.location.reload();
}
setTimeout( () => {
const searchParams = new URLSearchParams(
window?.location?.search
);
// If user is editing a pattern and savePatterns is true, redirect back to the patterns page.
if (
preference.savePatterns &&
searchParams.get( 'postType' ) === 'wp_block' &&
searchParams.get( 'postId' )
) {
window.location =
'/wp-admin/site-editor.php?postType=wp_block';
} else {
// If user is not editing a pattern, reload the editor.
window.location.reload();
}
}, 1000 );
} )
.catch( ( error ) => {
const errorMessage =
Expand Down
11 changes: 7 additions & 4 deletions src/plugin-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
tool,
copy,
download,
edit,
pencil,
code,
chevronLeft,
chevronRight,
Expand Down Expand Up @@ -72,11 +72,14 @@ function PluginSidebarItem( { icon, path, children, onClick } ) {
<ItemWrapper onClick={ onClick } path={ path }>
<HStack justify="flex-start">
<HStack justify="flex-start">
<Icon icon={ icon } />
<Icon icon={ icon } aria-hidden="true" />
<FlexItem>{ children }</FlexItem>
</HStack>
{ path && (
<Icon icon={ isRTL() ? chevronLeft : chevronRight } />
<Icon
icon={ isRTL() ? chevronLeft : chevronRight }
aria-hidden="true"
/>
) }
</HStack>
</ItemWrapper>
Expand Down Expand Up @@ -157,7 +160,7 @@ const CreateBlockThemePlugin = () => {
) }
</PluginSidebarItem>
<PluginSidebarItem
icon={ edit }
icon={ pencil }
onClick={ () =>
setIsMetadataEditorOpen( true )
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugin-styles.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "~@wordpress/base-styles/colors";
@use "@wordpress/base-styles/colors";

$modal-footer-height: 70px;

Expand Down
21 changes: 17 additions & 4 deletions src/test/unit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
// TODO: Add unit tests as needed
/**
* Internal dependencies
*/
import { generateWpVersions } from '../utils/generate-versions';

describe( 'Sample Unit Test', function () {
it( 'should pass', function () {
expect( true ).toBe( true );
describe( 'generateWpVersions', () => {
it( 'should generate version list down to 5.9 for version 6.5', () => {
const versions = generateWpVersions( '6.5' );
expect( versions[ 0 ] ).toBe( '6.5' );
expect( versions[ versions.length - 1 ] ).toBe( '5.9' );
expect( versions ).toContain( '6.0' );
expect( versions ).toContain( '5.9' );
} );

it( 'should handle versions with release candidate suffixes', () => {
const versions = generateWpVersions( '6.2-RC1' );
expect( versions[ 0 ] ).toBe( '6.2' );
expect( versions[ versions.length - 1 ] ).toBe( '5.9' );
} );
} );
Loading