Skip to content

Commit

Permalink
Merge pull request #400 from newfold-labs/enhance/improve-performance
Browse files Browse the repository at this point in the history
Improve performance
  • Loading branch information
arunshenoy99 authored Jan 9, 2024
2 parents 731d752 + c69a9dd commit 02b803c
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 20 deletions.
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 @@ -22,7 +22,9 @@ const SiteGenLoader = ( { autoNavigate = false } ) => {
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 Down Expand Up @@ -65,4 +67,4 @@ const SiteGenLoader = ( { autoNavigate = false } ) => {
);
};

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,7 +18,7 @@ const TextInputSiteGen = ( {
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 ] );
Expand Down Expand Up @@ -87,7 +88,7 @@ const TextInputSiteGen = ( {
{ 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,15 +40,21 @@ const SiteGenSiteDetails = () => {
setDrawerActiveView( false );

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

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 ] );

return (
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

0 comments on commit 02b803c

Please sign in to comment.