PluginProbe
Extendify / 3.0.4
Extendify v3.0.4
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 / hooks / usePageProfile.js

usePageProfile.js in Extendify 3.0.4, at src/PageCreator/hooks/usePageProfile.js

31 lines 987 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { getPageProfile } from '@page-creator/api/DataApi';
2 import { usePageDescriptionStore } from '@page-creator/state/cache';
3 import { useGlobalsStore } from '@page-creator/state/global';
4 import { useSiteProfileStore } from '@shared/state/site-profile';
5 import { useEffect } from '@wordpress/element';
6 import { __ } from '@wordpress/i18n';
7 import useSWRImmutable from 'swr/immutable';
8
9 // Returns the site profile and page profile
10 export const usePageProfile = () => {
11 const { description } = usePageDescriptionStore();
12 const { setProgress, regenerationCount } = useGlobalsStore();
13 const { siteProfile } = useSiteProfileStore();
14
15 const { data, error } = useSWRImmutable(
16 { key: `page-profile-${regenerationCount}`, description, siteProfile },
17 getPageProfile,
18 );
19
20 useEffect(() => {
21 if (data) return;
22 setProgress(__('Generating AI page profile...', 'extendify-local'));
23 }, [data, setProgress]);
24
25 return {
26 pageProfile: data,
27 error,
28 loading: !data && !error,
29 };
30 };
31