Skip to content
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
185 changes: 185 additions & 0 deletions src/amo/components/Home/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { compose } from 'redux';

import { setViewContext } from 'amo/actions/viewContext';
import Link from 'amo/components/Link';
import {
CLIENT_APP_ANDROID,
CLIENT_APP_FIREFOX,
VIEW_CONTEXT_HOME,
} from 'core/constants';
import translate from 'core/i18n/translate';
import Card from 'ui/components/Card';

import './styles.scss';


export const CategoryLink = ({ children, name, slug, type }) => {
return (
<li className={classNames('Home-category-li', `Home-${name}`)}>
<Link to={`/${type}/${slug}/`} className="Home-category-link">
<span>{children}</span>
</Link>
</li>
);
};
CategoryLink.propTypes = {
children: PropTypes.node.isRequired,
name: PropTypes.string.isRequired,
slug: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
};

export const ExtensionLink = (props) => {
return <CategoryLink type="extensions" {...props} />;
};

export const ThemeLink = (props) => {
return <CategoryLink type="themes" {...props} />;
};

export class HomeBase extends React.Component {
static propTypes = {
clientApp: PropTypes.string.isRequired,
dispatch: PropTypes.func.isRequired,
i18n: PropTypes.object.isRequired,
}

componentWillMount() {
const { dispatch } = this.props;

dispatch(setViewContext(VIEW_CONTEXT_HOME));
}

extensionsCategoriesForClientApp() {
const { clientApp, i18n } = this.props;

let linkHTML = null;

if (clientApp === CLIENT_APP_ANDROID) {
linkHTML = (
<ul className="Home-category-list">
<ExtensionLink name="block-ads" slug="security-privacy">
{i18n.gettext('Block ads')}
</ExtensionLink>
<ExtensionLink name="screenshot" slug="photos-media">
{i18n.gettext('Screenshot')}
</ExtensionLink>
<ExtensionLink name="find-news" slug="feeds-news-blogging">
{i18n.gettext('Find news')}
</ExtensionLink>
<ExtensionLink name="shop-online" slug="shopping">
{i18n.gettext('Shop online')}
</ExtensionLink>
<ExtensionLink name="be-social" slug="social-networking">
{i18n.gettext('Be social')}
</ExtensionLink>
<ExtensionLink name="play-games" slug="sports-games">
{i18n.gettext('Play games')}
</ExtensionLink>
</ul>
);
}

if (clientApp === CLIENT_APP_FIREFOX) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to have these work from the API at some point but probably better to do that after cats are consolidated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the thing is the category API just returns everything... I guess we could request filters on it though.

linkHTML = (
<ul className="Home-category-list">
<ExtensionLink name="block-ads" slug="privacy-security">
{i18n.gettext('Block ads')}
</ExtensionLink>
<ExtensionLink name="screenshot" slug="photos-media">
{i18n.gettext('Screenshot')}
</ExtensionLink>
<ExtensionLink name="find-news" slug="feeds-news-blogging">
{i18n.gettext('Find news')}
</ExtensionLink>
<ExtensionLink name="shop-online" slug="shopping">
{i18n.gettext('Shop online')}
</ExtensionLink>
<ExtensionLink name="be-social" slug="social-networking">
{i18n.gettext('Be social')}
</ExtensionLink>
<ExtensionLink name="play-games" slug="sports-games">
{i18n.gettext('Play games')}
</ExtensionLink>
</ul>
);
}

return linkHTML;
}

themesCategoriesForClientApp() {
const { i18n } = this.props;

return (
<ul className="Home-category-list">
<ThemeLink name="wild" slug="nature">{i18n.gettext('Wild')}</ThemeLink>
<ThemeLink name="abstract" slug="abstract">{i18n.gettext('Abstract')}</ThemeLink>
<ThemeLink name="holiday" slug="holiday">{i18n.gettext('Holiday')}</ThemeLink>
<ThemeLink name="scenic" slug="scenery">{i18n.gettext('Scenic')}</ThemeLink>
<ThemeLink name="sporty" slug="sports">{i18n.gettext('Sporty')}</ThemeLink>
<ThemeLink name="solid" slug="solid">{i18n.gettext('Solid')}</ThemeLink>
</ul>
);
}

render() {
const { i18n } = this.props;

return (
<div className="Home">
<Card
className="Home-category-card Home-category-card--extensions"
footerLink={<Link to="/extensions/">
{i18n.gettext('Browse all extensions')}
</Link>}
>
<div className="Home-text-wrapper">
<h2 className="Home-subheading">
{i18n.gettext('You can change how Firefox works…')}
</h2>
<p className="Home-description">
{i18n.gettext(
'Install powerful tools that make browsing faster and safer, add-ons make your browser yours.')}
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use a un-tagged template literal here if that helps with wrapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good call, will do.

</p>
</div>

{this.extensionsCategoriesForClientApp()}
</Card>

<Card
className="Home-category-card Home-category-card--themes"
footerLink={<Link to="/themes/">
{i18n.gettext('Browse all themes')}
</Link>}
>
<div className="Home-text-wrapper">
<h2 className="Home-subheading">
{i18n.gettext('…or what it looks like')}
</h2>
<p className="Home-description">
{i18n.gettext(
"Change your browser's appearance. Choose from thousands of themes to give Firefox the look you want.")}
</p>
</div>

{this.themesCategoriesForClientApp()}
</Card>
</div>
);
}
}

export function mapStateToProps(state) {
return { clientApp: state.api.clientApp };
}

export default compose(
// This allows us to dispatch from our component.
connect(mapStateToProps),
translate({ withRef: true }),
)(HomeBase);
195 changes: 195 additions & 0 deletions src/amo/components/Home/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
@import "~core/css/inc/mixins";
@import "~amo/css/inc/vars";
@import "~ui/css/vars";

.Home {
padding: $padding-page;
}

.Home-category-card {
margin-bottom: 10px;

.Card-contents {
@include respond-to(medium) {
display: flex;
flex-flow: row nowrap;
}
}
}

.Home-text-wrapper {
align-self: auto;

@include respond-to(medium) {
align-self: center;
}

@include respond-to(large) {
max-width: 200px;
}
}

.Home-subheading {
line-height: 1.2;
margin-bottom: -10px;
margin-top: 18px;
text-align: center;

@include respond-to(medium) {
@include text-align-start();
}
}

.Home-description {
display: none;

@include respond-to(medium) {
display: block;
}
}

.Home-category-list {
display: flex;
flex-flow: row wrap;
overflow: auto;
margin-bottom: 0;
padding: 0;
width: 100%;

@include respond-to(large) {
flex-wrap: nowrap;
}
}

.Home-category-li {
background-color: $base-color;
background-size: 50% auto;
background-position: 50% 35%;
background-repeat: no-repeat;
border-radius: 6px;
display: block;
flex-grow: 1;
list-style-type: none;
margin: 5px;
overflow: auto;
padding: 0;
position: relative;
text-align: center;
width: 25%;

a:link {
font-size: 10px;
text-decoration: none;
padding-top: 70%;
display: block;
}

a:hover,
a:focus {
text-decoration: underline;
}

span {
display: block;
padding: 5px 10px;
text-align: center;
text-decoration: inherit;
}
}

.Home-category-link,
.Home-extensions-link,
.Home-themes-link {
&,
&:visited {
color: $link-color;
}
}

.Home-extensions-link:link,
.Home-themes-link:link {
align-items: center;
background: $base-color;
border-radius: 6px;
display: flex;
font-size: 10px;
justify-content: center;
margin: 0 auto 20px;
padding: 10px;
text-align: center;
text-decoration: none;
text-transform: uppercase;
width: calc(100% - 40px);

&:hover,
&:focus {
text-decoration: underline;
}

&::before {
content: '';
display: inline-block;
width: 16px;
height: 16px;
margin: 0 5px;
}
}

.Home-extensions-link:link::before {
Copy link
Contributor

Choose a reason for hiding this comment

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

E_LINK_OVERLOAD

Copy link
Contributor

Choose a reason for hiding this comment

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

Not that there's an obvious alternative afaict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I really forget why we're using :link on a styles but my goodness is it frustrating.

background: url('~amo/img/icons/addon-outline.svg') no-repeat 50% 50%;
background-size: cover;
}

.Home-themes-link:link::before {
background: url('~amo/img/icons/theme-outline.svg') no-repeat 50% 50%;
background-size: cover;
}

.Home-block-ads {
background-image: url('~amo/img/home/block-ads.svg');
}

.Home-screenshot {
background-image: url('~amo/img/home/screenshot.svg');
}

.Home-find-news {
background-image: url('~amo/img/home/find-news.svg');
background-size: 40% auto;
}

.Home-shop-online {
background-image: url('~amo/img/home/shop-online.svg');
}

.Home-be-social {
background-image: url('~amo/img/home/be-social.svg');
}

.Home-play-games {
background-image: url('~amo/img/home/play-games.svg');
}

.Home-wild {
background-image: url('~amo/img/home/wild.svg');
}

.Home-abstract {
background-image: url('~amo/img/home/abstract.svg');
}

.Home-holiday {
background-image: url('~amo/img/home/holiday.svg');
}

.Home-scenic {
background-image: url('~amo/img/home/scenic.svg');
}

.Home-sporty {
background-image: url('~amo/img/home/sporty.svg');
}

.Home-solid {
background-image: url('~amo/img/home/solid.svg');
}
Loading