Skip to content

Commit

Permalink
Follow react rules of hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
kirtangajjar committed Jun 15, 2024
1 parent e0af360 commit d520ab4
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions assets/js/gutenberg-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,34 @@ const DistributorIcon = () => (
* Add the Distributor panel to Gutenberg
*/
const DistributorPlugin = () => {
// Ensure the user has proper permissions
if (
dtGutenberg.noPermissions &&
1 === parseInt( dtGutenberg.noPermissions )
) {
return null;
}

// eslint-disable-next-line no-shadow, react-hooks/rules-of-hooks -- permission checks are needed.
const postType = useSelect( ( select ) =>
select( 'core/editor' ).getCurrentPostType()
);

// eslint-disable-next-line no-shadow, react-hooks/rules-of-hooks -- permission checks are needed.
// eslint-disable-next-line no-shadow -- permission checks are needed.
const postStatus = useSelect( ( select ) =>
select( 'core/editor' ).getCurrentPostAttribute( 'status' )
);

// eslint-disable-next-line @wordpress/no-unused-vars-before-return
const distributorTopMenu = document.querySelector(
'#wp-admin-bar-distributor'
);

// eslint-disable-next-line no-shadow -- permission checks are needed.
const post = useSelect( ( select ) =>
select( 'core/editor' ).getCurrentPost()
);

// Ensure the user has proper permissions
if (
dtGutenberg.noPermissions &&
1 === parseInt( dtGutenberg.noPermissions )
) {
return null;
}

// Ensure we are on a supported post type
if (
dtGutenberg.supportedPostTypes &&
Expand All @@ -179,14 +189,6 @@ const DistributorPlugin = () => {
return null;
}

const distributorTopMenu = document.querySelector(
'#wp-admin-bar-distributor'
);

// eslint-disable-next-line no-shadow, react-hooks/rules-of-hooks -- permission checks are needed.
const post = useSelect( ( select ) =>
select( 'core/editor' ).getCurrentPost()
);
// Make the post title and status available to the top menu.
dt.postTitle = post.title;
dt.postStatus = post.status;
Expand Down

0 comments on commit d520ab4

Please sign in to comment.