Skip to content

Commit

Permalink
do not render the assistant is the post type is not viewable
Browse files Browse the repository at this point in the history
  • Loading branch information
CGastrell committed Jan 6, 2025
1 parent db3f1e4 commit b8e3631
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Button, TextControl, SVG, Circle } from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import {
useState,
useCallback,
Expand All @@ -10,6 +13,7 @@ import { __, sprintf } from '@wordpress/i18n';
import clsx from 'clsx';
import debugFactory from 'debug';
import './style.scss';
import { CoreSelect } from '../ai-assistant-plugin-sidebar/types';

type StepType = 'input' | 'options' | 'completion';

Expand Down Expand Up @@ -82,6 +86,16 @@ export default function SeoAssistant( { busy, disabled, onStep }: SeoAssistantPr
const [ messages, setMessages ] = useState< Message[] >( [] );
const messagesEndRef = useRef< HTMLDivElement >( null );
const [ titleOptions, setTitleOptions ] = useState< Option[] >( [] );
// const postContent = usePostContent();
// const { isLoadingModules, isChangingStatus, isModuleActive, changeStatus } = useModuleStatus( 'seo-tools' );
const isViewable = useSelect( select => {
const postTypeName = select( editorStore ).getCurrentPostType();
const postTypeObject = ( select( coreStore ) as unknown as CoreSelect ).getPostType(
postTypeName
);

return postTypeObject?.viewable;
}, [] );

const [ metaDescriptionOptions, setMetaDescriptionOptions ] = useState< Option[] >( [] );

Expand Down Expand Up @@ -384,6 +398,11 @@ export default function SeoAssistant( { busy, disabled, onStep }: SeoAssistantPr
setMessages( [] );
};

// If the post type is not viewable, do not render my plugin.
if ( ! isViewable ) {
return null;
}

if ( ! isOpen ) {
return (
<div>
Expand Down

0 comments on commit b8e3631

Please sign in to comment.