|
| 1 | +import PropTypes from 'prop-types'; |
| 2 | +import React from 'react'; |
| 3 | +import { connect } from 'react-redux'; |
| 4 | +import { compose } from 'redux'; |
| 5 | + |
| 6 | +import translate from 'core/i18n/translate'; |
| 7 | +import Card from 'ui/components/Card'; |
| 8 | + |
| 9 | +import './styles.scss'; |
| 10 | + |
| 11 | + |
| 12 | +export class SearchContextCardBase extends React.Component { |
| 13 | + static propTypes = { |
| 14 | + count: PropTypes.number, |
| 15 | + filters: PropTypes.object, |
| 16 | + i18n: PropTypes.object.isRequired, |
| 17 | + loading: PropTypes.bool.isRequired, |
| 18 | + } |
| 19 | + |
| 20 | + static defaultProps = { |
| 21 | + count: 0, |
| 22 | + filters: {}, |
| 23 | + } |
| 24 | + |
| 25 | + render() { |
| 26 | + const { count, filters, i18n, loading } = this.props; |
| 27 | + const { query } = filters; |
| 28 | + |
| 29 | + let searchText; |
| 30 | + |
| 31 | + if (!loading && query) { |
| 32 | + searchText = i18n.sprintf(i18n.ngettext( |
| 33 | + '%(count)s result for "%(query)s"', |
| 34 | + '%(count)s results for "%(query)s"', |
| 35 | + count), { count: i18n.formatNumber(count), query } |
| 36 | + ); |
| 37 | + } else if (loading && query) { |
| 38 | + searchText = i18n.sprintf(i18n.gettext( |
| 39 | + 'Searching for "%(query)s"'), { query }); |
| 40 | + } else if (loading) { |
| 41 | + searchText = i18n.gettext('Loading add-ons'); |
| 42 | + } else if (!loading && count === 0) { |
| 43 | + searchText = i18n.gettext('No add-ons found'); |
| 44 | + } else { |
| 45 | + searchText = i18n.sprintf(i18n.ngettext( |
| 46 | + '%(count)s add-on found"', |
| 47 | + '%(count)s add-ons found', |
| 48 | + count), { count: i18n.formatNumber(count) } |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | + return ( |
| 53 | + <Card className="SearchContextCard"> |
| 54 | + <h1 className="SearchContextCard-header">{searchText}</h1> |
| 55 | + </Card> |
| 56 | + ); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +export function mapStateToProps(state) { |
| 61 | + return { |
| 62 | + count: state.search.count, |
| 63 | + filters: state.search.filters, |
| 64 | + loading: state.search.loading, |
| 65 | + }; |
| 66 | +} |
| 67 | + |
| 68 | +export default compose( |
| 69 | + connect(mapStateToProps), |
| 70 | + translate(), |
| 71 | +)(SearchContextCardBase); |
0 commit comments