diff --git a/src/OnboardingSPA/components/CardHeader/index.js b/src/OnboardingSPA/components/CardHeader/index.js index dee9f00fe..d0939b44b 100644 --- a/src/OnboardingSPA/components/CardHeader/index.js +++ b/src/OnboardingSPA/components/CardHeader/index.js @@ -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 (
- {heading &&

{heading}

} + { heading && ( +

{ heading }

+ ) } - {subHeading && ( -

{subHeading}

- )} + { subHeading && ( +

+ { subHeading } +

+ ) } - {question &&

{question}

} + { question && ( +

{ question }

+ ) }
); }; -export default CardHeader; +export default memo( CardHeader ); diff --git a/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignColors.js b/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignColors.js index 21dbf016a..591fd4c44 100644 --- a/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignColors.js +++ b/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignColors.js @@ -6,11 +6,7 @@ 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 { - THEME_STATUS_ACTIVE, - THEME_STATUS_INIT, -} from '../../../../constants'; +import { THEME_STATUS_ACTIVE, THEME_STATUS_INIT } from '../../../../constants'; import Animate from '../../Animate'; const DesignColors = () => { @@ -107,7 +103,7 @@ const DesignColors = () => { const slug = selectedThemeColorPalette[ idx ]?.slug; if ( isCustomStyle && - selectedColorsLocalTemp?.[ slug ] != '' + selectedColorsLocalTemp?.[ slug ] !== '' ) selectedThemeColorPalette[ idx ].color = selectedColorsLocalTemp[ slug ]; @@ -153,7 +149,7 @@ const DesignColors = () => { switch ( selectedThemeColorPalette[ idx ]?.slug ) { case 'base': if ( - colorPickerCalledBy == 'base' && + colorPickerCalledBy === 'base' && customColors?.base ) selectedThemeColorPalette[ idx ].color = @@ -161,7 +157,7 @@ const DesignColors = () => { break; case 'primary': if ( - colorPickerCalledBy == 'primary' && + colorPickerCalledBy === 'primary' && customColors?.primary ) selectedThemeColorPalette[ idx ].color = @@ -169,7 +165,7 @@ const DesignColors = () => { break; case 'secondary': if ( - colorPickerCalledBy == 'secondary' && + colorPickerCalledBy === 'secondary' && customColors?.secondary ) selectedThemeColorPalette[ idx ].color = @@ -177,7 +173,7 @@ const DesignColors = () => { break; case 'tertiary': if ( - colorPickerCalledBy == 'tertiary' && + colorPickerCalledBy === 'tertiary' && customColors?.tertiary ) selectedThemeColorPalette[ idx ].color = @@ -332,15 +328,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'; @@ -470,18 +466,16 @@ const DesignColors = () => { } return ( - -
-

{ __( 'Color Palettes', 'wp-module-onboarding' ) }

- { /* {selectedColors?.slug && -
-
Reset Button
-
- } */ } - { colorPalettes && buildPalettes() } - { colorPalettes && buildCustomPalette() } -
-
+
+

{ __( 'Color Palettes', 'wp-module-onboarding' ) }

+ { /* {selectedColors?.slug && +
+
Reset Button
+
+ } */ } + { colorPalettes && buildPalettes() } + { colorPalettes && buildCustomPalette() } +
); }; diff --git a/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignTypography.js b/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignTypography.js index 3ec587d9d..6020931c3 100644 --- a/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignTypography.js +++ b/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignTypography.js @@ -3,13 +3,9 @@ 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'; -import { - THEME_STATUS_ACTIVE, - THEME_STATUS_INIT, -} from '../../../../constants'; +import { THEME_STATUS_ACTIVE, THEME_STATUS_INIT } from '../../../../constants'; const DesignTypography = () => { const drawerFontOptions = useRef(); @@ -146,7 +142,7 @@ 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(
{ } return ( - -
-

{ __( 'Font Palettes', 'wp-module-onboarding' ) }

- { /* { selectedFont && -
-
Reset Button
-
- } */ } - { fontPalettes && buildPalettes() } - { /* { fontPalettes && buildCustomPalette() } */ } -
{ rerender }
+
+

{ __( 'Font Palettes', 'wp-module-onboarding' ) }

+ { /* { selectedFont && +
+
Reset Button
- + } */ } + { fontPalettes && buildPalettes() } + { /* { fontPalettes && buildCustomPalette() } */ } +
{ rerender }
+
); }; export default DesignTypography; diff --git a/src/OnboardingSPA/components/Drawer/DrawerPanel/index.js b/src/OnboardingSPA/components/Drawer/DrawerPanel/index.js index 387a416a3..cdd75fd45 100644 --- a/src/OnboardingSPA/components/Drawer/DrawerPanel/index.js +++ b/src/OnboardingSPA/components/Drawer/DrawerPanel/index.js @@ -34,7 +34,7 @@ import classNames from 'classnames'; import { store as nfdOnboardingStore } from '../../../store'; import WithDesignBack from './WithDesignBack'; -const DrawerPanel = ( { isOpen } ) => { +const DrawerPanel = () => { const [ isNavView, setIsNavView ] = useState( true ); // menu-primary is default view const { isDrawerOpen, drawerView } = useSelect( ( select ) => { const { isDrawerOpened, getDrawerView } = select( nfdOnboardingStore ); @@ -121,7 +121,7 @@ const DrawerPanel = ( { isOpen } ) => { - )} + ) }
diff --git a/src/OnboardingSPA/components/Drawer/DrawerToggle/index.js b/src/OnboardingSPA/components/Drawer/DrawerToggle/index.js index 1506bd67a..cfc95b188 100644 --- a/src/OnboardingSPA/components/Drawer/DrawerToggle/index.js +++ b/src/OnboardingSPA/components/Drawer/DrawerToggle/index.js @@ -1,59 +1,57 @@ -import { - Button, - Icon, - __unstableMotion as motion, -} from '@wordpress/components'; +import { Button, __unstableMotion as motion } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; +import { useEffect, useRef } from '@wordpress/element'; +import { useDispatch, useSelect } from '@wordpress/data'; + import classNames from 'classnames'; import { store as nfdOnboardingStore } from '../../../store'; -import { useDispatch, useSelect } from '@wordpress/data'; -import { useEffect, useRef } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; -import { wordpress } from '@wordpress/icons'; - -const DrawerToggle = ({ isOpen }) => { - const { isDrawerOpen, isDrawerSuppressed } = useSelect((select) => { +const DrawerToggle = ( { isOpen } ) => { + const { isDrawerOpen, isDrawerSuppressed } = useSelect( ( select ) => { return { - isDrawerOpen: select(nfdOnboardingStore).isDrawerOpened(), - isDrawerSuppressed: select(nfdOnboardingStore).isDrawerSuppressed(), + isDrawerOpen: select( nfdOnboardingStore ).isDrawerOpened(), + isDrawerSuppressed: + select( nfdOnboardingStore ).isDrawerSuppressed(), }; - }, []); + }, [] ); - const { setIsDrawerOpened } = useDispatch(nfdOnboardingStore); + const { setIsDrawerOpened } = useDispatch( nfdOnboardingStore ); const drawerToggleRef = useRef(); - useEffect(() => { - if (!isDrawerOpen) { + useEffect( () => { + if ( ! isDrawerOpen ) { drawerToggleRef.current.focus(); } - }, [isDrawerOpen]); + }, [ isDrawerOpen ] ); const toggleDrawer = () => { - isDrawerSuppressed || setIsDrawerOpened(!isDrawerOpen); - } + isDrawerSuppressed || setIsDrawerOpened( ! isDrawerOpen ); + }; return ( diff --git a/src/OnboardingSPA/components/Drawer/index.js b/src/OnboardingSPA/components/Drawer/index.js index 9b8908c6a..8bca38ffc 100644 --- a/src/OnboardingSPA/components/Drawer/index.js +++ b/src/OnboardingSPA/components/Drawer/index.js @@ -1,23 +1,24 @@ -import { Fragment, useEffect } from '@wordpress/element'; +import { useDispatch } from '@wordpress/data'; +import { useViewportMatch } from '@wordpress/compose'; +import { Fragment, useEffect, memo } from '@wordpress/element'; import DrawerPanel from './DrawerPanel'; import DrawerToggle from './DrawerToggle'; import { store as nfdOnboardingStore } from '../../store'; -import { useDispatch } from '@wordpress/data'; -import { useViewportMatch } from '@wordpress/compose'; /** * Off-canvas drawer to left of viewport. + * * @param {*} param0 - * @returns + * @return */ -const Drawer = ({ isDefaultOpen = false }) => { - const isDesktopViewport = useViewportMatch('medium'); - const { setIsDrawerOpened } = useDispatch(nfdOnboardingStore); +const Drawer = ( { isDefaultOpen = false } ) => { + const isDesktopViewport = useViewportMatch( 'medium' ); + const { setIsDrawerOpened } = useDispatch( nfdOnboardingStore ); - useEffect(() => { - setIsDrawerOpened(isDefaultOpen && isDesktopViewport); - }, [isDefaultOpen, isDesktopViewport, setIsDrawerOpened]); + useEffect( () => { + setIsDrawerOpened( isDefaultOpen && isDesktopViewport ); + }, [ isDefaultOpen, isDesktopViewport, setIsDrawerOpened ] ); return ( @@ -27,4 +28,4 @@ const Drawer = ({ isDefaultOpen = false }) => { ); }; -export default Drawer; +export default memo( Drawer ); diff --git a/src/OnboardingSPA/components/Header/index.js b/src/OnboardingSPA/components/Header/index.js index b612ef7c7..45d7da21a 100644 --- a/src/OnboardingSPA/components/Header/index.js +++ b/src/OnboardingSPA/components/Header/index.js @@ -1,10 +1,11 @@ -import { useLocation } from 'react-router-dom'; import { __ } from '@wordpress/i18n'; +import { useLocation } from 'react-router-dom'; +import { memo } from '@wordpress/element'; import { useSelect } from '@wordpress/data'; -import { store as nfdOnboardingStore } from '../../store'; -import ExitToWordPress from '../ExitToWordPress'; import HeaderEnd from './components/HeaderEnd'; +import ExitToWordPress from '../ExitToWordPress'; +import { store as nfdOnboardingStore } from '../../store'; /** * Interface header rendered into header render prop in . @@ -19,15 +20,7 @@ const Header = () => { firstStep: select( nfdOnboardingStore ).getFirstStep(), }; }, [] ); - const { previousStep, nextStep } = useSelect( - ( select ) => { - return { - previousStep: select( nfdOnboardingStore ).getPreviousStep(), - nextStep: select( nfdOnboardingStore ).getNextStep(), - }; - }, - [ location.path ] - ); + const isGettingStarted = firstStep?.path === location?.pathname; return (
@@ -46,4 +39,4 @@ const Header = () => { ); }; -export default Header; +export default memo( Header ); diff --git a/src/OnboardingSPA/components/ImageUploader/index.js b/src/OnboardingSPA/components/ImageUploader/index.js index c629665e2..c4a469b65 100644 --- a/src/OnboardingSPA/components/ImageUploader/index.js +++ b/src/OnboardingSPA/components/ImageUploader/index.js @@ -1,107 +1,108 @@ -import { __ } from '@wordpress/i18n'; -import { useRef, useState } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; +import { memo, useRef, useState } from '@wordpress/element'; import { ImageUploadLoader } from '../Loaders'; import { uploadImage } from '../../utils/api/uploader'; - /* +/* * Image Uploader * */ -const ImageUploader = ({ icon, iconSetter }) => { +const ImageUploader = ( { icon, iconSetter } ) => { + const inputRef = useRef( null ); + const [ isUploading, setIsUploading ] = useState( false ); - const inputRef = useRef(null); - const [isUploading, setIsUploading] = useState(false); + async function updateItem( fileData ) { + if ( fileData ) { + setIsUploading( true ); + const res = await uploadImage( fileData ); + if ( res ) { + const id = res?.body?.id; + const url = res?.body?.source_url; + iconSetter( { + id, + url, + } ); + } else console.error( 'Image Upload Failed' ); + } else console.error( 'No File Attached' ); - async function updateItem(fileData) { - if(fileData){ - setIsUploading(true); - const res = await uploadImage(fileData); - if (res) { - const id = res?.body?.id; - const url = res?.body?.source_url; - iconSetter({ - id, - url - }); - } - else console.error('Image Upload Failed'); - } - else console.error('No File Attached'); + setIsUploading( false ); + } - setIsUploading(false); - } + const handleClick = () => { + inputRef?.current.click(); + }; - const handleClick = () => { - inputRef?.current.click(); - }; + const imageChange = ( e ) => { + if ( e?.target?.files && e?.target?.files.length > 0 ) { + updateItem( e?.target?.files[ 0 ] ); + } + }; - const imageChange = (e) => { - if (e?.target?.files && e?.target?.files.length > 0) { - updateItem(e?.target?.files[0]); - } - }; + const removeSelectedImage = () => { + iconSetter( 0 ); + if ( inputRef?.current?.files.length > 0 ) { + inputRef.current.value = ''; + } + }; + function loader() { + return ( +
+ +
+ ); + } + function getImageUploadWindow() { + return ( +
+
+
+ { ( icon == 0 || icon == undefined ) && ( +
+ ) } + { icon != 0 && icon != undefined && ( + Thumb + ) } +
+
+ { icon != 0 && icon != undefined && ( + + ) } + { ( icon == 0 || icon == undefined ) && ( + + ) } + +
+
+ ); + } - const removeSelectedImage = () => { - iconSetter(0); - if (inputRef?.current?.files.length > 0){ - inputRef.current.value = ""; - } - }; - function loader(){ - return ( -
- -
); - } - function getImageUploadWindow() { - return ( -
-
-
- {(icon == 0 || icon == undefined) && ( -
) - } - {(icon != 0 && icon != undefined) && ( - Thumb - )} -
-
- {(icon != 0 && icon != undefined) && ()} - {(icon == 0 || icon == undefined) && ()} - -
-
); - } - - return ( -
-

Logo

- { isUploading ? loader() : getImageUploadWindow() } -
- ); + return ( +
+

Logo

+ { isUploading ? loader() : getImageUploadWindow() } +
+ ); }; -export default ImageUploader; +export default memo( ImageUploader ); diff --git a/src/OnboardingSPA/components/LivePreview/BlockPreview/index.js b/src/OnboardingSPA/components/LivePreview/BlockPreview/index.js index e34a32660..70d69e684 100644 --- a/src/OnboardingSPA/components/LivePreview/BlockPreview/index.js +++ b/src/OnboardingSPA/components/LivePreview/BlockPreview/index.js @@ -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'; @@ -76,21 +76,25 @@ const BlockPreview = ( { } }, [ storedPreviewSettings ] ); + const SkeletonLivePreview = memo( () => { + return ( +
+
+ +
+
+
+
+
+ ); + } ); + return (
- { loading && ( -
-
- -
-
-
-
-
- ) } + { loading && } { settings && ( { useDispatch( nfdOnboardingStore ); const getStylesAndPatterns = async () => { - const globalStyles = await getGlobalStyles(); - if ( globalStyles?.error ) { - return updateThemeStatus( THEME_STATUS_INIT ); - } 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_INIT ); + } + 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 ) diff --git a/src/OnboardingSPA/components/MiniPreview/index.js b/src/OnboardingSPA/components/MiniPreview/index.js index b8a4c4d33..2bf4609be 100644 --- a/src/OnboardingSPA/components/MiniPreview/index.js +++ b/src/OnboardingSPA/components/MiniPreview/index.js @@ -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'; @@ -7,156 +7,221 @@ import { translations } from '../../utils/locales/translations'; /** * A Mini Preview Section. * - * @returns + * @param root0 + * @param root0.title + * @param root0.desc + * @param root0.icon + * @param root0.socialData + * @param root0.isSocialFormOpen + * @param root0.setIsSocialFormOpen + * @return */ -const MiniPreview = ({ title, desc, icon, socialData, isSocialFormOpen, setIsSocialFormOpen }) => { - - var iconPreview = icon == "" || icon == undefined ? content.icon : icon; - var titlePreview = title == "" ? sprintf(__(content.title, 'wp-module-onboarding'), translations('Site')) : title; - var descPreview = desc == "" ? sprintf(__(content.desc, 'wp-module-onboarding'), translations('Site')) : desc; - var urlPreview = title == "" ? content.url : titleToUrl(title); +const MiniPreview = ( { + title, + desc, + icon, + socialData, + isSocialFormOpen, + setIsSocialFormOpen, +} ) => { + const iconPreview = icon == '' || icon == undefined ? content.icon : icon; + const titlePreview = + title == '' + ? sprintf( + __( content.title, 'wp-module-onboarding' ), + translations( 'Site' ) + ) + : title; + const descPreview = + desc == '' + ? sprintf( + __( content.desc, 'wp-module-onboarding' ), + translations( 'Site' ) + ) + : desc; + const urlPreview = title == '' ? content.url : titleToUrl( title ); - const [facebook, setFacebook] = useState(""); - const [twitter, setTwitter] = useState(""); - const [instagram, setInstagram] = useState(""); - const [youtube, setYouTube] = useState(""); - const [linkedin, setLinkedIn] = useState(""); - const [yelp, setYelp] = useState(""); - const [tiktok, setTikTok] = useState(""); + const [ facebook, setFacebook ] = useState( '' ); + const [ twitter, setTwitter ] = useState( '' ); + const [ instagram, setInstagram ] = useState( '' ); + const [ youtube, setYouTube ] = useState( '' ); + const [ linkedin, setLinkedIn ] = useState( '' ); + const [ yelp, setYelp ] = useState( '' ); + const [ tiktok, setTikTok ] = useState( '' ); - useEffect(() => { - setFacebook((socialData?.facebook_site) ?? ""); - setTwitter(socialData?.twitter_site ?? ""); - setInstagram(socialData?.instagram_url ?? ""); - setYouTube(socialData?.youtube_url ?? ""); - setLinkedIn(socialData?.linkedin_url ?? ""); - if ( + useEffect( () => { + setFacebook( socialData?.facebook_site ?? '' ); + setTwitter( socialData?.twitter_site ?? '' ); + setInstagram( socialData?.instagram_url ?? '' ); + setYouTube( socialData?.youtube_url ?? '' ); + setLinkedIn( socialData?.linkedin_url ?? '' ); + if ( socialData && Object.keys( socialData ).includes( 'other_social_urls' ) - ) - { - const otherURLS = socialData.other_social_urls; - if (Object.keys(otherURLS).includes("yelp_url")) - setYelp(otherURLS["yelp_url"] ?? ""); + ) { + const otherURLS = socialData.other_social_urls; + if ( Object.keys( otherURLS ).includes( 'yelp_url' ) ) + setYelp( otherURLS.yelp_url ?? '' ); - if (Object.keys(otherURLS).includes("tiktok_url")) - setTikTok(otherURLS["tiktok_url"] ?? ""); - } - }, [socialData]); + if ( Object.keys( otherURLS ).includes( 'tiktok_url' ) ) + setTikTok( otherURLS.tiktok_url ?? '' ); + } + }, [ socialData ] ); - const isValidUrl = (urlString) => { - let url; - try { - url = new URL(urlString); - } - catch (e) { - return false; - } + const isValidUrl = ( urlString ) => { + let url; + try { + url = new URL( urlString ); + } catch ( e ) { + return false; + } - if (url.protocol !== "http:" && url.protocol !== "https:") - return false; - return true; - } + if ( url.protocol !== 'http:' && url.protocol !== 'https:' ) + return false; + return true; + }; - var socialDataset = [ - {url: facebook, image: 'var(--facebook-colored-icon)'}, - {url: twitter, image: 'var(--twitter-colored-icon)'}, - {url: instagram, image: 'var(--instagram-colored-icon)'}, - {url: youtube, image: 'var(--youtube-colored-icon)'}, - {url: linkedin, image: 'var(--linkedin-colored-icon)'}, - {url: yelp, image: 'var(--yelp-colored-icon)'}, - {url: tiktok, image: 'var(--tiktok-colored-icon)'}, - ] - - function titleToUrl(title) { - return `https://${title?.toLowerCase().replace(/\s/g, '').replace(/\W/g, '')}.com`; - } + const socialDataset = [ + { url: facebook, image: 'var(--facebook-colored-icon)' }, + { url: twitter, image: 'var(--twitter-colored-icon)' }, + { url: instagram, image: 'var(--instagram-colored-icon)' }, + { url: youtube, image: 'var(--youtube-colored-icon)' }, + { url: linkedin, image: 'var(--linkedin-colored-icon)' }, + { url: yelp, image: 'var(--yelp-colored-icon)' }, + { url: tiktok, image: 'var(--tiktok-colored-icon)' }, + ]; - function socialIconList() { - return socialDataset.map( (socialInfo) => { - return ( -
setIsSocialFormOpen(!isSocialFormOpen)} - className={`browser-content_social_icon ${socialInfo.url ? isValidUrl(socialInfo.url) || '--invalid-url' : '--no-url' }`} - style={{ backgroundImage: socialInfo.image }} /> - ) - }) - } - - return ( -
-

Preview

-
-
-
-
- - - -
-
-
-
-
-
-
- {(icon == 0 || icon == undefined) && (
)} - {(icon != 0 && icon != undefined) && (Thumb)} -
{__( - titlePreview?.substring(0, 20), - 'wp-module-onboarding' - )}
-
x
-
-
-
-
-
-
-
-
-
-
-
-
-
- {}} value={__( - urlPreview, - 'wp-module-onboarding' - )}> -
-
-
-
-
-
-
-

{__( - titlePreview, - 'wp-module-onboarding' - )}

- {__( - urlPreview, - 'wp-module-onboarding' - )} -
-
- {__( - descPreview, - 'wp-module-onboarding' - )} -
-
- {socialIconList()} -
-
-
-
- ); + function titleToUrl( title ) { + return `https://${ title + ?.toLowerCase() + .replace( /\s/g, '' ) + .replace( /\W/g, '' ) }.com`; + } + + function socialIconList() { + return socialDataset.map( ( socialInfo ) => { + return ( +
+ setIsSocialFormOpen( ! isSocialFormOpen ) + } + className={ `browser-content_social_icon ${ + socialInfo.url + ? isValidUrl( socialInfo.url ) || '--invalid-url' + : '--no-url' + }` } + style={ { backgroundImage: socialInfo.image } } + /> + ); + } ); + } + + return ( +
+

Preview

+
+
+
+
+ + + +
+
+
+
+
+
+
+ { ( icon == 0 || icon == undefined ) && ( +
+ ) } + { icon != 0 && icon != undefined && ( + Thumb + ) } +
+ { __( + titlePreview?.substring( 0, 20 ), + 'wp-module-onboarding' + ) } +
+
+ x +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {} } + value={ __( urlPreview, 'wp-module-onboarding' ) } + > +
+
+
+
+
+
+
+

+ { __( titlePreview, 'wp-module-onboarding' ) } +

+ + { __( urlPreview, 'wp-module-onboarding' ) } + +
+
+ { __( descPreview, 'wp-module-onboarding' ) } +
+
+ { socialIconList() } +
+
+
+
+ ); }; -export default MiniPreview; +export default memo( MiniPreview ); diff --git a/src/OnboardingSPA/components/Sidebar/components/LearnMore/Sidebar.js b/src/OnboardingSPA/components/Sidebar/components/LearnMore/Sidebar.js index a3ff944a6..0d3055c4f 100644 --- a/src/OnboardingSPA/components/Sidebar/components/LearnMore/Sidebar.js +++ b/src/OnboardingSPA/components/Sidebar/components/LearnMore/Sidebar.js @@ -1,5 +1,5 @@ import { Fill, PanelBody, PanelHeader, Button } from '@wordpress/components'; -import { Fragment, Suspense } from '@wordpress/element'; +import { Fragment, memo, Suspense } from '@wordpress/element'; import { closeSmall } from '@wordpress/icons'; import { useDispatch, useSelect } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; @@ -57,4 +57,4 @@ const LearnMoreSidebar = () => { ); }; -export default LearnMoreSidebar; +export default memo( LearnMoreSidebar ); diff --git a/src/OnboardingSPA/pages/Steps/GetStarted/GetStartedExperience/index.js b/src/OnboardingSPA/pages/Steps/GetStarted/GetStartedExperience/index.js index 119735a11..f8ec79613 100644 --- a/src/OnboardingSPA/pages/Steps/GetStarted/GetStartedExperience/index.js +++ b/src/OnboardingSPA/pages/Steps/GetStarted/GetStartedExperience/index.js @@ -58,14 +58,12 @@ const GetStartedExperience = () => { } }, [ isLoaded ] ); - useEffect( () => { - const saveData = async () => { - const currentDataCopy = currentData; - currentDataCopy.data.wpComfortLevel = wpComfortLevel || '0'; - setCurrentOnboardingData( currentDataCopy ); - }; - if ( isLoaded ) saveData(); - }, [ wpComfortLevel ] ); + const saveData = ( value ) => { + setWpComfortLevel( value ); + const currentDataCopy = currentData; + currentDataCopy.data.wpComfortLevel = value || '0'; + setCurrentOnboardingData( currentDataCopy ); + }; return ( @@ -102,7 +100,7 @@ const GetStartedExperience = () => { ), }; } ) } - onChange={ ( value ) => setWpComfortLevel( value ) } + onChange={ ( value ) => saveData( value ) } />