Skip to content

Commit

Permalink
Merge pull request #376 from newfold-labs/enhance/dark-mode-logic
Browse files Browse the repository at this point in the history
Minor dark mode fixes and slot filled footers
  • Loading branch information
arunshenoy99 authored Nov 30, 2023
2 parents 2efbdac + e5f18ad commit 241e85a
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 40 deletions.
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 Header from '../../Header';
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 { trigger as cronTrigger } from '../../../utils/api/cronTrigger';
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 @@ -423,15 +423,15 @@ const SiteBuild = () => {
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

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 @@ const SiteBuild = () => {
{ '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 Content from '../../Content';
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 @@ -116,11 +116,12 @@ const SiteGen = () => {
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 @@ -50,8 +50,6 @@ const SiteGenExperience = () => {
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 @@ -43,7 +43,6 @@ const SiteGenSiteDetails = () => {
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

0 comments on commit 241e85a

Please sign in to comment.