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

Dynamically change color scheme from color_scheme query param #96557

Merged
Merged
1 change: 1 addition & 0 deletions client/jetpack-connect/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ export const authorizeQueryDataSchema = {
allow_site_connection: { type: 'string' }, // '1' if true
installed_ext_success: { type: 'string' }, // '1' if true
plugin_name: { type: 'string' },
color_scheme: { type: 'string' },
},
};
16 changes: 16 additions & 0 deletions client/layout/color-scheme/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ export function getColorScheme( { state, isGlobalSidebarVisible, sectionName } )
return siteColorScheme ?? calypsoColorScheme;
}

export function getColorSchemeFromCurrentQuery( currentQuery, defaultColorScheme = 'default' ) {
if ( currentQuery?.color_scheme ) {
return currentQuery.color_scheme;
}

if ( currentQuery?.redirect_to ) {
try {
return new URLSearchParams( currentQuery.redirect_to ).get( 'color_scheme' );
} catch ( error ) {
return defaultColorScheme;
}
}

return defaultColorScheme;
}

export function refreshColorScheme( prevColorScheme, nextColorScheme ) {
if ( typeof document === 'undefined' ) {
return;
Expand Down
14 changes: 8 additions & 6 deletions client/layout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import {
masterbarIsVisible,
} from 'calypso/state/ui/selectors';
import BodySectionCssClass from './body-section-css-class';
import { getColorScheme, refreshColorScheme } from './color-scheme';
import { getColorScheme, getColorSchemeFromCurrentQuery, refreshColorScheme } from './color-scheme';
import GlobalNotifications from './global-notifications';
import LayoutLoader from './loader';
import { shouldLoadInlineHelp, handleScroll } from './utils';
Expand Down Expand Up @@ -504,11 +504,13 @@ export default withCurrentRoute(
const userAllowedToHelpCenter =
config.isEnabled( 'calypso/help-center' ) && ! getIsOnboardingAffiliateFlow( state );

const colorScheme = getColorScheme( {
state,
sectionName,
isGlobalSidebarVisible,
} );
const colorScheme = isWooPasswordlessJPC
? getColorSchemeFromCurrentQuery( currentQuery )
: getColorScheme( {
state,
isGlobalSidebarVisible,
sectionName,
} );

return {
masterbarIsHidden,
Expand Down
12 changes: 12 additions & 0 deletions client/layout/logged-out.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { UniversalNavbarHeader, UniversalNavbarFooter } from '@automattic/wpcom-
import clsx from 'clsx';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { useEffect } from 'react';
import { connect, useSelector } from 'react-redux';
import { CookieBannerContainerSSR } from 'calypso/blocks/cookie-banner';
import ReaderJoinConversationDialog from 'calypso/blocks/reader-join-conversation/dialog';
Expand Down Expand Up @@ -48,6 +49,7 @@ import getWccomFrom from 'calypso/state/selectors/get-wccom-from';
import isWooPasswordlessJPCFlow from 'calypso/state/selectors/is-woo-passwordless-jpc-flow';
import { masterbarIsVisible } from 'calypso/state/ui/selectors';
import BodySectionCssClass from './body-section-css-class';
import { refreshColorScheme, getColorSchemeFromCurrentQuery } from './color-scheme';

import './style.scss';

Expand Down Expand Up @@ -81,6 +83,7 @@ const LayoutLoggedOut = ( {
twoFactorEnabled,
/* eslint-disable no-shadow */
clearLastActionRequiresLogin,
colorScheme,
} ) => {
const localizeUrl = useLocalizeUrl();
const isLoggedIn = useSelector( isUserLoggedIn );
Expand Down Expand Up @@ -153,6 +156,10 @@ const LayoutLoggedOut = ( {

let masterbar = null;

useEffect( () => {
isWooPasswordlessJPC && refreshColorScheme( 'default', colorScheme );
}, [] ); // Empty dependency array ensures it runs only once on mount

// Open new window to create account page when a logged in action was triggered on the Reader tag embed page and the user is not logged in
if ( ! isLoggedIn && loggedInAction && isReaderTagEmbed ) {
const { pathname } = getUrlParts( window.location.href );
Expand Down Expand Up @@ -366,6 +373,10 @@ export default withCurrentRoute(
noMasterbarForRoute;
const twoFactorEnabled = isTwoFactorEnabled( state );

const colorScheme = isWooPasswordlessJPC
? getColorSchemeFromCurrentQuery( currentQuery )
: null;

return {
isJetpackLogin,
isWhiteLogin,
Expand All @@ -389,6 +400,7 @@ export default withCurrentRoute(
isWooPasswordless: getIsWooPasswordless( state ),
isBlazePro: getIsBlazePro( state ),
twoFactorEnabled,
colorScheme,
};
},
{ clearLastActionRequiresLogin }
Expand Down
10 changes: 5 additions & 5 deletions client/layout/masterbar/woo.scss
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ $breakpoint-mobile: 660px;

.progress-bar__progress {
border-radius: 0;
background-color: var(--wp-admin-theme-color);
background-color: var(--color-primary);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix!

}
}

Expand Down Expand Up @@ -964,7 +964,7 @@ $breakpoint-mobile: 660px;
height: 48px;
padding: 10px 16px;
font-weight: 500;
background-color: var(--wp-admin-theme-color);
background-color: var(--color-primary);
}

.two-factor-authentication__actions.card button.button {
Expand Down Expand Up @@ -1927,11 +1927,11 @@ $breakpoint-mobile: 660px;
}

button.button.is-primary {
background-color: var(--wp-admin-theme-color);
background-color: var(--color-primary);
font-family: inherit;
border-radius: 2px;
&:hover:not(:disabled) {
background-color: var(--wp-admin-theme-color);
background-color: var(--color-primary);
}
}

Expand Down Expand Up @@ -2119,4 +2119,4 @@ $breakpoint-mobile: 660px;
}
}
}
}
}
Loading