Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function SuggestionPanel( {
handleAccept,
handleDismiss,
handleDismissAll,
wordCountType,
} = useContentClassification( taxonomy );

const taxonomyObject: any = select( coreStore ).getTaxonomy( taxonomy );
Expand Down Expand Up @@ -73,10 +74,15 @@ export default function SuggestionPanel( {

{ ! hasEnoughContent && ! hasSuggestions && (
<p className="ai-content-classification__hint components-base-control__help">
{ __(
'Add more content to enable AI suggestions (approximately 150 words).',
'ai'
) }
{ wordCountType === 'words'
? __(
'Add more content to enable AI suggestions (approximately 150 words).',
'ai'
)
: __(
'Add more content to enable AI suggestions (approximately 150 characters).',
'ai'
) }
</p>
) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
/**
* WordPress dependencies
*/
import { _x } from '@wordpress/i18n';
import { dispatch, select } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';
import { useState, useCallback } from '@wordpress/element';
import { store as noticesStore } from '@wordpress/notices';
import { count as wordCount } from '@wordpress/wordcount';
import { count as wordCount, type Strategy } from '@wordpress/wordcount';
import { addQueryArgs } from '@wordpress/url';
import apiFetch from '@wordpress/api-fetch';

Expand All @@ -26,7 +27,7 @@ import type {
ContentClassificationData,
} from '../types';

const MINIMUM_WORD_COUNT = 150;
const MINIMUM_WORD_CHARACTER_COUNT = 150;
const NOTICE_ID = 'ai_content_classification_error';

const getSettings = (): ContentClassificationData =>
Expand Down Expand Up @@ -117,16 +118,34 @@ export function useContentClassification( taxonomy: string ): {
handleAccept: ( suggestion: TagSuggestion ) => void;
handleDismiss: ( suggestion: TagSuggestion ) => void;
handleDismissAll: () => void;
wordCountType: Strategy;
} {
const postId = select( editorStore ).getCurrentPostId() as number;
const content = select( editorStore ).getEditedPostContent();
const [ isGenerating, setIsGenerating ] = useState< boolean >( false );
const [ suggestions, setSuggestions ] = useState< TagSuggestion[] >( [] );
const { removeNotice, createErrorNotice } = dispatch( noticesStore ) as any;

// Check if content has enough words.
/**
* translators: If your word count is based on single characters (e.g. East Asian characters),
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
* Do not translate into your own language.
*
* Uses the default (core) text domain so the word count type stays consistent
* with WordPress core's behavior.
*
* See - https://github.com/WordPress/ai/pull/577#discussion_r3265155502
*/
// eslint-disable-next-line @wordpress/i18n-text-domain
const wordCountType = _x(
'words',
'Word count type. Do not translate!'
) as Strategy;
Comment thread
hbhalodia marked this conversation as resolved.

// Check if content has enough words or characters.
const hasEnoughContent =
wordCount( content || '', 'words' ) >= MINIMUM_WORD_COUNT;
wordCount( content || '', wordCountType ) >=
MINIMUM_WORD_CHARACTER_COUNT;

const handleGenerate = useCallback( async () => {
if ( ! ensureProvider( NOTICE_ID ) ) {
Expand Down Expand Up @@ -203,6 +222,7 @@ export function useContentClassification( taxonomy: string ): {
handleAccept,
handleDismiss,
handleDismissAll,
wordCountType,
};
}

Expand Down
Loading