Skip to content

Commit

Permalink
Merge branch 'develop' into add/paired-browsing-template-include-filt…
Browse files Browse the repository at this point in the history
…er-priority
  • Loading branch information
pierlon committed Aug 8, 2020
2 parents c4d565c + 177a673 commit 2cf9081
Show file tree
Hide file tree
Showing 39 changed files with 647 additions and 193 deletions.
5 changes: 4 additions & 1 deletion assets/src/components/phone/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
display: flex;
flex-direction: column;
margin-bottom: 1rem;
max-height: 413px;
height: 413px;
min-height: 200px;
padding: 12px;
position: relative;
Expand All @@ -25,5 +25,8 @@
}

.phone-inner {
display: flex;
background-color: var(--color-gray-medium);
flex-grow: 1;
overflow: hidden;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* WordPress dependencies
*/
import { createContext } from '@wordpress/element';

export const ReaderThemes = createContext();

/**
* MOCK.
*
* @param {Object} props
* @param {any} props.children Component children.
* @param {boolean} props.downloadingTheme Whether downloading a theme or not.
*/
export function ReaderThemesContextProvider( { children, downloadingTheme = false } ) {
return (
<ReaderThemes.Provider value={
{
downloadingTheme,
}
}>
{ children }
</ReaderThemes.Provider>
);
}
ReaderThemesContextProvider.propTypes = {
children: PropTypes.any,
downloadingTheme: PropTypes.bool,
};
13 changes: 9 additions & 4 deletions assets/src/components/reader-themes-context-provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { __ } from '@wordpress/i18n';
* External dependencies
*/
import PropTypes from 'prop-types';
import { USING_FALLBACK_READER_THEME, LEGACY_THEME_SLUG } from 'amp-settings';

/**
* Internal dependencies
Expand Down Expand Up @@ -80,16 +81,20 @@ export function ReaderThemesContextProvider( { wpAjaxUrl, children, currentTheme
const [ downloadingThemeError, setDownloadingThemeError ] = useState( null );

/**
* If the currently selected theme is unavailable and not installable, or the current theme is the active theme,
* unset the reader theme option.
* If the currently selected theme is not installable, is the active theme, or unavailable for selection, set the
* Reader theme to AMP Legacy.
*/
useEffect( () => {
if ( themeWasOverridden ) { // Only do this once.
return;
}

if ( selectedTheme.availability === 'non-installable' || originalSelectedTheme.availability === 'active' ) {
updateOptions( { reader_theme: 'legacy' } );
if (
selectedTheme.availability === 'non-installable' ||
originalSelectedTheme.availability === 'active' ||
USING_FALLBACK_READER_THEME
) {
updateOptions( { reader_theme: LEGACY_THEME_SLUG } );
setThemeWasOverridden( true );
}
}, [ originalSelectedTheme.availability, selectedTheme.availability, themeWasOverridden, updateOptions ] );
Expand Down
49 changes: 49 additions & 0 deletions assets/src/components/svg/desktop-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions assets/src/components/svg/mobile-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 15 additions & 10 deletions assets/src/components/theme-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import PropTypes from 'prop-types';
/**
* Internal dependencies
*/
import './style.css';
import MobileIcon from '../svg/mobile-icon.svg';
import { Options } from '../options-context-provider';
import { Selectable } from '../selectable';
import { Phone } from '../phone';
import './style.css';

/**
* A selectable card showing a theme in a list of themes.
Expand Down Expand Up @@ -48,14 +49,18 @@ export function ThemeCard( { description, ElementName = 'li', homepage, screensh
>
<label htmlFor={ id } className="theme-card__label">
<Phone>
<img
src={ screenshotUrl }
alt={ name }
height="2165"
width="1000"
loading="lazy"
decoding="async"
/>
{
screenshotUrl ? (
<img
src={ screenshotUrl }
alt={ name }
height="2165"
width="1000"
loading="lazy"
decoding="async"
/>
) : <MobileIcon style={ { width: '100%' } } />
}
{ disabled && (
<div className="theme-card__disabled-overlay">
{ __( 'Unavailable', 'amp' ) }
Expand Down Expand Up @@ -96,7 +101,7 @@ ThemeCard.propTypes = {
description: PropTypes.string.isRequired,
ElementName: PropTypes.string,
homepage: PropTypes.string.isRequired,
screenshotUrl: PropTypes.string.isRequired,
screenshotUrl: PropTypes.string,
slug: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
disabled: PropTypes.bool,
Expand Down
5 changes: 1 addition & 4 deletions assets/src/components/theme-card/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@
}
}

.theme-card .phone-inner {
max-height: 307px; /* Make all images uniform height. */
}

.theme-card img {
height: auto;
width: 100%;
margin: auto;
}

p.theme-card__description {
Expand Down
4 changes: 3 additions & 1 deletion assets/src/onboarding-wizard/components/nav/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import './style.css';
import { Options } from '../../../components/options-context-provider';
import { User } from '../user-context-provider';
import { READER } from '../../../common/constants';
import { ReaderThemes } from '../../../components/reader-themes-context-provider';

/**
* Navigation component.
Expand All @@ -36,6 +37,7 @@ export function Nav( { closeLink, finishLink } ) {
originalOptions: { preview_permalink: previewPermalink, reader_theme: readerTheme },
} = useContext( Options );
const { savingDeveloperToolsOption } = useContext( User );
const { downloadingTheme } = useContext( ReaderThemes );

let nextText;
let nextLink;
Expand Down Expand Up @@ -97,7 +99,7 @@ export function Nav( { closeLink, finishLink } ) {
}

<Button
disabled={ ! canGoForward || savingOptions || savingDeveloperToolsOption }
disabled={ ! canGoForward || savingOptions || savingDeveloperToolsOption || downloadingTheme }
href={ nextLink }
id="next-button"
isPrimary
Expand Down
9 changes: 7 additions & 2 deletions assets/src/onboarding-wizard/components/nav/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import { Nav } from '..';
import { NavigationContextProvider } from '../../navigation-context-provider';
import { UserContextProvider } from '../../user-context-provider';
import { OptionsContextProvider } from '../../../../components/options-context-provider';
import { ReaderThemesContextProvider } from '../../../../components/reader-themes-context-provider';
import { STANDARD, READER } from '../../../../common/constants';

jest.mock( '../../../../components/options-context-provider' );
jest.mock( '../../../../components/reader-themes-context-provider' );
jest.mock( '../../user-context-provider' );

let container;
Expand All @@ -35,11 +37,13 @@ const testPages = [
{ PageComponent: MyPageComponent, slug: 'slug-2', title: 'Page 1' },
];

const Providers = ( { children, pages, themeSupport = READER } ) => (
const Providers = ( { children, pages, themeSupport = READER, downloadingTheme = false } ) => (
<OptionsContextProvider themeSupport={ themeSupport }>
<UserContextProvider>
<NavigationContextProvider pages={ pages }>
{ children }
<ReaderThemesContextProvider downloadingTheme={ downloadingTheme }>
{ children }
</ReaderThemesContextProvider>
</NavigationContextProvider>
</UserContextProvider>
</OptionsContextProvider>
Expand All @@ -48,6 +52,7 @@ Providers.propTypes = {
children: PropTypes.any,
pages: PropTypes.array,
themeSupport: PropTypes.string,
downloadingTheme: PropTypes.bool,
};

describe( 'Nav', () => {
Expand Down
23 changes: 14 additions & 9 deletions assets/src/onboarding-wizard/pages/summary/desktop-screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,26 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import { Desktop } from '../../components/desktop';
import DesktopIcon from '../../../components/svg/desktop-icon.svg';

export function DesktopScreenshot( { screenshot, name, description, url } ) {
return (
<div className="selectable selectable--bottom">

<div className="grid grid-1-2 summary-screenshot">
<Desktop>
<img
src={ screenshot }
alt={ name }
loading="lazy"
decoding="async"
height="900"
width="1200"
/>
{
screenshot ? (
<img
src={ screenshot }
alt={ name }
loading="lazy"
decoding="async"
height="900"
width="1200"
/>
) : <DesktopIcon />
}
</Desktop>
<div>
<h3>
Expand All @@ -50,6 +55,6 @@ export function DesktopScreenshot( { screenshot, name, description, url } ) {
DesktopScreenshot.propTypes = {
description: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
screenshot: PropTypes.string.isRequired,
screenshot: PropTypes.string,
url: PropTypes.string.isRequired,
};
Loading

0 comments on commit 2cf9081

Please sign in to comment.