Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the jslint warning from useSelect usage #651

Merged
merged 1 commit into from
May 23, 2024
Merged
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
24 changes: 9 additions & 15 deletions src/editor-sidebar/create-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,24 @@ import ScreenHeader from './screen-header';
export const CreateThemePanel = ( { createType } ) => {
const { createErrorNotice } = useDispatch( noticesStore );

const subfolder = useSelect( ( select ) => {
const stylesheet = select( 'core' ).getCurrentTheme().stylesheet;
if ( stylesheet.lastIndexOf( '/' ) > 1 ) {
return stylesheet.substring( 0, stylesheet.lastIndexOf( '/' ) );
}
return '';
}, [] );

Comment on lines +35 to +42
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never tried setting initial state based on a value provided by a function called within the same component, but it doesn't seem to be a problem... so I'm inclined to approve this, albeit hesitantly

const [ theme, setTheme ] = useState( {
name: '',
description: '',
uri: '',
author: '',
author_uri: '',
tags_custom: '',
subfolder: '',
subfolder,
} );

useSelect( ( select ) => {
const themeData = select( 'core' ).getCurrentTheme();
setTheme( {
...theme,
subfolder:
themeData.stylesheet.lastIndexOf( '/' ) > 1
? themeData.stylesheet.substring(
0,
themeData.stylesheet.lastIndexOf( '/' )
)
: '',
} );
}, [] );

const cloneTheme = () => {
if ( createType === 'createClone' ) {
handleCloneClick();
Expand Down
Loading