From 868a88a16286420906e5183f0e05b27419f613af Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Tue, 20 Feb 2024 10:51:57 +0530 Subject: [PATCH 01/16] Update index.js --- .../NewfoldInterfaceSkeleton/SiteGen/index.js | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index 1b28cdd1c..7b6e2bc81 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -1,4 +1,4 @@ -import { useEffect, useRef } from '@wordpress/element'; +import { useEffect, useRef, useState } from '@wordpress/element'; import { useLocation } from 'react-router-dom'; import { useSelect, useDispatch } from '@wordpress/data'; @@ -34,6 +34,7 @@ const ThemedNewfoldInterfaceSkeleton = themeToggleHOC( ); const SiteGen = () => { + const [ failedApi, setFailedApi ] = useState( [] ); const { newfoldBrand } = useSelect( ( select ) => { return { newfoldBrand: select( nfdOnboardingStore ).getNewfoldBrand(), @@ -62,6 +63,7 @@ const SiteGen = () => { useDispatch( nfdOnboardingStore ); const prevSiteGenErrorStatus = useRef(); + const preFailedApis = useRef(); async function syncStoreToDB() { if ( currentData ) { @@ -105,19 +107,27 @@ const SiteGen = () => { } } catch ( err ) { if ( retryCount < MAX_RETRIES_SITE_GEN ) { - performSiteGenMetaGeneration( + return performSiteGenMetaGeneration( siteInfo, identifier, skipCache, retryCount + 1 ); - } else { - updateSiteGenErrorStatus( true ); } + // setFailedApi( ( prevState ) => [ ...prevState, identifier ] ); + setFailedApi( ( prevState ) => { + if ( ! prevState.includes( identifier ) ) { + return [ ...prevState, identifier ]; + } + return prevState; + } ); + currentData.sitegen.siteGenErrorStatus = true; + updateSiteGenErrorStatus( true ); } } async function generateSiteGenData() { + console.log( failedApi ); // Start the API Requests when the loader is shown. if ( ! ( @@ -127,24 +137,32 @@ const SiteGen = () => { ) { return; } - let identifiers = await getSiteGenIdentifiers(); - identifiers = identifiers.body; - - const midIndex = Math.floor( identifiers.length / 2 ); - if ( location.pathname.includes( 'experience' ) ) { - identifiers = identifiers.slice( 0, midIndex ); - currentData.sitegen.siteGenMetaStatus.currentStatus = 0; - } else if ( location.pathname.includes( 'building' ) ) { - identifiers = identifiers.slice( midIndex ); - currentData.sitegen.siteGenMetaStatus.currentStatus = midIndex; + let identifiers; + if ( Array.isArray( failedApi ) && failedApi.length > 0 ) { + identifiers = failedApi; + preFailedApis.current = [ ...preFailedApis.current, ...failedApi ]; + setFailedApi( [] ); + } else { + identifiers = await getSiteGenIdentifiers(); + identifiers = identifiers.body; + console.log( identifiers ); + + const midIndex = Math.floor( identifiers.length / 2 ); + if ( location.pathname.includes( 'experience' ) ) { + identifiers = identifiers.slice( 0, midIndex ); + currentData.sitegen.siteGenMetaStatus.currentStatus = 0; + } else if ( location.pathname.includes( 'building' ) ) { + identifiers = identifiers.slice( midIndex ); + currentData.sitegen.siteGenMetaStatus.currentStatus = midIndex; + } + setCurrentOnboardingData( currentData ); } - setCurrentOnboardingData( currentData ); const siteInfo = { site_description: currentData.sitegen?.siteDetails?.prompt, }; - const skipCache = currentData.sitegen?.skipCache; - + const skipCache = false; + console.log( identifiers ); // Iterate over Identifiers and fire Requests! identifiers.forEach( ( identifier ) => { performSiteGenMetaGeneration( siteInfo, identifier, skipCache ); @@ -182,7 +200,7 @@ const SiteGen = () => { useEffect( () => { if ( prevSiteGenErrorStatus.current === true && siteGenErrorStatus === false ) { - generateSiteGenData(); + generateSiteGenData( failedApi ); syncStoreToDB(); } prevSiteGenErrorStatus.current = siteGenErrorStatus; From 13dad51496934b3251d7725bd9f7901843fbb395 Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Tue, 20 Feb 2024 14:54:38 +0530 Subject: [PATCH 02/16] Update index.js --- .../NewfoldInterfaceSkeleton/SiteGen/index.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index 7b6e2bc81..6edd48817 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -63,7 +63,6 @@ const SiteGen = () => { useDispatch( nfdOnboardingStore ); const prevSiteGenErrorStatus = useRef(); - const preFailedApis = useRef(); async function syncStoreToDB() { if ( currentData ) { @@ -114,7 +113,7 @@ const SiteGen = () => { retryCount + 1 ); } - // setFailedApi( ( prevState ) => [ ...prevState, identifier ] ); + setFailedApi( ( prevState ) => { if ( ! prevState.includes( identifier ) ) { return [ ...prevState, identifier ]; @@ -127,7 +126,6 @@ const SiteGen = () => { } async function generateSiteGenData() { - console.log( failedApi ); // Start the API Requests when the loader is shown. if ( ! ( @@ -137,15 +135,14 @@ const SiteGen = () => { ) { return; } + let identifiers; if ( Array.isArray( failedApi ) && failedApi.length > 0 ) { identifiers = failedApi; - preFailedApis.current = [ ...preFailedApis.current, ...failedApi ]; setFailedApi( [] ); } else { identifiers = await getSiteGenIdentifiers(); identifiers = identifiers.body; - console.log( identifiers ); const midIndex = Math.floor( identifiers.length / 2 ); if ( location.pathname.includes( 'experience' ) ) { @@ -161,8 +158,7 @@ const SiteGen = () => { site_description: currentData.sitegen?.siteDetails?.prompt, }; - const skipCache = false; - console.log( identifiers ); + const skipCache = currentData.sitegen?.skipCache; // Iterate over Identifiers and fire Requests! identifiers.forEach( ( identifier ) => { performSiteGenMetaGeneration( siteInfo, identifier, skipCache ); From 64209de7237ecbd0de17d4c41cc2facd479d024e Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Tue, 20 Feb 2024 17:29:49 +0530 Subject: [PATCH 03/16] remooved building step --- src/OnboardingSPA/chapters/sitegen.js | 2 -- .../NewfoldInterfaceSkeleton/SiteGen/index.js | 17 ++++++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/OnboardingSPA/chapters/sitegen.js b/src/OnboardingSPA/chapters/sitegen.js index faaf53ad6..1a93c73ff 100644 --- a/src/OnboardingSPA/chapters/sitegen.js +++ b/src/OnboardingSPA/chapters/sitegen.js @@ -6,7 +6,6 @@ import { stepSiteGenSiteDetails } from '../steps/SiteGen/SiteDetails/step'; import { stepSiteGenSiteLogo } from '../steps/SiteGen/SiteLogo/step'; import { stepSiteGenSocialMedia } from '../steps/SiteGen/SocialMedia/step'; import { stepSiteGenExperience } from '../steps/SiteGen/Experience/step'; -import { stepSiteGenBuilding } from '../steps/SiteGen/Building/step'; import { stepSiteGenPreview } from '../steps/SiteGen/Preview/step'; import { stepSiteGenEditor } from '../steps/SiteGen/Editor/step'; @@ -16,7 +15,6 @@ const steps = [ stepSiteGenSocialMedia, stepSiteGenSiteLogo, stepSiteGenExperience, - stepSiteGenBuilding, stepSiteGenPreview, stepSiteGenEditor, ]; diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index 1b28cdd1c..39fcd8f52 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -119,24 +119,16 @@ const SiteGen = () => { async function generateSiteGenData() { // Start the API Requests when the loader is shown. - if ( - ! ( - location.pathname.includes( 'experience' ) || - location.pathname.includes( 'building' ) - ) - ) { + if ( ! location.pathname.includes( 'experience' ) ) { return; } let identifiers = await getSiteGenIdentifiers(); identifiers = identifiers.body; - const midIndex = Math.floor( identifiers.length / 2 ); + const midIndex = Math.floor( identifiers.length ); if ( location.pathname.includes( 'experience' ) ) { identifiers = identifiers.slice( 0, midIndex ); currentData.sitegen.siteGenMetaStatus.currentStatus = 0; - } else if ( location.pathname.includes( 'building' ) ) { - identifiers = identifiers.slice( midIndex ); - currentData.sitegen.siteGenMetaStatus.currentStatus = midIndex; } setCurrentOnboardingData( currentData ); const siteInfo = { @@ -181,7 +173,10 @@ const SiteGen = () => { }, [ location.pathname ] ); useEffect( () => { - if ( prevSiteGenErrorStatus.current === true && siteGenErrorStatus === false ) { + if ( + prevSiteGenErrorStatus.current === true && + siteGenErrorStatus === false + ) { generateSiteGenData(); syncStoreToDB(); } From b9f9bcf362d37b4447f0658c789c0b6786b44c00 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Tue, 20 Feb 2024 18:51:30 +0530 Subject: [PATCH 04/16] upadted preview step --- .../NewfoldInterfaceSkeleton/SiteGen/index.js | 2 +- .../steps/SiteGen/Preview/index.js | 77 ++++++++++++++++++- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index 39fcd8f52..24f4a155f 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -125,7 +125,7 @@ const SiteGen = () => { let identifiers = await getSiteGenIdentifiers(); identifiers = identifiers.body; - const midIndex = Math.floor( identifiers.length ); + const midIndex = Math.floor( identifiers.length / 2 ); if ( location.pathname.includes( 'experience' ) ) { identifiers = identifiers.slice( 0, midIndex ); currentData.sitegen.siteGenMetaStatus.currentStatus = 0; diff --git a/src/OnboardingSPA/steps/SiteGen/Preview/index.js b/src/OnboardingSPA/steps/SiteGen/Preview/index.js index 030a782ec..4a5af4d1c 100644 --- a/src/OnboardingSPA/steps/SiteGen/Preview/index.js +++ b/src/OnboardingSPA/steps/SiteGen/Preview/index.js @@ -6,12 +6,17 @@ import { cloneDeep, isEmpty } from 'lodash'; import CommonLayout from '../../../components/Layouts/Common'; import { store as nfdOnboardingStore } from '../../../store'; -import { HEADER_SITEGEN } from '../../../../constants'; +import { HEADER_SITEGEN, MAX_RETRIES_SITE_GEN } from '../../../../constants'; import { SiteGenPreviewSelectableCard } from '../../../components/LivePreview'; import getContents from './contents'; import HeartAnimation from './heartAnimation'; import RegeneratingSiteCard from './regeneratingCard'; -import { getHomepages, regenerateHomepage } from '../../../utils/api/siteGen'; +import { + getHomepages, + regenerateHomepage, + generateSiteGenMeta, + getSiteGenIdentifiers, +} from '../../../utils/api/siteGen'; import { getGlobalStyles } from '../../../utils/api/themes'; import SitegenAiStateHandler from '../../../components/StateHandlers/SitegenAi'; @@ -47,6 +52,13 @@ const SiteGenPreview = () => { } ); + // Define fetchData outside of useEffect + async function fetchPreviewData() { + await generateSiteGenData(); + loadHomepages(); + loadGlobalStyles(); + } + useEffect( () => { setIsHeaderEnabled( true ); setHideFooterNav( true ); @@ -67,6 +79,64 @@ const SiteGenPreview = () => { prevSiteGenErrorStatus.current = siteGenErrorStatus; }, [ siteGenErrorStatus ] ); + async function performSiteGenMetaGeneration( + siteInfo, + identifier, + skipCache, + retryCount = 1 + ) { + try { + const data = await generateSiteGenMeta( + siteInfo, + identifier, + skipCache + ); + if ( data.body !== null ) { + currentData.sitegen.siteGenMetaStatus.currentStatus += 1; + if ( + currentData.sitegen.siteGenMetaStatus.currentStatus === + currentData.sitegen.siteGenMetaStatus.totalCount + ) { + currentData.sitegen.skipCache = false; + } + setCurrentOnboardingData( currentData ); + } + } catch ( err ) { + if ( retryCount < MAX_RETRIES_SITE_GEN ) { + performSiteGenMetaGeneration( + siteInfo, + identifier, + skipCache, + retryCount + 1 + ); + } else { + updateSiteGenErrorStatus( true ); + } + } + } + + async function generateSiteGenData() { + setIsPreviewLoading( true ); + // Start the API Requests when the loader is shown. + let identifiers = await getSiteGenIdentifiers(); + identifiers = identifiers.body; + + const midIndex = Math.floor( identifiers.length / 2 ); + identifiers = identifiers.slice( midIndex, identifiers.length ); + currentData.sitegen.siteGenMetaStatus.currentStatus = midIndex; + setCurrentOnboardingData( currentData ); + const siteInfo = { + site_description: currentData.sitegen?.siteDetails?.prompt, + }; + + const skipCache = currentData.sitegen?.skipCache; + + // Iterate over Identifiers and fire Requests! + identifiers.forEach( ( identifier ) => { + performSiteGenMetaGeneration( siteInfo, identifier, skipCache ); + } ); + } + const loadHomepages = async () => { setIsPreviewLoading( true ); if ( ! isEmpty( currentData.sitegen.homepages.data ) ) { @@ -105,8 +175,7 @@ const SiteGenPreview = () => { }; useEffect( () => { - loadHomepages(); - loadGlobalStyles(); + fetchPreviewData(); }, [] ); const handlePreview = ( slug ) => { From b109d85ffe88d4f6234267fea9eba5d13137f07b Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Tue, 20 Feb 2024 21:14:53 +0530 Subject: [PATCH 05/16] Update index.js --- .../components/NewfoldInterfaceSkeleton/SiteGen/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index 6edd48817..b7bf420f0 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -205,6 +205,7 @@ const SiteGen = () => { useEffect( () => { initializeThemes(); initializeSettings(); + updateSiteGenErrorStatus( false ); }, [] ); return ( From 9f929bcc6e78448031ba0d8888129e38c8ae5751 Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Wed, 21 Feb 2024 10:07:30 +0530 Subject: [PATCH 06/16] Update index.js --- .../components/NewfoldInterfaceSkeleton/SiteGen/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index b7bf420f0..4a5958721 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -196,7 +196,7 @@ const SiteGen = () => { useEffect( () => { if ( prevSiteGenErrorStatus.current === true && siteGenErrorStatus === false ) { - generateSiteGenData( failedApi ); + generateSiteGenData(); syncStoreToDB(); } prevSiteGenErrorStatus.current = siteGenErrorStatus; From 7da20d10f9a2a84653f3a64b55ec07e51e9ec491 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Wed, 21 Feb 2024 12:00:36 +0530 Subject: [PATCH 07/16] changed total count --- src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js b/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js index 94cd18a97..dcf576d7f 100644 --- a/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js +++ b/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js @@ -33,9 +33,10 @@ const SiteGenLoader = ( { autoNavigate = false } ) => { }, [] ); useEffect( () => { + /* Divided the totalCount by 2 to complete the progress bar in the experience step */ const percentageValue = ( currentData?.sitegen?.siteGenMetaStatus?.currentStatus / - currentData?.sitegen?.siteGenMetaStatus?.totalCount ) * + ( currentData?.sitegen?.siteGenMetaStatus?.totalCount / 2 ) ) * 100; setPercentage( percentageValue ); }, [ currentData?.sitegen?.siteGenMetaStatus?.currentStatus ] ); From a8ff043af63bc301707214240302bdfa4457d2f9 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Wed, 21 Feb 2024 12:06:10 +0530 Subject: [PATCH 08/16] removed building step files --- .../steps/SiteGen/Building/index.js | 48 ----------- .../steps/SiteGen/Building/step.js | 18 ----- .../steps/SiteGen/Building/stylesheet.scss | 80 ------------------- src/OnboardingSPA/styles/app.scss | 1 - 4 files changed, 147 deletions(-) delete mode 100644 src/OnboardingSPA/steps/SiteGen/Building/index.js delete mode 100644 src/OnboardingSPA/steps/SiteGen/Building/step.js delete mode 100644 src/OnboardingSPA/steps/SiteGen/Building/stylesheet.scss diff --git a/src/OnboardingSPA/steps/SiteGen/Building/index.js b/src/OnboardingSPA/steps/SiteGen/Building/index.js deleted file mode 100644 index 87bb72cad..000000000 --- a/src/OnboardingSPA/steps/SiteGen/Building/index.js +++ /dev/null @@ -1,48 +0,0 @@ -import CommonLayout from '../../../components/Layouts/Common'; - -import { memo, useEffect } from '@wordpress/element'; - -import { useDispatch } from '@wordpress/data'; -import { store as nfdOnboardingStore } from '../../../store'; -import { HEADER_SITEGEN } from '../../../../constants'; - -import SiteGenLoader from '../../../components/Loaders/SiteGenLoader'; -import SitegenAiStateHandler from '../../../components/StateHandlers/SitegenAi'; - -const SiteGenBuilding = () => { - const { - setIsHeaderEnabled, - setSidebarActiveView, - setHeaderActiveView, - setDrawerActiveView, - } = useDispatch( nfdOnboardingStore ); - - useEffect( () => { - setIsHeaderEnabled( true ); - setSidebarActiveView( false ); - setHeaderActiveView( HEADER_SITEGEN ); - setDrawerActiveView( false ); - } ); - return ( - - -
-
-
-
-
-
-
-
-
- -
-
-
- ); -}; - -export default memo( SiteGenBuilding ); diff --git a/src/OnboardingSPA/steps/SiteGen/Building/step.js b/src/OnboardingSPA/steps/SiteGen/Building/step.js deleted file mode 100644 index 2cd24d672..000000000 --- a/src/OnboardingSPA/steps/SiteGen/Building/step.js +++ /dev/null @@ -1,18 +0,0 @@ -import { copy } from '@wordpress/icons'; -import { lazy } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; -import { Step } from '../../../data/models/Step'; - -const SiteGenBuilding = lazy( () => import( './index' ) ); - -export const stepSiteGenBuilding = new Step( { - path: '/sitegen/step/building', - title: __( 'Page Layouts', 'wp-module-onboarding' ), - Component: SiteGenBuilding, - icon: copy, - sidebars: { - LearnMore: { - SidebarComponents: [], - }, - }, -} ); diff --git a/src/OnboardingSPA/steps/SiteGen/Building/stylesheet.scss b/src/OnboardingSPA/steps/SiteGen/Building/stylesheet.scss deleted file mode 100644 index b698b0a4b..000000000 --- a/src/OnboardingSPA/steps/SiteGen/Building/stylesheet.scss +++ /dev/null @@ -1,80 +0,0 @@ -@property --angle { - inherits: true; - syntax: ""; - initial-value: 90deg; -} - -@keyframes borderRotate { - - 100% { - --angle: 360deg; - } -} - -.nfd-onboarding-step--site-gen__building { - margin: 20px; - padding: 20px; - position: relative; - display: flex; - place-content: center; - place-items: flex-start; -} - -.site-gen__building { - - &_skimmer { - max-width: 1800px; - - &--main { - margin-bottom: 30px; - background: rgba(var(--nfd-onboarding-primary-rgb), 0.05); - box-shadow: 0 4px 30px rgba(var(--nfd-onboarding-secondary-rgb), 0.1); - animation: borderRotate 3500ms infinite forwards; - border: 0.25px solid rgba(var(--nfd-onboarding-secondary-rgb), 0.26); - border-image: conic-gradient(from var(--angle), rgba(var(--nfd-onboarding-secondary-rgb), 0.26) calc(var(--angle) + 0.5deg), rgba(var(--nfd-onboarding-shimmer-color), 0.5) calc(var(--angle) + 1deg)) 30; - - @media (prefers-reduced-motion) { - animation: none !important; - } - } - - &--header { - height: 6vh; - width: 90vw; - min-height: 50px; - } - - &--body { - width: 90vw; - height: calc(56vh - 150px); - min-height: 250px; - } - - &--footer { - width: 90vw; - display: flex; - align-items: center; - flex-direction: row; - justify-content: space-between; - - &_left { - width: 45vw; - height: calc(38vh - 100px); - min-height: 150px; - } - - &_right { - width: 37vw; - height: calc(38vh - 100px); - min-height: 150px; - } - } - } - - &_loader__overlay { - position: fixed; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - } -} diff --git a/src/OnboardingSPA/styles/app.scss b/src/OnboardingSPA/styles/app.scss index 4b00aa040..61c55c74f 100644 --- a/src/OnboardingSPA/styles/app.scss +++ b/src/OnboardingSPA/styles/app.scss @@ -86,7 +86,6 @@ @import "../steps/SiteGen/SiteLogo/stylesheet"; @import "../steps/SiteGen/SocialMedia/stylesheet"; @import "../steps/SiteGen/Welcome/stylesheet"; -@import "../steps/SiteGen/Building/stylesheet"; @import "../steps/SiteGen/Editor/stylesheet"; @import "../steps/SiteGen/Editor/Header/stylesheet"; From 1362793d702abe48a5db0ab620071aba0f377ec3 Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Wed, 21 Feb 2024 14:25:40 +0530 Subject: [PATCH 09/16] error status check --- src/OnboardingSPA/steps/SiteGen/Preview/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/OnboardingSPA/steps/SiteGen/Preview/index.js b/src/OnboardingSPA/steps/SiteGen/Preview/index.js index 4a5af4d1c..eea2e4562 100644 --- a/src/OnboardingSPA/steps/SiteGen/Preview/index.js +++ b/src/OnboardingSPA/steps/SiteGen/Preview/index.js @@ -55,8 +55,13 @@ const SiteGenPreview = () => { // Define fetchData outside of useEffect async function fetchPreviewData() { await generateSiteGenData(); - loadHomepages(); - loadGlobalStyles(); + if ( ! siteGenErrorStatus ) { + console.log( 'Load homepages' ); + loadHomepages(); + loadGlobalStyles(); + } else { + console.log( 'Do not load home pages' ); + } } useEffect( () => { @@ -111,6 +116,7 @@ const SiteGenPreview = () => { ); } else { updateSiteGenErrorStatus( true ); + setIsPreviewLoading( false ); } } } From 209d3d110c309f57676dea67e79d9d738de3a157 Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Wed, 21 Feb 2024 15:25:46 +0530 Subject: [PATCH 10/16] code update for error state and retry only failed apis --- .../steps/SiteGen/Preview/index.js | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/src/OnboardingSPA/steps/SiteGen/Preview/index.js b/src/OnboardingSPA/steps/SiteGen/Preview/index.js index eea2e4562..da97a33e5 100644 --- a/src/OnboardingSPA/steps/SiteGen/Preview/index.js +++ b/src/OnboardingSPA/steps/SiteGen/Preview/index.js @@ -25,7 +25,9 @@ const SiteGenPreview = () => { const [ homepages, setHomepages ] = useState( false ); const [ isRegenerating, setIsRegenerating ] = useState( false ); const [ isPreviewLoading, setIsPreviewLoading ] = useState( false ); + const [ isMetaApiSuccess, setIsMetaApiSuccess ] = useState( false ); const [ globalStyles, setGlobalStyles ] = useState( false ); + const [ failedApi, setFailedApi ] = useState( [] ); const prevSiteGenErrorStatus = useRef(); @@ -52,18 +54,6 @@ const SiteGenPreview = () => { } ); - // Define fetchData outside of useEffect - async function fetchPreviewData() { - await generateSiteGenData(); - if ( ! siteGenErrorStatus ) { - console.log( 'Load homepages' ); - loadHomepages(); - loadGlobalStyles(); - } else { - console.log( 'Do not load home pages' ); - } - } - useEffect( () => { setIsHeaderEnabled( true ); setHideFooterNav( true ); @@ -73,13 +63,28 @@ const SiteGenPreview = () => { updateInitialize( true ); }, [ currentData ] ); + useEffect( () => { + generateSiteGenData(); + }, [] ); + + useEffect( () => { + if ( isMetaApiSuccess ) { + loadHomepages(); + loadGlobalStyles(); + } + }, [ isMetaApiSuccess ] ); + useEffect( () => { if ( prevSiteGenErrorStatus.current === true && siteGenErrorStatus === false ) { - loadHomepages(); - loadGlobalStyles(); + if ( ! isMetaApiSuccess ) { + generateSiteGenData(); + } else { + loadHomepages(); + loadGlobalStyles(); + } } prevSiteGenErrorStatus.current = siteGenErrorStatus; }, [ siteGenErrorStatus ] ); @@ -103,6 +108,7 @@ const SiteGenPreview = () => { currentData.sitegen.siteGenMetaStatus.totalCount ) { currentData.sitegen.skipCache = false; + setIsMetaApiSuccess( true ); } setCurrentOnboardingData( currentData ); } @@ -115,6 +121,13 @@ const SiteGenPreview = () => { retryCount + 1 ); } else { + setFailedApi( ( prevState ) => { + if ( ! prevState.includes( identifier ) ) { + return [ ...prevState, identifier ]; + } + return prevState; + } ); + currentData.sitegen.siteGenErrorStatus = true; updateSiteGenErrorStatus( true ); setIsPreviewLoading( false ); } @@ -124,12 +137,20 @@ const SiteGenPreview = () => { async function generateSiteGenData() { setIsPreviewLoading( true ); // Start the API Requests when the loader is shown. - let identifiers = await getSiteGenIdentifiers(); - identifiers = identifiers.body; - const midIndex = Math.floor( identifiers.length / 2 ); - identifiers = identifiers.slice( midIndex, identifiers.length ); - currentData.sitegen.siteGenMetaStatus.currentStatus = midIndex; + let identifiers; + if ( Array.isArray( failedApi ) && failedApi.length > 0 ) { + identifiers = failedApi; + setFailedApi( [] ); + } else { + identifiers = await getSiteGenIdentifiers(); + identifiers = identifiers.body; + + const midIndex = Math.floor( identifiers.length / 2 ); + identifiers = identifiers.slice( midIndex, identifiers.length ); + currentData.sitegen.siteGenMetaStatus.currentStatus = midIndex; + } + setCurrentOnboardingData( currentData ); const siteInfo = { site_description: currentData.sitegen?.siteDetails?.prompt, @@ -180,10 +201,6 @@ const SiteGenPreview = () => { setGlobalStyles( globalStylesResponse.body ); }; - useEffect( () => { - fetchPreviewData(); - }, [] ); - const handlePreview = ( slug ) => { if ( ! ( slug in homepages ) ) { return false; From 4fad0545cd5c7bc147e1ff942043d3fb196210a4 Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Thu, 22 Feb 2024 15:51:36 +0530 Subject: [PATCH 11/16] Moved all apis to experience page --- .../components/Loaders/SiteGenLoader/index.js | 4 +- .../NewfoldInterfaceSkeleton/SiteGen/index.js | 7 +- .../steps/SiteGen/Experience/index.js | 2 +- .../steps/SiteGen/Preview/index.js | 110 ++---------------- 4 files changed, 18 insertions(+), 105 deletions(-) diff --git a/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js b/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js index 78c59a2ad..110cd5967 100644 --- a/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js +++ b/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js @@ -36,9 +36,11 @@ const SiteGenLoader = ( { customNavPercentage, watcher = null } ) => { /* Divided the totalCount by 2 to complete the progress bar in the experience step */ const percentageValue = ( currentData?.sitegen?.siteGenMetaStatus?.currentStatus / - ( currentData?.sitegen?.siteGenMetaStatus?.totalCount / 2 ) ) * + ( currentData?.sitegen?.siteGenMetaStatus?.totalCount) ) * 100; + console.log(percentageValue); setPercentage( percentageValue ); + }, [ currentData?.sitegen?.siteGenMetaStatus?.currentStatus ] ); useEffect( () => { diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index 827f1adb2..cb8346fe0 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -160,11 +160,8 @@ const SiteGen = () => { identifiers = await getSiteGenIdentifiers(); identifiers = identifiers.body; - const midIndex = Math.floor( identifiers.length / 2 ); - if ( location.pathname.includes( 'experience' ) ) { - identifiers = identifiers.slice( 0, midIndex ); - currentData.sitegen.siteGenMetaStatus.currentStatus = 0; - } + currentData.sitegen.siteGenMetaStatus.currentStatus = 0; + setCurrentOnboardingData( currentData ); } const siteInfo = { diff --git a/src/OnboardingSPA/steps/SiteGen/Experience/index.js b/src/OnboardingSPA/steps/SiteGen/Experience/index.js index 2f26d02ce..2dbc7dab0 100644 --- a/src/OnboardingSPA/steps/SiteGen/Experience/index.js +++ b/src/OnboardingSPA/steps/SiteGen/Experience/index.js @@ -59,7 +59,7 @@ const SiteGenExperience = () => {
{ const [ homepages, setHomepages ] = useState( false ); const [ isRegenerating, setIsRegenerating ] = useState( false ); const [ isPreviewLoading, setIsPreviewLoading ] = useState( false ); - const [ isMetaApiSuccess, setIsMetaApiSuccess ] = useState( false ); const [ globalStyles, setGlobalStyles ] = useState( false ); - const [ failedApi, setFailedApi ] = useState( [] ); + const prevSiteGenErrorStatus = useRef(); @@ -66,107 +63,17 @@ const SiteGenPreview = () => { setIsHeaderNavigationEnabled( false ); }, [ currentData ] ); - useEffect( () => { - generateSiteGenData(); - }, [] ); - - useEffect( () => { - if ( isMetaApiSuccess ) { - loadHomepages(); - loadGlobalStyles(); - } - }, [ isMetaApiSuccess ] ); - useEffect( () => { if ( prevSiteGenErrorStatus.current === true && siteGenErrorStatus === false ) { - if ( ! isMetaApiSuccess ) { - generateSiteGenData(); - } else { - loadHomepages(); - loadGlobalStyles(); - } + loadHomepages(); + loadGlobalStyles(); } prevSiteGenErrorStatus.current = siteGenErrorStatus; }, [ siteGenErrorStatus ] ); - async function performSiteGenMetaGeneration( - siteInfo, - identifier, - skipCache, - retryCount = 1 - ) { - try { - const data = await generateSiteGenMeta( - siteInfo, - identifier, - skipCache - ); - if ( data.body !== null ) { - currentData.sitegen.siteGenMetaStatus.currentStatus += 1; - if ( - currentData.sitegen.siteGenMetaStatus.currentStatus === - currentData.sitegen.siteGenMetaStatus.totalCount - ) { - currentData.sitegen.skipCache = false; - setIsMetaApiSuccess( true ); - } - setCurrentOnboardingData( currentData ); - } - } catch ( err ) { - if ( retryCount < MAX_RETRIES_SITE_GEN ) { - performSiteGenMetaGeneration( - siteInfo, - identifier, - skipCache, - retryCount + 1 - ); - } else { - setFailedApi( ( prevState ) => { - if ( ! prevState.includes( identifier ) ) { - return [ ...prevState, identifier ]; - } - return prevState; - } ); - currentData.sitegen.siteGenErrorStatus = true; - updateSiteGenErrorStatus( true ); - setIsPreviewLoading( false ); - } - } - } - - async function generateSiteGenData() { - setIsPreviewLoading( true ); - // Start the API Requests when the loader is shown. - - let identifiers; - if ( Array.isArray( failedApi ) && failedApi.length > 0 ) { - identifiers = failedApi; - setFailedApi( [] ); - } else { - identifiers = await getSiteGenIdentifiers(); - identifiers = identifiers.body; - - const midIndex = Math.floor( identifiers.length / 2 ); - identifiers = identifiers.slice( midIndex, identifiers.length ); - currentData.sitegen.siteGenMetaStatus.currentStatus = midIndex; - } - - setCurrentOnboardingData( currentData ); - const siteInfo = { - site_description: currentData.sitegen?.siteDetails?.prompt, - }; - - const skipCache = currentData.sitegen?.skipCache; - - // Iterate over Identifiers and fire Requests! - identifiers.forEach( ( identifier ) => { - performSiteGenMetaGeneration( siteInfo, identifier, skipCache ); - } ); - } - const loadHomepages = async () => { setIsPreviewLoading( true ); if ( ! isEmpty( currentData.sitegen.homepages.data ) ) { @@ -182,7 +89,9 @@ const SiteGenPreview = () => { const response = await getHomepages( currentData.sitegen.siteDetails.prompt ); - + // setIsPreviewLoading( false ); + // updateSiteGenErrorStatus( true ); + // return; if ( response.error ) { setIsPreviewLoading( false ); updateSiteGenErrorStatus( true ); @@ -204,6 +113,11 @@ const SiteGenPreview = () => { setGlobalStyles( globalStylesResponse.body ); }; + useEffect( () => { + loadHomepages(); + loadGlobalStyles(); + }, [] ); + const handlePreview = ( slug ) => { if ( ! ( slug in homepages ) ) { return false; From 0e396f9b6e411f93219b43d0a889a386f162b0a8 Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Thu, 22 Feb 2024 16:00:25 +0530 Subject: [PATCH 12/16] removed comments --- src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js | 4 +--- .../components/NewfoldInterfaceSkeleton/SiteGen/index.js | 2 +- src/OnboardingSPA/steps/SiteGen/Preview/index.js | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js b/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js index 110cd5967..6be299443 100644 --- a/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js +++ b/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js @@ -36,11 +36,9 @@ const SiteGenLoader = ( { customNavPercentage, watcher = null } ) => { /* Divided the totalCount by 2 to complete the progress bar in the experience step */ const percentageValue = ( currentData?.sitegen?.siteGenMetaStatus?.currentStatus / - ( currentData?.sitegen?.siteGenMetaStatus?.totalCount) ) * + ( currentData?.sitegen?.siteGenMetaStatus?.totalCount ) ) * 100; - console.log(percentageValue); setPercentage( percentageValue ); - }, [ currentData?.sitegen?.siteGenMetaStatus?.currentStatus ] ); useEffect( () => { diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index cb8346fe0..e2fed5cfa 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -142,7 +142,7 @@ const SiteGen = () => { return prevState; } ); currentData.sitegen.siteGenErrorStatus = true; - updateSiteGenErrorStatus( true ); + setCurrentOnboardingData( currentData ); } } diff --git a/src/OnboardingSPA/steps/SiteGen/Preview/index.js b/src/OnboardingSPA/steps/SiteGen/Preview/index.js index 57786f99b..aab5e04e4 100644 --- a/src/OnboardingSPA/steps/SiteGen/Preview/index.js +++ b/src/OnboardingSPA/steps/SiteGen/Preview/index.js @@ -89,9 +89,7 @@ const SiteGenPreview = () => { const response = await getHomepages( currentData.sitegen.siteDetails.prompt ); - // setIsPreviewLoading( false ); - // updateSiteGenErrorStatus( true ); - // return; + if ( response.error ) { setIsPreviewLoading( false ); updateSiteGenErrorStatus( true ); From e369aa5529e6631f3eb8a136438a1575c07a886f Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Fri, 23 Feb 2024 18:40:05 +0530 Subject: [PATCH 13/16] lint issues --- src/OnboardingSPA/steps/SiteGen/Preview/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OnboardingSPA/steps/SiteGen/Preview/index.js b/src/OnboardingSPA/steps/SiteGen/Preview/index.js index aab5e04e4..11670c663 100644 --- a/src/OnboardingSPA/steps/SiteGen/Preview/index.js +++ b/src/OnboardingSPA/steps/SiteGen/Preview/index.js @@ -26,7 +26,6 @@ const SiteGenPreview = () => { const [ isPreviewLoading, setIsPreviewLoading ] = useState( false ); const [ globalStyles, setGlobalStyles ] = useState( false ); - const prevSiteGenErrorStatus = useRef(); const { From 5ad08bdcdbfdf16b2544734e6e5dab86bfbefe8e Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Wed, 28 Feb 2024 16:44:58 +0530 Subject: [PATCH 14/16] removed build step from features --- src/OnboardingSPA/chapters/siteGen/features.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OnboardingSPA/chapters/siteGen/features.js b/src/OnboardingSPA/chapters/siteGen/features.js index 118f82766..1ac7a4ec4 100644 --- a/src/OnboardingSPA/chapters/siteGen/features.js +++ b/src/OnboardingSPA/chapters/siteGen/features.js @@ -2,10 +2,9 @@ import { __ } from '@wordpress/i18n'; import { CHAPTER_SITEGEN_FEATURES } from '../../../constants'; import { Chapter } from '../../data/models/Chapter'; -import { stepSiteGenBuilding } from '../../steps/SiteGen/Building/step'; import { stepSiteGenExperience } from '../../steps/SiteGen/Experience/step'; -const steps = [ stepSiteGenExperience, stepSiteGenBuilding ]; +const steps = [ stepSiteGenExperience ]; export const siteGenFeatures = new Chapter( { id: CHAPTER_SITEGEN_FEATURES, From ba2d8570eafe4bc8e5c3fcdbd421e3194895e1aa Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Wed, 28 Feb 2024 16:48:22 +0530 Subject: [PATCH 15/16] fixed lint --- src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js | 2 +- src/OnboardingSPA/steps/SiteGen/Preview/index.js | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js b/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js index 6be299443..d8a5297d6 100644 --- a/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js +++ b/src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js @@ -36,7 +36,7 @@ const SiteGenLoader = ( { customNavPercentage, watcher = null } ) => { /* Divided the totalCount by 2 to complete the progress bar in the experience step */ const percentageValue = ( currentData?.sitegen?.siteGenMetaStatus?.currentStatus / - ( currentData?.sitegen?.siteGenMetaStatus?.totalCount ) ) * + currentData?.sitegen?.siteGenMetaStatus?.totalCount ) * 100; setPercentage( percentageValue ); }, [ currentData?.sitegen?.siteGenMetaStatus?.currentStatus ] ); diff --git a/src/OnboardingSPA/steps/SiteGen/Preview/index.js b/src/OnboardingSPA/steps/SiteGen/Preview/index.js index 1e2057d15..0b058df29 100644 --- a/src/OnboardingSPA/steps/SiteGen/Preview/index.js +++ b/src/OnboardingSPA/steps/SiteGen/Preview/index.js @@ -11,10 +11,7 @@ import { SiteGenPreviewSelectableCard } from '../../../components/LivePreview'; import getContents from './contents'; import HeartAnimation from './heartAnimation'; import RegeneratingSiteCard from './regeneratingCard'; -import { - getHomepages, - regenerateHomepage, -} from '../../../utils/api/siteGen'; +import { getHomepages, regenerateHomepage } from '../../../utils/api/siteGen'; import { getGlobalStyles } from '../../../utils/api/themes'; import SitegenAiStateHandler from '../../../components/StateHandlers/SitegenAi'; import Animate from '../../../components/Animate'; From b233bb2a360952bde58758e5f60c9f9b8b9e37db Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Wed, 28 Feb 2024 16:54:55 +0530 Subject: [PATCH 16/16] removed extra code --- .../NewfoldInterfaceSkeleton/SiteGen/index.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index 60aa42fee..6905a0cf5 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -45,17 +45,6 @@ const ThemedNewfoldInterfaceSkeleton = themeToggleHOC( const SiteGen = () => { const [ failedApi, setFailedApi ] = useState( [] ); - const { newfoldBrand } = useSelect( ( select ) => { - return { - newfoldBrand: select( nfdOnboardingStore ).getNewfoldBrand(), - }; - }, [] ); - - // Update Title and Tagline on the site. - const { editEntityRecord } = useDispatch( coreStore ); - const { getEditedEntityRecord } = useSelect( ( select ) => { - return select( coreStore ); - }, [] ); useEffect( () => { document.body.classList.add( `nfd-brand-${ newfoldBrand }` ); @@ -103,7 +92,6 @@ const SiteGen = () => { useEffect( () => { document.body.classList.add( `nfd-brand-${ newfoldBrand }` ); }, [ newfoldBrand ] ); - const location = useLocation(); const prevSiteGenErrorStatus = useRef();