PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / PageCreator / components / MainButton.jsx

MainButton.jsx in Extendify 3.1.5, at src/PageCreator/components/MainButton.jsx

58 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { ConfirmationModal } from '@page-creator/components/ConfirmationModal';
2 import { PageGen } from '@page-creator/icons/ai-gen';
3 import { useGlobalsStore } from '@page-creator/state/global';
4 import { useActivityStore } from '@shared/state/activity';
5 import { useSelect } from '@wordpress/data';
6 import { store as editorStore } from '@wordpress/editor';
7 import { useState } from '@wordpress/element';
8 import { __ } from '@wordpress/i18n';
9 import { Icon } from '@wordpress/icons';
10
11 export const MainButton = () => {
12 const { setOpen } = useGlobalsStore();
13 const { incrementActivity } = useActivityStore();
14 const [confirmationOpen, setConfirmationOpen] = useState(false);
15 // Get post attributes using WordPress's useSelect hook
16 const isEmptyPage = useSelect(
17 (select) => select(editorStore).isEditedPostEmpty(),
18 [],
19 );
20
21 const handleClick = () => {
22 // Minimize HC if its open
23 window.dispatchEvent(new CustomEvent('extendify-hc:minimize'));
24 if (!isEmptyPage) return setConfirmationOpen(true);
25
26 setOpen(true);
27 incrementActivity('page-creator-button-click');
28 };
29
30 return (
31 <>
32 {confirmationOpen && (
33 <ConfirmationModal
34 setConfirmationOpen={setConfirmationOpen}
35 setModalOpen={setOpen}
36 confirmationOpen={confirmationOpen}
37 />
38 )}
39 {/* biome-ignore lint: allow button role here */}
40 <div
41 role="button"
42 onClick={handleClick}
43 onKeyDown={(e) => {
44 if (!(e.key === 'Enter' || e.key === ' ')) return;
45 handleClick();
46 }}
47 tabIndex={0}
48 className="components-button has-icon is-primary ml-3 h-8 min-w-0 cursor-pointer px-2 xs:h-9 sm:ml-2 xl:pr-3"
49 >
50 <Icon icon={PageGen} size={24} className="fill-none" />
51 <span className="ml-1 hidden xl:inline">
52 {__('AI Page Generator', 'extendify-local')}
53 </span>
54 </div>
55 </>
56 );
57 };
58