| Server IP : 66.29.153.156 / Your IP : 216.73.216.226 Web Server : LiteSpeed System : Linux premium322.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64 User : lastyfjz ( 1521) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/lastyfjz/www/wp-content/plugins/extendify/src/PageCreator/hooks/ |
Upload File : |
import { useEffect, useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { generateCustomContent } from '@page-creator/api/DataApi';
import { usePageLayout } from '@page-creator/hooks/usePageLayout';
import { usePageProfile } from '@page-creator/hooks/usePageProfile';
import { useGlobalsStore } from '@page-creator/state/global';
import { replaceThemeVariables } from '@page-creator/util/replaceThemeVariables';
import { safeParseJson } from '@shared/lib/parsing';
import useSWRImmutable from 'swr/immutable';
const { state } = safeParseJson(
window.extSharedData?.userData?.userSelectionData,
);
const siteId = window.extSharedData.siteId;
const currentTheme = window.extSharedData?.themeSlug || 'extendable';
export const usePageCustomContent = () => {
const { pageProfile } = usePageProfile();
const { template } = usePageLayout();
const { setProgress, regenerationCount } = useGlobalsStore();
const loading = !pageProfile || !template;
const params = {
key: `page-creator-page-custom-content-${regenerationCount}`,
pageProfile,
userState: {
businessInformation: state?.businessInformation,
goals: state?.goals,
siteInformation: state?.siteInformation,
siteId,
},
page: template,
};
const { data, error } = useSWRImmutable(
loading ? null : params,
generateCustomContent,
);
useEffect(() => {
if (loading) return;
setProgress(__('Writing custom content...', 'extendify-local'));
}, [data, setProgress, loading]);
const themeAdjustedPatterns = useMemo(() => {
if (!data?.patterns) return [];
return data.patterns.map((pattern) => ({
...pattern,
code: replaceThemeVariables(pattern.code, currentTheme),
}));
}, [data?.patterns]);
return {
page: data
? {
patterns: themeAdjustedPatterns,
title: pageProfile.aiTitle,
}
: data,
error,
loading: !data && !error,
};
};