PluginProbe
Extendify / 3.0.5
Extendify v3.0.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 / pages / Dashboard.jsx

Dashboard.jsx in Extendify 3.0.5, at src/PageCreator/pages/Dashboard.jsx

130 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { CheckboxInput } from '@page-creator/components/content/CheckboxInput';
2 import { CustomTextarea } from '@page-creator/components/content/CustomTextarea';
3 import { Title } from '@page-creator/components/content/Title';
4 import { usePageDescriptionStore } from '@page-creator/state/cache';
5 import { useGlobalsStore } from '@page-creator/state/global';
6 import { usePagesStore } from '@page-creator/state/pages';
7 import { useUserStore } from '@page-creator/state/user';
8 import { useSiteProfileStore } from '@shared/state/site-profile';
9 import { useEffect, useLayoutEffect, useState } from '@wordpress/element';
10 import { decodeEntities } from '@wordpress/html-entities';
11 import { __, sprintf } from '@wordpress/i18n';
12
13 const { siteTitle } = window.extSharedData;
14
15 export const Dashboard = () => {
16 const { nextPage } = usePagesStore();
17 const { allowsInstallingPlugins, updateUserOption } = useUserStore();
18 const { siteProfile, setSiteProfile } = useSiteProfileStore();
19 const { setDescription, description } = usePageDescriptionStore();
20 const [pageDescription, setPageDescription] = useState(description ?? '');
21 const [disabled, setDisabled] = useState(true);
22 const [hideEditor, setHideEditor] = useState(true);
23 const { incrementRegenerationCount } = useGlobalsStore();
24
25 const [siteDescription, setSiteDescription] = useState(
26 decodeEntities(siteProfile?.description) || '',
27 );
28
29 useLayoutEffect(() => {
30 if (siteDescription) return;
31 setHideEditor(false);
32 }, [siteDescription]);
33
34 useEffect(() => {
35 setDisabled(true);
36 const timer = setTimeout(() => {
37 if (pageDescription) setDescription(pageDescription);
38 if (siteDescription && siteDescription !== siteProfile?.description) {
39 // Persist the site profile if they edit it
40 setSiteProfile({ description: siteDescription });
41 }
42 setDisabled(!pageDescription.length);
43 }, 1000);
44
45 return () => clearTimeout(timer);
46 }, [
47 setDescription,
48 pageDescription,
49 siteDescription,
50 setDisabled,
51 setSiteProfile,
52 siteProfile,
53 ]);
54
55 return (
56 <div className="mx-auto my-12 flex max-w-xl flex-col">
57 <div className="mb-12 grid grid-cols-1 gap-1 text-center">
58 <Title
59 title={__('AI Page Creation', 'extendify-local')}
60 description={__(
61 'Describe the page you want to create, adding key details, and Al will generate a unique, ready-to-use page for you.',
62 'extendify-local',
63 )}
64 />
65 </div>
66 <div className="grid grid-cols-1 gap-3">
67 <CustomTextarea
68 id="extendify-page-creator-page-description"
69 title={__('Describe Your Page', 'extendify-local')}
70 required={true}
71 className="input-focus h-[220px] w-full max-w-full resize-none border border-gray-600 py-3 pe-6 ps-3 text-base placeholder:italic placeholder:opacity-70"
72 placeholder={__(
73 'E.g., Create an "About Us" page highlighting our story, mission, values and team overview.',
74 'extendify-local',
75 )}
76 value={pageDescription}
77 onChange={(e) => setPageDescription(e.currentTarget.value)}
78 />
79
80 <CustomTextarea
81 id="extendify-page-creator-site-description"
82 hideEditor={hideEditor}
83 setHideEditor={setHideEditor}
84 title={
85 siteTitle
86 ? // translators: %s: The site title
87 sprintf(
88 __('Site Description for %s', 'extendify-local'),
89 decodeEntities(siteTitle),
90 )
91 : __('Site Description', 'extendify-local')
92 }
93 className="input-focus h-[220px] w-full max-w-full resize-none border border-gray-600 py-3 pe-6 ps-3 text-base placeholder:italic placeholder:opacity-70"
94 placeholder={__(
95 'This is the site description with all its ups and downs.',
96 'extendify-local',
97 )}
98 value={siteDescription}
99 onChange={(e) => setSiteDescription(e.currentTarget.value)}
100 />
101
102 <CheckboxInput
103 label={__(
104 'Allow plugins to be installed for advanced page features',
105 'extendify-local',
106 )}
107 slug="extendify-page-creator-allow-plugins"
108 checked={allowsInstallingPlugins}
109 onChange={(e) =>
110 updateUserOption('allowsInstallingPlugins', e.target.checked)
111 }
112 />
113
114 <button
115 id="extendify-page-creator-generate-btn"
116 type="button"
117 disabled={disabled}
118 onClick={() => {
119 incrementRegenerationCount();
120 nextPage();
121 }}
122 className="mt-2.5 rounded-xs bg-editor-main px-4 py-2.5 text-sm font-medium text-design-text hover:opacity-90 disabled:bg-gray-300"
123 >
124 {__('Generate Page', 'extendify-local')}
125 </button>
126 </div>
127 </div>
128 );
129 };
130