-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathSummarizationPlugin.tsx
More file actions
76 lines (68 loc) · 1.75 KB
/
SummarizationPlugin.tsx
File metadata and controls
76 lines (68 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Summarization plugin component.
*/
/**
* WordPress dependencies
*/
import { Button, Flex, FlexItem } from '@wordpress/components';
import { PluginPostStatusInfo } from '@wordpress/editor';
import { __ } from '@wordpress/i18n';
import { update } from '@wordpress/icons';
/**
* Internal dependencies
*/
import { useSummaryGeneration } from '../functions/useSummaryGeneration';
const { aiSummarizationData } = window as any;
/**
* Summarization plugin component.
*/
export default function SummarizationPlugin() {
const { isSummarizing, hasSummary, handleSummarize } =
useSummaryGeneration();
let buttonLabel: string = __( 'Generate Summary', 'ai' );
if ( isSummarizing ) {
buttonLabel = __( 'Generating…', 'ai' );
} else if ( hasSummary ) {
buttonLabel = __( 'Re-generate Summary', 'ai' );
}
const buttonDescription = hasSummary
? __(
'This will update the AI generated summary block with a new summary of the content of this post.',
'ai'
)
: __(
'This will create a block that is a summary of the content of this post.',
'ai'
);
// Don't render if disabled.
if ( ! aiSummarizationData?.enabled ) {
return null;
}
return (
<PluginPostStatusInfo>
<Flex
direction="column"
className="ai-summarization-plugin-container"
gap={ 2 }
>
<FlexItem>
<Button
className="ai-summarization-plugin-button"
variant="secondary"
label={ buttonLabel }
icon={ update }
onClick={ handleSummarize }
disabled={ isSummarizing }
isBusy={ isSummarizing }
__next40pxDefaultSize
>
{ buttonLabel }
</Button>
</FlexItem>
<FlexItem>
<span className="description">{ buttonDescription }</span>
</FlexItem>
</Flex>
</PluginPostStatusInfo>
);
}