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

PRESS 2 498 | Audit memoization candidates #157

Merged
merged 26 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b5267af
Refactored Skeleton to be a React.memo component
officiallygod Jan 12, 2023
9ff7324
Added React Memo in Skeletons
officiallygod Jan 12, 2023
b9029a4
Revert "Added React Memo in Skeletons"
officiallygod Jan 13, 2023
848e2c9
Removed Log
officiallygod Jan 13, 2023
32b66a8
Merge branch 'trunk' into PRESS-2-498-Audit-Memoization-Candidates
officiallygod Jan 18, 2023
0582614
Memoized Global Styles Output
officiallygod Jan 20, 2023
a2a8a17
Merge branch 'trunk' into PRESS-2-498-Audit-Memoization-Candidates
officiallygod Jan 20, 2023
ec0012b
Added Memoization to Basic Info
officiallygod Jan 23, 2023
5fb81a4
Added memo to Card Header
officiallygod Jan 23, 2023
b83d5cb
Reduced API Calls for Global Styles
officiallygod Jan 24, 2023
4176df0
Merge branch 'trunk' into PRESS-2-498-Audit-Memoization-Candidates
officiallygod Feb 1, 2023
7fb0072
Lint for JS
officiallygod Feb 1, 2023
cbe694e
Header.js
officiallygod Feb 2, 2023
ff045e9
Refactored Drawer
officiallygod Feb 2, 2023
2c081c9
Drawer.js
officiallygod Feb 2, 2023
14b7615
Sidebar.js
officiallygod Feb 2, 2023
3607ff7
Refactored Experience to not use UseEffect
officiallygod Feb 2, 2023
9ce7a52
Removed lodash memoize
officiallygod Feb 6, 2023
5a4655c
Delete build/1.0.4 directory
officiallygod Feb 7, 2023
7a0a900
Revert "Delete build/1.0.4 directory"
officiallygod Feb 8, 2023
da76771
Added Build Folder
officiallygod Feb 8, 2023
eb6c504
Merge branch 'trunk' into PRESS-2-498-Audit-Memoization-Candidates
officiallygod Feb 8, 2023
3b4aa37
Merge branch 'trunk' into PRESS-2-498-Audit-Memoization-Candidates
officiallygod Feb 8, 2023
8cd9f88
Update use-global-styles-output.js
officiallygod Feb 9, 2023
20e6d04
Lint Changes
officiallygod Feb 9, 2023
d11b336
Update use-global-styles-output.js
officiallygod Feb 9, 2023
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
29 changes: 20 additions & 9 deletions src/OnboardingSPA/components/CardHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@
* @return CardHeader
*/

import React from 'react';

const CardHeader = ({ heading, subHeading, question }) => {
import { memo } from '@wordpress/element';

const CardHeader = ( { heading, subHeading, question } ) => {
return (
<div>
{heading && <h2 className="nfd-step-card-heading">{heading}</h2>}
{ heading && (
<h2 className="nfd-step-card-heading">{ heading }</h2>
) }

{subHeading && (
<h3 className={ question ? "nfd-step-card-subheading-other" : "nfd-step-card-subheading" }>{subHeading}</h3>
)}
{ subHeading && (
<h3
className={
question
? 'nfd-step-card-subheading-other'
: 'nfd-step-card-subheading'
}
>
{ subHeading }
</h3>
) }

{question && <h3 className="nfd-step-card-question">{question}</h3>}
{ question && (
<h3 className="nfd-step-card-question">{ question }</h3>
) }
</div>
);
};

export default CardHeader;
export default memo( CardHeader );
41 changes: 19 additions & 22 deletions src/OnboardingSPA/components/Drawer/DrawerPanel/DesignColors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Popover, ColorPicker } from '@wordpress/components';
import { store as nfdOnboardingStore } from '../../../store';
import { getGlobalStyles, getThemeColors } from '../../../utils/api/themes';
import { useGlobalStylesOutput } from '../../../utils/global-styles/use-global-styles-output';
import { GlobalStylesProvider } from '../../LivePreview';
import Animate from '../../Animate';

const DesignColors = () => {
Expand Down Expand Up @@ -96,7 +95,7 @@ const DesignColors = () => {
const slug = selectedThemeColorPalette[ idx ]?.slug;
if (
isCustomStyle &&
selectedColorsLocalTemp?.[ slug ] != ''
selectedColorsLocalTemp?.[ slug ] !== ''
)
selectedThemeColorPalette[ idx ].color =
selectedColorsLocalTemp[ slug ];
Expand Down Expand Up @@ -142,31 +141,31 @@ const DesignColors = () => {
switch ( selectedThemeColorPalette[ idx ]?.slug ) {
case 'base':
if (
colorPickerCalledBy == 'base' &&
colorPickerCalledBy === 'base' &&
customColors?.base
)
selectedThemeColorPalette[ idx ].color =
customColors?.base;
break;
case 'primary':
if (
colorPickerCalledBy == 'primary' &&
colorPickerCalledBy === 'primary' &&
customColors?.primary
)
selectedThemeColorPalette[ idx ].color =
customColors?.primary;
break;
case 'secondary':
if (
colorPickerCalledBy == 'secondary' &&
colorPickerCalledBy === 'secondary' &&
customColors?.secondary
)
selectedThemeColorPalette[ idx ].color =
customColors?.secondary;
break;
case 'tertiary':
if (
colorPickerCalledBy == 'tertiary' &&
colorPickerCalledBy === 'tertiary' &&
customColors?.tertiary
)
selectedThemeColorPalette[ idx ].color =
Expand Down Expand Up @@ -278,7 +277,7 @@ const DesignColors = () => {
<div
key={ colorStyle }
className={ `color-palette ${
colorStyle == selectedColors?.slug
colorStyle === selectedColors?.slug
? 'color-palette-selected'
: ''
} ` }
Expand Down Expand Up @@ -317,15 +316,15 @@ const DesignColors = () => {

function buildCustomPalette() {
const primaryColorTemp =
customColors && customColors?.primary != ''
customColors && customColors?.primary !== ''
? customColors?.primary
: selectedColorsLocal?.primary ?? '#fff';
const secondaryColorTemp =
customColors && customColors?.secondary != ''
customColors && customColors?.secondary !== ''
? customColors?.secondary
: selectedColorsLocal?.secondary ?? '#fff';
const tertiaryColorTemp =
customColors && customColors?.tertiary != ''
customColors && customColors?.tertiary !== ''
? customColors?.tertiary
: selectedColorsLocal?.tertiary ?? '#fff';

Expand Down Expand Up @@ -455,18 +454,16 @@ const DesignColors = () => {
}

return (
<GlobalStylesProvider>
<div className="theme-colors--drawer">
<h2>{ __( 'Color Palettes', 'wp-module-onboarding' ) }</h2>
{ /* {selectedColors?.slug &&
<div className='theme-colors--drawer--reset' onClick={resetColors}>
<div>Reset Button</div>
</div>
} */ }
{ colorPalettes && buildPalettes() }
{ colorPalettes && buildCustomPalette() }
</div>
</GlobalStylesProvider>
<div className="theme-colors--drawer">
<h2>{ __( 'Color Palettes', 'wp-module-onboarding' ) }</h2>
{ /* {selectedColors?.slug &&
<div className='theme-colors--drawer--reset' onClick={resetColors}>
<div>Reset Button</div>
</div>
} */ }
{ colorPalettes && buildPalettes() }
{ colorPalettes && buildCustomPalette() }
</div>
);
};

Expand Down
29 changes: 14 additions & 15 deletions src/OnboardingSPA/components/Drawer/DrawerPanel/DesignTypography.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { useState, useEffect, useRef } from '@wordpress/element';

import { store as nfdOnboardingStore } from '../../../store';
import { GlobalStylesProvider } from '../../../components/LivePreview';
import { getGlobalStyles, getThemeFonts } from '../../../utils/api/themes';
import { useGlobalStylesOutput } from '../../../utils/global-styles/use-global-styles-output';

Expand Down Expand Up @@ -131,11 +130,13 @@ const DesignTypography = () => {
const paletteRenderedList = [];
for ( const fontStyle in fontPalettes ) {
const splitLabel = fontPalettes[ fontStyle ]?.label.split( '&', 2 );
if ( splitLabel.length == 0 ) continue;
if ( splitLabel.length === 0 ) continue;
paletteRenderedList.push(
<div
className={ `font-palette ${
selectedFont == fontStyle ? 'font-palette-selected' : ''
selectedFont === fontStyle
? 'font-palette-selected'
: ''
} ` }
onClick={ ( e ) => handleClick( fontStyle ) }
>
Expand Down Expand Up @@ -202,19 +203,17 @@ const DesignTypography = () => {
}

return (
<GlobalStylesProvider>
<div ref={ drawerFontOptions } className="theme-fonts--drawer">
<h2>{ __( 'Font Palettes', 'wp-module-onboarding' ) }</h2>
{ /* { selectedFont &&
<div className='theme-fonts--drawer--reset' onClick={resetFonts}>
<div>Reset Button</div>
</div>
} */ }
{ fontPalettes && buildPalettes() }
{ /* { fontPalettes && buildCustomPalette() } */ }
<div className="custom-font-palette--hidden">{ rerender }</div>
<div ref={ drawerFontOptions } className="theme-fonts--drawer">
<h2>{ __( 'Font Palettes', 'wp-module-onboarding' ) }</h2>
{ /* { selectedFont &&
<div className='theme-fonts--drawer--reset' onClick={resetFonts}>
<div>Reset Button</div>
</div>
</GlobalStylesProvider>
} */ }
{ fontPalettes && buildPalettes() }
{ /* { fontPalettes && buildCustomPalette() } */ }
<div className="custom-font-palette--hidden">{ rerender }</div>
</div>
);
};
export default DesignTypography;
4 changes: 2 additions & 2 deletions src/OnboardingSPA/components/ImageUploader/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { __ } from '@wordpress/i18n';
import { useRef, useState } from '@wordpress/element';
import { memo, useRef, useState } from '@wordpress/element';

import { ImageUploadLoader } from '../Loaders';
import { uploadImage } from '../../utils/api/uploader';
Expand Down Expand Up @@ -104,4 +104,4 @@ const ImageUploader = ({ icon, iconSetter }) => {
);
};

export default ImageUploader;
export default memo(ImageUploader);
32 changes: 18 additions & 14 deletions src/OnboardingSPA/components/LivePreview/BlockPreview/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useSelect } from '@wordpress/data';
import { BlockEditorProvider } from '@wordpress/block-editor';
import { parse } from '@wordpress/blocks';
import { useEffect, useState } from '@wordpress/element';
import { useEffect, useState, memo } from '@wordpress/element';

import AutoHeightBlockPreview from './auto';
import { useGlobalStylesOutput } from '../../../utils/global-styles/use-global-styles-output';
Expand Down Expand Up @@ -76,21 +76,25 @@ const BlockPreview = ( {
}
}, [ storedPreviewSettings ] );

const SkeletonLivePreview = memo( () => {
return (
<div className="live-preview__container--is-skeleton">
Yashita101 marked this conversation as resolved.
Show resolved Hide resolved
<div className="live-preview__container--is-skeleton--box live-preview__container--is-skeleton--box-header">
<Animate
type={ 'shine' }
className="live-preview__container--is-skeleton--shimmer"
></Animate>
</div>
<div className="live-preview__container--is-skeleton--box live-preview__container--is-skeleton--box-body-1" />
<div className="live-preview__container--is-skeleton--box live-preview__container--is-skeleton--box-body-2" />
<div className="live-preview__container--is-skeleton--box live-preview__container--is-skeleton--box-footer" />
</div>
);
} );

return (
<div className={ `live-preview__container-${ styling }` }>
{ loading && (
<div className="live-preview__container--is-skeleton">
<div className="live-preview__container--is-skeleton--box live-preview__container--is-skeleton--box-header">
<Animate
type={ 'shine' }
className="live-preview__container--is-skeleton--shimmer"
></Animate>
</div>
<div className="live-preview__container--is-skeleton--box live-preview__container--is-skeleton--box-body-1" />
<div className="live-preview__container--is-skeleton--box live-preview__container--is-skeleton--box-body-2" />
<div className="live-preview__container--is-skeleton--box live-preview__container--is-skeleton--box-footer" />
</div>
) }
{ loading && <SkeletonLivePreview /> }
{ settings && (
<BlockEditorProvider
value={ blocks }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { useState, useEffect } from '@wordpress/element';

import { store as nfdOnboardingStore } from '../../../store';
import { THEME_STATUS_NOT_ACTIVE } from '../../../../constants';
import { getGlobalStyles, setGlobalStyles } from '../../../utils/api/themes';
import { useGlobalStylesOutput } from '../../../utils/global-styles/use-global-styles-output';

Expand Down Expand Up @@ -29,20 +30,22 @@ const GlobalStylesProvider = ( { children } ) => {
useDispatch( nfdOnboardingStore );

const getStylesAndPatterns = async () => {
const globalStyles = await getGlobalStyles();
if ( globalStyles?.error ) {
return updateThemeStatus( THEME_STATUS_NOT_ACTIVE );
}
let selectedGlobalStyle;
if ( storedPreviewSettings?.title && storedPreviewSettings?.settings )
selectedGlobalStyle = storedPreviewSettings;
else if ( currentData.data.theme.variation ) {
selectedGlobalStyle = globalStyles.body.filter(
( globalStyle ) =>
globalStyle.title === currentData.data.theme.variation
)[ 0 ];
} else if ( globalStyles.body[ 0 ]?.id === 0 ) {
selectedGlobalStyle = globalStyles.body[ 0 ];
else {
const globalStyles = await getGlobalStyles();
if ( globalStyles?.error ) {
return updateThemeStatus( THEME_STATUS_NOT_ACTIVE );
}
if ( currentData.data.theme.variation ) {
selectedGlobalStyle = globalStyles.body.filter(
( globalStyle ) =>
globalStyle.title === currentData.data.theme.variation
)[ 0 ];
} else if ( globalStyles.body[ 0 ]?.id === 0 ) {
selectedGlobalStyle = globalStyles.body[ 0 ];
}
}

if ( selectedGlobalStyle )
Expand Down
4 changes: 2 additions & 2 deletions src/OnboardingSPA/components/MiniPreview/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { __, sprintf } from '@wordpress/i18n';
import { useState, useEffect } from '@wordpress/element';
import { memo, useState, useEffect } from '@wordpress/element';

import content from './miniPreview.json';
import { translations } from '../../utils/locales/translations';
Expand Down Expand Up @@ -159,4 +159,4 @@ const MiniPreview = ({ title, desc, icon, socialData, isSocialFormOpen, setIsSoc
);
};

export default MiniPreview;
export default memo(MiniPreview);
Loading