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

Remove building step with error screen UI #478

Merged
merged 21 commits into from
Feb 28, 2024
Merged
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
3 changes: 1 addition & 2 deletions src/OnboardingSPA/chapters/siteGen/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions src/OnboardingSPA/chapters/sitegen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { CHAPTER_SITEGEN } from '../../constants';
import { Chapter } from '../data/models/Chapter';
import { __ } from '@wordpress/i18n';
import { stepSiteGenWelcome } from '../steps/SiteGen/Welcome/step';
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 { stepSiteGenPreview } from '../steps/SiteGen/Preview/step';
import { stepSiteGenEditor } from '../steps/SiteGen/Editor/step';

const steps = [
stepSiteGenWelcome,
stepSiteGenSiteDetails,
stepSiteGenSocialMedia,
stepSiteGenSiteLogo,
stepSiteGenExperience,
stepSiteGenPreview,
stepSiteGenEditor,
];

export const sitegen = new Chapter( {
id: CHAPTER_SITEGEN,
name: __( 'Site Generation', 'wp-module-onboarding' ),
steps,
} );
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

useEffect( () => {
const statusTimer = setInterval( () => {
statusIdx += 1;

Check warning on line 24 in src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Assignments to the 'statusIdx' variable from inside React Hook useEffect will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside useEffect
if ( statusIdx === content.status.length ) {
statusIdx = 0;
}
Expand All @@ -33,12 +33,13 @@
}, [] );

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 ) *
100;
setPercentage( percentageValue );
}, [ currentData?.sitegen?.siteGenMetaStatus?.currentStatus ] );

Check warning on line 42 in src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'currentData?.sitegen?.siteGenMetaStatus?.totalCount'. Either include it or remove the dependency array

useEffect( () => {
if ( percentage === customNavPercentage ) {
Expand All @@ -49,7 +50,7 @@
navigate( nextStep.path );
}
}
}, [ percentage, watcher ] );

Check warning on line 53 in src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'customNavPercentage', 'navigate', and 'nextStep'. Either include them or remove the dependency array

return (
<div className={ 'nfd-sg-loader' }>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef } from '@wordpress/element';
import { useEffect, useRef, useState } from '@wordpress/element';
import { store as coreStore } from '@wordpress/core-data';
import { useLocation } from 'react-router-dom';
import { useSelect, useDispatch } from '@wordpress/data';
Expand Down Expand Up @@ -44,6 +44,13 @@
);

const SiteGen = () => {
const [ failedApi, setFailedApi ] = useState( [] );

useEffect( () => {
document.body.classList.add( `nfd-brand-${ newfoldBrand }` );
}, [ newfoldBrand ] );
const location = useLocation();

const {
currentData,
initialize,
Expand Down Expand Up @@ -85,7 +92,6 @@
useEffect( () => {
document.body.classList.add( `nfd-brand-${ newfoldBrand }` );
}, [ newfoldBrand ] );
const location = useLocation();

const prevSiteGenErrorStatus = useRef();

Expand Down Expand Up @@ -145,18 +151,21 @@
retryCount + 1
);
}
updateSiteGenErrorStatus( true );

setFailedApi( ( prevState ) => {
if ( ! prevState.includes( identifier ) ) {
return [ ...prevState, identifier ];
}
return prevState;
} );
currentData.sitegen.siteGenErrorStatus = true;
setCurrentOnboardingData( currentData );
}
}

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;
}

Expand All @@ -167,24 +176,23 @@
}, 1000 );
}

let identifiers = await getSiteGenIdentifiers();
identifiers = identifiers.body;
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 );
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;

// Iterate over Identifiers and fire Requests!
identifiers.forEach( ( identifier ) => {
performSiteGenMetaGeneration( siteInfo, identifier, skipCache );
Expand Down Expand Up @@ -254,20 +262,20 @@

useEffect( () => {
trackChapters();
}, [ currentStep ] );

Check warning on line 265 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'trackChapters'. Either include it or remove the dependency array

useEffect( () => {
if ( initialize ) {
initializePlugins( pluginInstallHash );
setInterval( cronTrigger, 45000 );
}
}, [ initialize ] );

Check warning on line 272 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'pluginInstallHash'. Either include it or remove the dependency array

useEffect( () => {
syncStoreToDB();
generateSiteGenData();
handlePreviousStepTracking();
}, [ location.pathname ] );

Check warning on line 278 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'generateSiteGenData', 'handlePreviousStepTracking', and 'syncStoreToDB'. Either include them or remove the dependency array

useEffect( () => {
if (
Expand All @@ -278,13 +286,14 @@
syncStoreToDB();
}
prevSiteGenErrorStatus.current = siteGenErrorStatus;
}, [ siteGenErrorStatus ] );

Check warning on line 289 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'generateSiteGenData' and 'syncStoreToDB'. Either include them or remove the dependency array

useEffect( () => {
initializeThemes();
initializeSettings();
getEditedEntityRecord( 'root', 'site' );
updateSiteGenErrorStatus( false );
}, [] );

Check warning on line 296 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'getEditedEntityRecord' and 'updateSiteGenErrorStatus'. Either include them or remove the dependency array

return (
<ThemeProvider>
Expand Down
50 changes: 0 additions & 50 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.

2 changes: 1 addition & 1 deletion src/OnboardingSPA/steps/SiteGen/Experience/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
setIsHeaderNavigationEnabled,
} = useDispatch( nfdOnboardingStore );

useEffect( () => {

Check warning on line 40 in src/OnboardingSPA/steps/SiteGen/Experience/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect contains a call to 'setSelection'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [setHideFooterNav, setIsHeaderEnabled, setSidebarActiveView, setIsHeaderNavigationEnabled, setHeaderActiveView, setDrawerActiveView, currentData.sitegen.experience.level] as a second argument to the useEffect Hook
setHideFooterNav( true );
setIsHeaderEnabled( true );
setSidebarActiveView( false );
Expand Down Expand Up @@ -89,7 +89,7 @@
<div className={ 'nfd-sg-experience-level' }>
<SiteGenLoader
watcher={ selection !== 0 ? true : false }
customNavPercentage={ 50 }
customNavPercentage={ 100 }
/>
<CardWithOptions
title={ content.heading }
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 @@ -87,7 +87,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