Skip to content

Commit

Permalink
Linting JS
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Feb 21, 2023
1 parent e941db3 commit 52beacf
Show file tree
Hide file tree
Showing 13 changed files with 530 additions and 415 deletions.
25 changes: 14 additions & 11 deletions src/OnboardingSPA/components/Content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ const Content = () => {
};
} );

const getMappedPages = useCallback(( routes ) => {
return routes?.map( ( route ) => (
<Route
key={ route.path }
path={ route.path }
end
element={ <route.Component /> }
/>
) );
}, [ routes ]);
const getMappedPages = useCallback(
( routes ) => {
return routes?.map( ( route ) => (
<Route
key={ route.path }
path={ route.path }
end
element={ <route.Component /> }
/>
) );
},
[ routes ]
);

return (
<main className="nfd-onboard-content">
Expand All @@ -37,5 +40,5 @@ const Content = () => {
);
};

const ContentMemo = memo(Content);
const ContentMemo = memo( Content );
export default ContentMemo;
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,21 @@ const DesignTypography = () => {
// Changes the Global Styles to Recompute css properties
const globalStylesCopy = selectedGlobalStyle;

if( globalStylesCopy?.styles?.typography?.fontFamily
&& globalStylesCopy?.styles?.blocks[ 'core/heading' ]?.typography?.fontFamily ) {
if (
globalStylesCopy?.styles?.typography?.fontFamily &&
globalStylesCopy?.styles?.blocks[ 'core/heading' ]?.typography
?.fontFamily
) {
globalStylesCopy.styles.typography.fontFamily =
fontPalettesCopy[ fontStyle ]?.styles?.typography?.fontFamily;
globalStylesCopy.styles.blocks[ 'core/heading' ].typography.fontFamily =
fontPalettesCopy[ fontStyle ]?.styles?.typography?.fontFamily;
globalStylesCopy.styles.blocks[
'core/heading'
].typography.fontFamily =
fontPalettesCopy[ fontStyle ]?.styles.blocks[
'core/heading'
].typography.fontFamily;
}

if (
globalStylesCopy.styles?.blocks[ 'core/site-title' ]?.typography
?.fontFamily
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ const BlockPreview = ( {

const { currentData, storedPreviewSettings } = useSelect( ( select ) => {
return {
currentData: select( nfdOnboardingStore ).getCurrentOnboardingData(),
storedPreviewSettings: select( nfdOnboardingStore ).getPreviewSettings(),
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
storedPreviewSettings:
select( nfdOnboardingStore ).getPreviewSettings(),
};
}, [] );

Expand Down Expand Up @@ -112,5 +114,5 @@ const BlockPreview = ( {
);
};

const BlockPreviewMemo = memo(BlockPreview);
const BlockPreviewMemo = memo( BlockPreview );
export default BlockPreviewMemo;
137 changes: 69 additions & 68 deletions src/OnboardingSPA/components/SkipButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,87 +12,88 @@ import { wpAdminPage, bluehostDashboardPage } from '../../../constants';
/**
* Interface Text Inputs with standard design.
*
* @returns
* @return
*/
const SkipButton = () => {
const navigate = useNavigate();
const location = useLocation();
const { nextStep, currentData } = useSelect( ( select ) => {
return {
nextStep: select( nfdOnboardingStore ).getNextStep(),
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
};
}, [] );

const navigate = useNavigate();
const location = useLocation();
const { nextStep, currentData } = useSelect(
(select) => {
return {
nextStep: select(nfdOnboardingStore).getNextStep(),
currentData: select(nfdOnboardingStore).getCurrentOnboardingData(),
};
},
[]
);
const isLastStep = null === nextStep || false === nextStep;

const isLastStep = null === nextStep || false === nextStep;
async function syncSocialSettingsFinish( currentData ) {
const initialData = await getSettings();
const result = await setSettings( currentData?.data?.socialData );
if ( result?.error != null ) {
console.error( 'Unable to Save Social Data!' );
return initialData?.body;
}
return result?.body;
}

async function syncSocialSettingsFinish(currentData) {
const initialData = await getSettings();
const result = await setSettings(currentData?.data?.socialData);
if (result?.error != null) {
console.error('Unable to Save Social Data!');
return initialData?.body;
}
return result?.body;
}
async function saveData( path, currentData ) {
if ( currentData ) {
currentData.isComplete = new Date().getTime();

async function saveData(path, currentData) {
// If Social Data is changed then sync it
if ( path?.includes( 'basic-info' ) ) {
const socialData = await syncSocialSettingsFinish(
currentData
);

if (currentData) {
currentData.isComplete = new Date().getTime();
// If Social Data is changed then Sync that also to the store
if ( socialData && currentData?.data )
currentData.data.socialData = socialData;
}
setFlow( currentData );
}
// Redirect to Admin Page for normal customers
// and Bluehost Dashboard for ecommerce customers
const exitLink = exitToWordpressForEcommerce()
? bluehostDashboardPage
: wpAdminPage;
window.location.replace( exitLink );
}

// If Social Data is changed then sync it
if (path?.includes('basic-info')) {
const socialData = await syncSocialSettingsFinish(currentData);
function skipStep() {
if ( isLastStep ) {
return (
<Button
className="skip-button"
onClick={ () => saveData( location.pathname, currentData ) }
>
{ __( 'Skip this Step', 'wp-module-onboarding' ) }
</Button>
);
}
return (
<Button
className="skip-button"
onClick={ () => navigate( nextStep.path ) }
>
{ __( 'Skip this Step', 'wp-module-onboarding' ) }
</Button>
);
}

// If Social Data is changed then Sync that also to the store
if (socialData && currentData?.data)
currentData.data.socialData = socialData;
}
setFlow(currentData);
}
// Redirect to Admin Page for normal customers
// and Bluehost Dashboard for ecommerce customers
const exitLink = exitToWordpressForEcommerce() ? bluehostDashboardPage : wpAdminPage;
window.location.replace(exitLink);
}

function skipStep() {
if (isLastStep)
{
return (
<Button className="skip-button"
onClick={() => saveData(location.pathname, currentData)} >
{__('Skip this Step', 'wp-module-onboarding')}
</Button>
);
}
else {
return (
<Button className="skip-button"
onClick={() => navigate(nextStep.path)} >
{__('Skip this Step', 'wp-module-onboarding')}
</Button>
);
}
}

return skipStep();
return skipStep();
};

/*
* check if this is the last step
* check if this is the last step
*/
const exitToWordpressForEcommerce = () => {
if (window.nfdOnboarding.currentFlow == 'ecommerce') {
return true;
}
return false;
}
if ( window.nfdOnboarding.currentFlow == 'ecommerce' ) {
return true;
}
return false;
};

const SkipButtonMemo = memo(SkipButton)
const SkipButtonMemo = memo( SkipButton );
export default SkipButtonMemo;
107 changes: 61 additions & 46 deletions src/OnboardingSPA/components/TextInput/index.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,74 @@
import { __ } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import { useRef, useEffect, useState, memo } from '@wordpress/element';

/**
* Interface Text Inputs with standard design.
*
* @returns
* @param root0
* @param root0.title
* @param root0.hint
* @param root0.placeholder
* @param root0.height
* @param root0.maxCharacters
* @param root0.textValue
* @param root0.textValueSetter
* @return
*/
const TextInput = ({ title, hint, placeholder, height, maxCharacters, textValue, textValueSetter }) => {
const TextInput = ( {
title,
hint,
placeholder,
height,
maxCharacters,
textValue,
textValueSetter,
} ) => {
const textareaRef = useRef( null );
const [ inputText, setInputText ] = useState( 'nfd-input__field' );

const textareaRef = useRef(null);
const [inputText, setInputText] = useState("nfd-input__field");
useEffect( () => {
textareaRef.current.style.height = height;
const scrollHeight = textareaRef.current.scrollHeight;
textareaRef.current.style.height = scrollHeight + 'px';
}, [ textValue ] );

useEffect(() => {
textareaRef.current.style.height = height;
const scrollHeight = textareaRef.current.scrollHeight;
textareaRef.current.style.height = scrollHeight + "px";
}, [textValue]);
const onTextChange = ( e ) => {
e.preventDefault();
textValueSetter( e.target.value );

const onTextChange = (e) => {
e.preventDefault();
textValueSetter(e.target.value);

e.target.value.length == maxCharacters ?
setInputText("nfd-input__field nfd-input__field_error") :
setInputText("nfd-input__field")
}
e.target.value.length == maxCharacters
? setInputText( 'nfd-input__field nfd-input__field_error' )
: setInputText( 'nfd-input__field' );
};

return (
<div className='nfd-input'>
<label>
<div className='nfd-input__label'>
<p className='nfd-input__label_title'>{__(
title,
'wp-module-onboarding'
)}</p>
<p className='nfd-input__label_maxChar'>{`(${maxCharacters - textValue?.length} characters left)`}</p>
</div>
<textarea
type="text"
className={inputText}
ref={textareaRef}
style={{height: height}}
placeholder={placeholder}
value={textValue}
maxLength={maxCharacters}
onChange={(e) => onTextChange(e)}
/>
<p className='nfd-input__hint'>{__(
hint,
'wp-module-onboarding'
)}</p>
</label>
</div>
);
return (
<div className="nfd-input">
<label>
<div className="nfd-input__label">
<p className="nfd-input__label_title">
{ __( title, 'wp-module-onboarding' ) }
</p>
<p className="nfd-input__label_maxChar">{ `(${
maxCharacters - textValue?.length
} characters left)` }</p>
</div>
<textarea
type="text"
className={ inputText }
ref={ textareaRef }
style={ { height } }
placeholder={ placeholder }
value={ textValue }
maxLength={ maxCharacters }
onChange={ ( e ) => onTextChange( e ) }
/>
<p className="nfd-input__hint">
{ __( hint, 'wp-module-onboarding' ) }
</p>
</label>
</div>
);
};

const TextInputMemo = memo(TextInput)
const TextInputMemo = memo( TextInput );
export default TextInputMemo;
6 changes: 3 additions & 3 deletions src/OnboardingSPA/pages/Steps/DesignColors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const StepDesignColors = () => {

const { currentData, currentStep, themeStatus } = useSelect( ( select ) => {
return {
currentData: select( nfdOnboardingStore ).getCurrentOnboardingData(),
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
currentStep: select( nfdOnboardingStore ).getStepFromPath(
location.pathname
),
Expand All @@ -48,8 +49,7 @@ const StepDesignColors = () => {
};

useEffect( () => {
if ( THEME_STATUS_ACTIVE === themeStatus )
getStylesAndPatterns();
if ( THEME_STATUS_ACTIVE === themeStatus ) getStylesAndPatterns();
}, [ themeStatus ] );

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ const StepDesignThemeStylesMenu = () => {
};

useEffect( () => {
if ( themeStatus === THEME_STATUS_ACTIVE )
getStylesAndPatterns();
if ( themeStatus === THEME_STATUS_ACTIVE ) getStylesAndPatterns();
}, [ themeStatus ] );

const handleClick = ( idx ) => {
Expand Down
Loading

0 comments on commit 52beacf

Please sign in to comment.