Skip to content

Commit

Permalink
feat: Add desktop view for search (fix #2560)
Browse files Browse the repository at this point in the history
  • Loading branch information
tofumatt committed Jun 21, 2017
1 parent 0158cd6 commit dd6282f
Show file tree
Hide file tree
Showing 24 changed files with 720 additions and 307 deletions.
5 changes: 5 additions & 0 deletions src/amo/components/Addon/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
padding: 20px 10px;
}

.Addon .Card {
margin-bottom: 10px;
}

.Addon-icon-image {
height: 48px;
width: 48px;
Expand Down Expand Up @@ -144,6 +148,7 @@
grid-auto-flow: column dense;
grid-gap: 10px;
grid-template-columns: minmax(300px, 35%) auto;
margin: 10px 0 0;

.AddonDescription {
grid-column: 2;
Expand Down
2 changes: 2 additions & 0 deletions src/amo/components/AddonsCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
import SearchResult from 'amo/components/SearchResult';
import CardList from 'ui/components/CardList';

import './styles.scss';


export default class AddonsCard extends React.Component {
static propTypes = {
Expand Down
16 changes: 16 additions & 0 deletions src/amo/components/AddonsCard/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@import "~amo/css/inc/vars";
@import "~core/css/inc/mixins";
@import "~ui/css/vars";

@include respond-to(large) {
ul.AddonsCard-list {
display: grid;
grid-auto-flow: column dense;
grid-template-columns: 50% 50%;

.SearchResult {
background: $white;
grid-column: 1 / -1;
}
}
}
2 changes: 1 addition & 1 deletion src/amo/components/LandingPage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
align-items: center;
display: flex;
flex-direction: column;
margin: $padding-page $padding-page ($padding-page * 2);
margin: $padding-page;
}

.LandingPage-header-top {
Expand Down
15 changes: 13 additions & 2 deletions src/amo/components/Search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { compose } from 'redux';

import { setViewContext } from 'amo/actions/viewContext';
import Link from 'amo/components/Link';
import SearchContextCard from 'amo/components/SearchContextCard';
import Paginate from 'core/components/Paginate';
import { VIEW_CONTEXT_EXPLORE } from 'core/constants';
import SearchResults from 'amo/components/SearchResults';
Expand All @@ -16,6 +17,8 @@ import {
} from 'core/searchUtils';
import { safeAsyncConnect } from 'core/utils';

import './styles.scss';


export class SearchBase extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -54,8 +57,15 @@ export class SearchBase extends React.Component {

render() {
const {
LinkComponent, count, enableSearchSort, filters, hasSearchParams,
loading, page, pathname, results,
LinkComponent,
count,
enableSearchSort,
filters,
hasSearchParams,
loading,
page,
pathname,
results,
} = this.props;
const queryParams = this.props.queryParams ||
convertFiltersToQueryParams(filters);
Expand All @@ -69,6 +79,7 @@ export class SearchBase extends React.Component {

return (
<div className="Search">
<SearchContextCard />
{searchSort}
<SearchResults count={count} hasSearchParams={hasSearchParams}
filters={filters} loading={loading} pathname={pathname}
Expand Down
53 changes: 52 additions & 1 deletion src/amo/components/Search/styles.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
@import "~amo/css/inc/vars";
@import "~core/css/inc/mixins";

.Search {
padding: $padding-page $padding-page 0;
@include respond-to(large) {
display: grid;
grid-auto-flow: column dense;
grid-gap: 10px;
grid-template-columns: minmax(300px, 35%) auto;
padding: $padding-page;
}

.Card {
margin: $padding-page;

@include respond-to(large) {
margin: 0;
}
}

.SearchSort {
margin: $padding-page;

@include respond-to(large) {
margin: 0;
}
}

.SearchContextCard {
@include respond-to(large) {
grid-column: 1 / -1;
grid-row: 1;
}
}

.SearchSort {
@include respond-to(large) {
grid-column: 1 / 2;
grid-row: 2;
}
}

.SearchResults {
@include respond-to(large) {
grid-column: 2;
grid-row: 2 / 4;
}
}

.Paginate {
@include respond-to(large) {
grid-column: 1 / -1;
grid-row: 4;
}
}
}
71 changes: 71 additions & 0 deletions src/amo/components/SearchContextCard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { compose } from 'redux';

import translate from 'core/i18n/translate';
import Card from 'ui/components/Card';

import './styles.scss';


export class SearchContextCardBase extends React.Component {
static propTypes = {
count: PropTypes.number,
filters: PropTypes.object,
i18n: PropTypes.object.isRequired,
loading: PropTypes.bool.isRequired,
}

static defaultProps = {
count: 0,
filters: {},
}

render() {
const { count, filters, i18n, loading } = this.props;
const { query } = filters;

let searchText;

if (!loading && query) {
searchText = i18n.sprintf(i18n.ngettext(
'%(count)s result for "%(query)s"',
'%(count)s results for "%(query)s"',
count), { count: i18n.formatNumber(count), query }
);
} else if (loading && query) {
searchText = i18n.sprintf(i18n.gettext(
'Searching for "%(query)s"'), { query });
} else if (loading) {
searchText = i18n.gettext('Loading add-ons');
} else if (!loading && count === 0) {
searchText = i18n.gettext('No add-ons found');
} else {
searchText = i18n.sprintf(i18n.ngettext(
'%(count)s add-on found"',
'%(count)s add-ons found',
count), { count: i18n.formatNumber(count) }
);
}

return (
<Card className="SearchContextCard">
<h1 className="SearchContextCard-header">{searchText}</h1>
</Card>
);
}
}

export function mapStateToProps(state) {
return {
count: state.search.count,
filters: state.search.filters,
loading: state.search.loading,
};
}

export default compose(
connect(mapStateToProps),
translate(),
)(SearchContextCardBase);
6 changes: 6 additions & 0 deletions src/amo/components/SearchContextCard/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import "~ui/css/vars";

.SearchContextCard-header {
font-size: $font-size-l;
margin: 0;
}
73 changes: 0 additions & 73 deletions src/amo/components/SearchResult.js

This file was deleted.

Loading

0 comments on commit dd6282f

Please sign in to comment.