Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed building step #473

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/OnboardingSPA/chapters/sitegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -16,7 +15,6 @@ const steps = [
stepSiteGenSocialMedia,
stepSiteGenSiteLogo,
stepSiteGenExperience,
stepSiteGenBuilding,
stepSiteGenPreview,
stepSiteGenEditor,
];
Expand Down
3 changes: 2 additions & 1 deletion src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ 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();
Expand All @@ -134,9 +129,6 @@ const SiteGen = () => {
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 = {
Expand Down Expand Up @@ -181,7 +173,10 @@ const SiteGen = () => {
}, [ location.pathname ] );

useEffect( () => {
if ( prevSiteGenErrorStatus.current === true && siteGenErrorStatus === false ) {
if (
prevSiteGenErrorStatus.current === true &&
siteGenErrorStatus === false
) {
generateSiteGenData();
syncStoreToDB();
}
Expand Down
48 changes: 0 additions & 48 deletions src/OnboardingSPA/steps/SiteGen/Building/index.js

This file was deleted.

18 changes: 0 additions & 18 deletions src/OnboardingSPA/steps/SiteGen/Building/step.js

This file was deleted.

80 changes: 0 additions & 80 deletions src/OnboardingSPA/steps/SiteGen/Building/stylesheet.scss

This file was deleted.

110 changes: 101 additions & 9 deletions src/OnboardingSPA/steps/SiteGen/Preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -20,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();

Expand Down Expand Up @@ -56,17 +63,107 @@ 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 ] );

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 ) ) {
Expand Down Expand Up @@ -104,11 +201,6 @@ const SiteGenPreview = () => {
setGlobalStyles( globalStylesResponse.body );
};

useEffect( () => {
loadHomepages();
loadGlobalStyles();
}, [] );

const handlePreview = ( slug ) => {
if ( ! ( slug in homepages ) ) {
return false;
Expand Down
1 change: 0 additions & 1 deletion src/OnboardingSPA/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Loading