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

Minor dark mode fixes and slot filled footers #376

Merged
merged 1 commit into from
Nov 30, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Fill } from '@wordpress/components';
import { FOOTER_SITEGEN, FOOTER_START } from '../../../../../constants';
import ToggleDarkMode from '../../../ToggleDarkMode';

const SiteGenFooter = () => {
return (
<>
<Fill name={ `${ FOOTER_SITEGEN }/${ FOOTER_START }` }>
<ToggleDarkMode />
</Fill>
</>
);
};

export default SiteGenFooter;
37 changes: 37 additions & 0 deletions src/OnboardingSPA/components/Footer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { FOOTER_END, FOOTER_START } from '../../../constants';
import { Slot } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { Fragment, Suspense } from '@wordpress/element';

import { store as nfdOnboardingStore } from '../../store';

const Footer = () => {
const { footers, footerActiveView } = useSelect( ( select ) => {
return {
footers: select( nfdOnboardingStore ).getFooters(),
footerActiveView:
select( nfdOnboardingStore ).getFooterActiveView(),
};
} );
return (
<div className={ 'nfd-onboarding-footer' }>
<Suspense fallback={ <Fragment /> }>
{ footers.map( ( footer ) => {
return (
<Fragment key={ footer.id }>
<footer.footer />
</Fragment>
);
} ) }
</Suspense>
<div className="nfd-onboarding-footer__start">
<Slot name={ `${ footerActiveView }/${ FOOTER_START }` } />
</div>
<div className="nfd-onboarding-footer__end">
<Slot name={ `${ footerActiveView }/${ FOOTER_END }` } />
</div>
</div>
);
};

export default Footer;
22 changes: 22 additions & 0 deletions src/OnboardingSPA/components/Footer/stylesheet.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.nfd-onboarding-footer {
position: absolute;
bottom: 0;
left: 0;
z-index: 1;

display: flex;
flex-direction: row;

height: auto;
width: 100%;
border: none;

&__end {
position: absolute;
right: 25px;
}

&--background {
background-color: rgba(var(--nfd-onboarding-secondary-rgb), 0.75);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import Content from '../../Content';
import Drawer from '../../Drawer';
import Sidebar from '../../Sidebar';
import ToggleDarkMode from '../../ToggleDarkMode';
import classNames from 'classnames';
import { useLocation } from 'react-router-dom';
import { setFlow } from '../../../utils/api/flow';
Expand Down Expand Up @@ -55,6 +54,7 @@
import { stepTheFork } from '../../../steps/TheFork/step';
import { ThemeProvider } from '../../ThemeContextProvider';
import themeToggleHOC from '../themeToggleHOC';
import Footer from '../../Footer';

const SiteBuild = () => {
const location = useLocation();
Expand Down Expand Up @@ -101,7 +101,7 @@
select( nfdOnboardingStore ).getPluginInstallHash(),
};
},
[ location.pathname ]

Check warning on line 104 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useSelect has an unnecessary dependency: 'location.pathname'. Either exclude it or remove the dependency array

Check warning on line 104 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useSelect has an unnecessary dependency: 'location.pathname'. Either exclude it or remove the dependency array
);

const [ isRequestPlaced, setIsRequestPlaced ] = useState( false );
Expand Down Expand Up @@ -364,7 +364,7 @@

useEffect( () => {
trackChapters();
}, [ currentStep ] );

Check warning on line 367 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'trackChapters'. Either include it or remove the dependency array

Check warning on line 367 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'trackChapters'. Either include it or remove the dependency array

const prioritizeFlow = () => {
const currentFlow = window.nfdOnboarding.currentFlow;
Expand Down Expand Up @@ -405,13 +405,13 @@
initializeSettings();
setInterval( cronTrigger, 45000 );
}
}, [ initialize ] );

Check warning on line 408 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'pluginInstallHash'. Either include it or remove the dependency array

Check warning on line 408 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'pluginInstallHash'. Either include it or remove the dependency array

useEffect( () => {
if ( false !== brandConfig?.prioritization ) {
return prioritizeFlow();
}
}, [ experienceLevel, topPriority ] );

Check warning on line 414 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'brandConfig?.prioritization' and 'prioritizeFlow'. Either include them or remove the dependency array

Check warning on line 414 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'brandConfig?.prioritization' and 'prioritizeFlow'. Either include them or remove the dependency array

useEffect( () => {
document.body.classList.add( `nfd-brand-${ newfoldBrand }` );
Expand All @@ -421,17 +421,17 @@
syncStoreToDB();
handlePreviousStepTracking();
handleConditionalDesignStepsRoutes();
}, [ location.pathname, onboardingFlow ] );

Check warning on line 424 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'handleConditionalDesignStepsRoutes', 'handlePreviousStepTracking', and 'syncStoreToDB'. Either include them or remove the dependency array

Check warning on line 424 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'handleConditionalDesignStepsRoutes', 'handlePreviousStepTracking', and 'syncStoreToDB'. Either include them or remove the dependency array

const shouldApplyTheme =
const isForkStep =
currentStep === stepTheFork ||
window.nfdOnboarding.currentFlow === 'sitegen';
// wrapping the NewfoldInterfaceSkeleton with the HOC to make 'theme' available
const ThemedNewfoldInterfaceSkeleton = themeToggleHOC(
NewfoldInterfaceSkeleton,
'nfd-onboarding-sitegen-dark',
'nfd-onboarding-sitegen-light',
shouldApplyTheme
isForkStep
);

return (
Expand All @@ -445,14 +445,14 @@
{ 'is-large-viewport': isLargeViewport },
{ 'is-small-viewport': ! isLargeViewport },
{
'nfd-onboarding-skeleton--sitegen': shouldApplyTheme,
'nfd-onboarding-skeleton--sitegen': isForkStep,
}
) }
header={ <Header /> }
drawer={ <Drawer /> }
content={ <Content /> }
sidebar={ <Sidebar /> }
footer={ shouldApplyTheme ? <ToggleDarkMode /> : null }
footer={ isForkStep ? <Footer /> : null }
/>
</ThemeProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import Sidebar from '../../Sidebar';
import themeToggleHOC from '../themeToggleHOC';
import NewfoldInterfaceSkeleton from '../index';
import ToggleDarkMode from '../../ToggleDarkMode';
import { ThemeProvider } from '../../ThemeContextProvider';
import { store as nfdOnboardingStore } from '../../../store';
import { setFlow } from '../../../utils/api/flow';
import {
generateSiteGenMeta,
getSiteGenIdentifiers,
} from '../../../utils/api/siteGen';
import Footer from '../../Footer';

// Wrapping the NewfoldInterfaceSkeleton with the HOC to make theme available
const ThemedNewfoldInterfaceSkeleton = themeToggleHOC(
Expand Down Expand Up @@ -111,16 +111,17 @@
syncStoreToDB();
generateSiteGenData();
handlePreviousStepTracking();
}, [ location.pathname ] );

Check warning on line 114 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'generateSiteGenData', 'handlePreviousStepTracking', and 'syncStoreToDB'. Either include them or remove the dependency array

Check warning on line 114 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'generateSiteGenData', 'handlePreviousStepTracking', and 'syncStoreToDB'. Either include them or remove the dependency array

return (
<ThemeProvider>
<ThemedNewfoldInterfaceSkeleton
id={ 'nfd-onboarding-skeleton--sitegen' }
className={ 'nfd-onboarding-skeleton--sitegen' }
header={ <Header /> }
content={ <Content /> }
sidebar={ <Sidebar /> }
footer={ <ToggleDarkMode /> }
footer={ <Footer /> }
/>
</ThemeProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ const themeToggleHOC = (
WrappedComponent,
darkClass,
lightClass,
shouldApplyTheme = true
isForkStep = true
) => {
return ( props ) => {
const { theme } = useContext( ThemeContext );
const isDarkMode = theme === THEME_DARK;
const shouldApply =
shouldApplyTheme !== undefined ? shouldApplyTheme : true;
const shouldApply = isForkStep !== undefined ? isForkStep : true;
const className = classNames( props.className, {
[ darkClass ]: isDarkMode && shouldApply,
[ lightClass ]: ! isDarkMode && shouldApply,
Expand Down
50 changes: 29 additions & 21 deletions src/OnboardingSPA/components/ToggleDarkMode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useContext } from '@wordpress/element';
import { ThemeContext } from '../ThemeContextProvider';
import classNames from 'classnames';
import { THEME_DARK } from '../../../constants';
import Animate from '../Animate';

const ToggleDarkMode = () => {
const { theme, toggleTheme } = useContext( ThemeContext );
Expand All @@ -11,27 +12,34 @@ const ToggleDarkMode = () => {
};

return (
<div className="nfd-onboarding-toggle__theme">
<div
className={ classNames(
'nfd-onboarding-toggle__theme__button',
{
'nfd-onboarding-toggle__theme__button__light':
! isDarkMode,
'nfd-onboarding-toggle__theme__button__dark':
isDarkMode,
}
) }
onClick={ () => onChange() }
role="button"
onKeyDown={ ( event ) => {
if ( event.key === 'Enter' ) {
onChange();
}
} }
tabIndex="0"
></div>
</div>
<Animate
type={ 'fade-in' }
duration="200ms"
key={ isDarkMode }
timingFunction="ease-in-out"
>
<div className="nfd-onboarding-toggle__theme">
<div
className={ classNames(
'nfd-onboarding-toggle__theme__button',
{
'nfd-onboarding-toggle__theme__button__light':
! isDarkMode,
'nfd-onboarding-toggle__theme__button__dark':
isDarkMode,
}
) }
onClick={ () => onChange() }
role="button"
onKeyDown={ ( event ) => {
if ( event.key === 'Enter' ) {
onChange();
}
} }
tabIndex="0"
></div>
</div>
</Animate>
);
};

Expand Down
8 changes: 3 additions & 5 deletions src/OnboardingSPA/components/ToggleDarkMode/stylesheet.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
.nfd-onboarding-toggle__theme {
position: absolute;
bottom: 25px;
left: 25px;
z-index: 1;
margin-left: 25px;
margin-top: 10px;
margin-bottom: 10px;

&__button {
width: 60px;
height: 60px;
cursor: pointer;

&__light {
animation: fadeIn 600ms ease-in-out;
background: var(--sitegen-toggle-theme-icon-light);
}

Expand Down
15 changes: 15 additions & 0 deletions src/OnboardingSPA/data/footers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { lazy } from '@wordpress/element';

import { FOOTER_SITEGEN } from '../../../constants';

const SiteGenFooter = lazy( () =>
import( '../../components/Footer/components/SiteGenFooter' )
);

export const footers = [
{
id: FOOTER_SITEGEN,
footer: SiteGenFooter,
enabled: true,
},
];
2 changes: 0 additions & 2 deletions src/OnboardingSPA/steps/SiteGen/Experience/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
setCurrentOnboardingData,
} = useDispatch( nfdOnboardingStore );

useEffect( () => {

Check warning on line 35 in src/OnboardingSPA/steps/SiteGen/Experience/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect contains a call to 'setSelection'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [setIsHeaderEnabled, setSidebarActiveView, setHeaderActiveView, setDrawerActiveView, currentData.sitegen.experience.level] as a second argument to the useEffect Hook
setIsHeaderEnabled( true );
setSidebarActiveView( false );
setHeaderActiveView( HEADER_SITEGEN );
Expand All @@ -50,8 +50,6 @@
setSelection( idx );
currentData.sitegen.experience.level = idx;
setCurrentOnboardingData( currentData );
// console.log( selection );
// console.log( 'Navigate to the next screen!' );
if ( nextStep ) {
navigate( nextStep.path );
}
Expand Down
1 change: 0 additions & 1 deletion src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@
if ( currentData.sitegen.siteDetails?.prompt !== '' ) {
setCustomerInput( currentData.sitegen.siteDetails.prompt );
}
}, [] );

Check warning on line 41 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', 'setHeaderActiveView', 'setIsHeaderEnabled', and 'setSidebarActiveView'. Either include them or remove the dependency array

const checkAndNavigate = () => {
currentData.sitegen.siteDetails.prompt = customerInput;
setCurrentOnboardingData( currentData );
// console.log( 'Navigate to the next screen!' );
};

return (
Expand Down
4 changes: 3 additions & 1 deletion src/OnboardingSPA/steps/TheFork/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useEffect } from '@wordpress/element';

import { useSelect, useDispatch } from '@wordpress/data';
import { store as nfdOnboardingStore } from '../../store';
import { HEADER_SITEGEN } from '../../../constants';
import { FOOTER_SITEGEN, HEADER_SITEGEN } from '../../../constants';

import { useNavigate } from 'react-router-dom';

Expand Down Expand Up @@ -34,6 +34,7 @@ const TheFork = () => {
updateRoutes,
updateDesignRoutes,
updateInitialize,
setFooterActiveView,
} = useDispatch( nfdOnboardingStore );

const switchFlow = ( newFlow ) => {
Expand Down Expand Up @@ -61,6 +62,7 @@ const TheFork = () => {
setIsHeaderNavigationEnabled( false );
setHeaderActiveView( HEADER_SITEGEN );
setDrawerActiveView( false );
setFooterActiveView( FOOTER_SITEGEN );
} );

const oldFlow = window.nfdOnboarding?.oldFlow
Expand Down
7 changes: 7 additions & 0 deletions src/OnboardingSPA/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ export function setHeaderActiveView( view ) {
};
}

export function setFooterActiveView( view ) {
return {
type: 'SET_FOOTER_ACTIVE_VIEW',
view,
};
}

export function updatePreviewSettings( previewSettings ) {
return {
type: 'SET_PREVIEW_SETTINGS',
Expand Down
21 changes: 21 additions & 0 deletions src/OnboardingSPA/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
VIEW_NAV_PRIMARY,
THEME_STATUS_INIT,
HEADER_SITEBUILD,
FOOTER_SITEGEN,
} from '../../constants';

import {
Expand All @@ -14,6 +15,7 @@ import {
} from '../data/flows/index';
import { sidebars } from '../data/sidebars/index';
import { headers } from '../data/headers';
import { footers } from '../data/footers';
import apiQueueExecutor from '../utils/api-queuer/api-queue-executor';
import { DEFAULT_FLOW } from '../data/flows/constants';

Expand Down Expand Up @@ -297,6 +299,24 @@ export function queue( state = [], action ) {
return state;
}

export function footer(
state = {
footers,
view: FOOTER_SITEGEN,
},
action
) {
switch ( action.type ) {
case 'SET_FOOTER_ACTIVE_VIEW':
return {
...state,
view: action.view,
};
}

return state;
}

export default combineReducers( {
drawer,
runtime,
Expand All @@ -305,5 +325,6 @@ export default combineReducers( {
flow,
sidebar,
header,
footer,
queue,
} );
8 changes: 8 additions & 0 deletions src/OnboardingSPA/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ export function getHeaders( state ) {
return state.header.headers;
}

export function getFooters( state ) {
return state.footer.footers;
}

export function getHeaderActiveView( state ) {
return state.header.view;
}

export function getFooterActiveView( state ) {
return state.footer.view;
}

/**
* Gets current Newfold brand
*
Expand Down
Loading
Loading