/** * WordPress dependencies */ import { useSelect } from '@safe-wordpress/data'; /** * External dependencies */ import { store as NC_DATA } from '@nelio-content/data'; import { store as NC_EDIT_POST } from '@nelio-content/edit-post'; import type { PostTypeContext } from '@nelio-content/types'; import { useMemo } from '@safe-wordpress/element'; const CONTEXTS: ReadonlyArray< PostTypeContext > = [ 'comments', 'efi', 'future-actions', 'notifications', 'quality-checks', 'references', 'series', 'tasks', ]; export const useAreContentToolsEnabled = (): boolean => { const type = useSelect( ( select ) => select( NC_EDIT_POST ).getPostType(), [] ); const postTypesByContext = useSelect( ( select ) => CONTEXTS.map( ( c ) => select( NC_DATA ).getPostTypes( c ) ), [] ); const allTypes = useMemo( () => postTypesByContext.flatMap( ( xs ) => xs ), [ postTypesByContext ] ); return useMemo( () => allTypes.some( ( t ) => t.name === type ), [ allTypes, type ] ); }; export const useIsFeatureEnabled = ( context: PostTypeContext ): boolean => { const type = useSelect( ( select ) => select( NC_EDIT_POST ).getPostType(), [] ); const types = useSelect( ( select ) => select( NC_DATA ).getPostTypes( context ), [ context ] ); return types.some( ( t ) => t.name === type ); };