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

Improve performance #400

Merged
merged 8 commits into from
Jan 9, 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: 2 additions & 1 deletion src/OnboardingSPA/components/CardWithOptions/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { memo } from '@wordpress/element';
import { Icon, chevronRight } from '@wordpress/icons';

const CardWithOptions = ( { title, options, skip, callback } ) => {
Expand Down Expand Up @@ -68,4 +69,4 @@ const CardWithOptions = ( { title, options, skip, callback } ) => {
);
};

export default CardWithOptions;
export default memo( CardWithOptions );
14 changes: 11 additions & 3 deletions src/OnboardingSPA/components/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '../../../constants';
import classNames from 'classnames';
import { stepSiteGenEditor } from '../../steps/SiteGen/Editor/step';
import { SITEGEN_FLOW } from '../../data/flows/constants';

const Header = () => {
const { headers, headerActiveView, isHeaderEnabled, currentStep } =
Expand All @@ -25,6 +26,7 @@ const Header = () => {
} );

const isEditorStep = currentStep === stepSiteGenEditor;
const isSitegenFlow = window.nfdOnboarding.currentFlow === SITEGEN_FLOW;

return (
<>
Expand All @@ -40,9 +42,15 @@ const Header = () => {
<Slot name={ `${ headerActiveView }/${ HEADER_TOP }` } />
{ isHeaderEnabled && (
<div
className={ classNames( 'nfd-onboarding-header', {
'nfd-onboarding-header--dark': isEditorStep,
} ) }
className={ classNames(
'nfd-onboarding-header',
{
'nfd-onboarding-header--dark': isEditorStep,
},
{
'nfd-onboarding-header--sitegen': isSitegenFlow,
}
) }
>
<div className="nfd-onboarding-header__start">
<Slot
Expand Down
7 changes: 7 additions & 0 deletions src/OnboardingSPA/components/Header/stylesheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
}
}

.nfd-onboarding-header--sitegen {

body.is-fullscreen-mode & {
padding-left: 0;
}
}

.nfd-onboarding-skeleton.is-drawer-open {

.nfd-onboarding-header {
Expand Down
4 changes: 3 additions & 1 deletion src/OnboardingSPA/components/Heading/AIHeading/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { memo } from '@wordpress/element';

const AIHeading = ( { title } ) => {
return (
<div className={ 'ai-heading' }>
Expand All @@ -7,4 +9,4 @@ const AIHeading = ( { title } ) => {
);
};

export default AIHeading;
export default memo( AIHeading );
8 changes: 5 additions & 3 deletions src/OnboardingSPA/components/Loaders/SiteGenLoader/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import getContents from './contents';
import { useSelect } from '@wordpress/data';
import { useNavigate } from 'react-router-dom';
import { useEffect, useState } from '@wordpress/element';
import { memo, useEffect, useState } from '@wordpress/element';
import { store as nfdOnboardingStore } from '../../../store';

const SiteGenLoader = ( { autoNavigate = false } ) => {
Expand All @@ -21,8 +21,10 @@

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;
if ( statusIdx === content.status.length ) {
statusIdx = 0;
}
setStatus( content.status[ statusIdx ].title );
}, 3000 );
return () => {
Expand All @@ -36,7 +38,7 @@
currentData.sitegen.siteGenMetaStatus.totalCount ) *
100;
setPercentage( percentageValue );
}, [ currentData.sitegen.siteGenMetaStatus.currentStatus ] );

Check warning on line 41 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 === 100 ) {
Expand All @@ -44,7 +46,7 @@
navigate( nextStep.path );
}
}
}, [ percentage ] );

Check warning on line 49 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: 'autoNavigate', 'navigate', and 'nextStep'. Either include them or remove the dependency array

return (
<div className={ 'nfd-sg-loader' }>
Expand All @@ -65,4 +67,4 @@
);
};

export default SiteGenLoader;
export default memo( SiteGenLoader );
3 changes: 2 additions & 1 deletion src/OnboardingSPA/components/StartOptions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolveGetDataForFlow } from '../../data/flows';
import { useSelect, useDispatch } from '@wordpress/data';
import { validateFlow } from '../../data/flows/utils';
import { useNavigate } from 'react-router-dom';
import { memo } from '@wordpress/element';
import { store as nfdOnboardingStore } from '../../store';

const StartOptions = ( { questionnaire, oldFlow, options } ) => {
Expand Down Expand Up @@ -101,4 +102,4 @@ const StartOptions = ( { questionnaire, oldFlow, options } ) => {
);
};

export default StartOptions;
export default memo( StartOptions );
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classNames from 'classnames';
import { __ } from '@wordpress/i18n';
import { useRef, useEffect, useState, memo } from '@wordpress/element';

const TextInputSiteGen = ( {
Expand All @@ -17,10 +18,10 @@
textareaRef.current.style.height = height;
const scrollHeight = textareaRef.current.scrollHeight;
textareaRef.current.style.height = scrollHeight + 'px';
const analysisResult = calculateAnalysisScore( customerInput );
const analysisResult = calculateAnalysisScore( customerInput?.trim() );
setAnalysisScore( analysisResult );
setIsValidInput( analysisResult >= 2 );
}, [ customerInput ] );

Check warning on line 24 in src/OnboardingSPA/components/TextInput/TextInputSiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'height' and 'setIsValidInput'. Either include them or remove the dependency array. If 'setIsValidInput' changes too often, find the parent component that defines it and wrap that definition in useCallback

const calculateAnalysisScore = ( input ) => {
/* Number of Characters in the input
Expand Down Expand Up @@ -87,7 +88,7 @@
{ customerInput ? (
<div className={ 'nfd-sg-input-box__info' }>
<div className={ 'nfd-sg-input-box__info-text' }>
Detail
{ __( 'Detail', 'wp-module-onboarding' ) }
</div>
{ renderDetails() }
</div>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/OnboardingSPA/steps/SiteGen/Building/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CommonLayout from '../../../components/Layouts/Common';

import { useEffect } from '@wordpress/element';
import { memo, useEffect } from '@wordpress/element';

import { useDispatch } from '@wordpress/data';
import { store as nfdOnboardingStore } from '../../../store';
Expand Down Expand Up @@ -42,4 +42,4 @@ const SiteGenBuilding = () => {
);
};

export default SiteGenBuilding;
export default memo( SiteGenBuilding );
12 changes: 9 additions & 3 deletions src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,22 @@
setDrawerActiveView( false );

if ( currentData.sitegen.siteDetails?.prompt !== '' ) {
setIsValidInput( true );
setFooterNavEnabled( true );
return setCustomerInput( currentData.sitegen.siteDetails.prompt );
}
setFooterNavEnabled( false );
}, [] );

Check warning on line 48 in src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'currentData.sitegen.siteDetails.prompt', 'setDrawerActiveView', 'setFooterNavEnabled', 'setHeaderActiveView', 'setIsHeaderEnabled', and 'setSidebarActiveView'. Either include them or remove the dependency array

useEffect( () => {
setFooterNavEnabled( isValidInput );
currentData.sitegen.siteDetails.prompt = customerInput;
setCurrentOnboardingData( currentData );
if ( customerInput?.trim() === '' ) {
setFooterNavEnabled( false );
} else {
setFooterNavEnabled( isValidInput );
currentData.sitegen.siteDetails.prompt = customerInput?.trim();
setCurrentOnboardingData( currentData );
}
}, [ customerInput ] );

Check warning on line 58 in src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'currentData', 'isValidInput', 'setCurrentOnboardingData', and 'setFooterNavEnabled'. Either include them or remove the dependency array

return (
<CommonLayout isCentered>
Expand Down
4 changes: 2 additions & 2 deletions src/OnboardingSPA/steps/SiteGen/SocialMedia/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useDispatch } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { memo, useEffect } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';

import getContents from './contents';
Expand Down Expand Up @@ -64,4 +64,4 @@ const SiteGenSiteSocialMedia = () => {
);
};

export default SiteGenSiteSocialMedia;
export default memo( SiteGenSiteSocialMedia );
4 changes: 2 additions & 2 deletions src/OnboardingSPA/steps/SiteGen/Welcome/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from '@wordpress/element';
import { memo, useEffect } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';

import CommonLayout from '../../../components/Layouts/Common';
Expand Down Expand Up @@ -46,4 +46,4 @@ const SiteGenWelcome = () => {
);
};

export default SiteGenWelcome;
export default memo( SiteGenWelcome );
2 changes: 2 additions & 0 deletions src/OnboardingSPA/steps/SiteGen/Welcome/stylesheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

@media (max-width: #{ ($break-small) }) {
margin: 16px;
margin-bottom: 100px;
}

@media (min-width: 2600px ) {
Expand Down Expand Up @@ -71,6 +72,7 @@
width: 100%;
margin: 10px;
padding: 0;
margin-bottom: 40px;

&__text {
text-align: center;
Expand Down