Making WordPress.org


Ignore:
Timestamp:
03/01/2017 06:08:54 PM (8 years ago)
Author:
obenland
Message:

Plugin Directory: Update React client with latest changes.

This is largely a cleanup commit with some WIP around switching to node-wpapi.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/search/search.jsx

    r4223 r5024  
    1 import React from 'react';
     1/**
     2 * External dependencies.
     3 */
     4import React, { PropTypes } from 'react';
     5import { connect } from 'react-redux';
     6import { identity } from 'lodash';
     7import { localize } from 'i18n-calypso';
    28
     9/**
     10 * Internal dependencies.
     11 */
    312import ContentNone from 'components/content-none';
    413import PluginCard from 'components/plugin-card';
     14import { getSearchResults } from 'state/selectors';
    515
    6 export default React.createClass( {
    7     displayName: 'Search',
     16export const Search = ( { params, plugins, translate } ) => {
     17    if ( ! plugins ) {
     18        return <div>{ translate( 'Loading&hellip;' ) }</div>;
     19    }
    820
    9     render() {
    10         if ( ! this.props.plugins ) {
    11             return <div>{ 'Loading...' }</div>;
    12         }
     21    if ( 0 === plugins.length ) {
     22        return <ContentNone />;
     23    }
    1324
    14         if ( 0 === this.props.plugins.length ) {
    15             return <ContentNone { ...this.props } />;
    16         }
     25    return (
     26        <div>
     27            <header className="page-header">
     28                <h1 className="page-title">
     29                    { translate( 'Search results for: {{strong}}%(search)s{{/strong}}', {
     30                        args: { search: params.search },
     31                        components: { strong: <strong /> },
     32                    } ) }
     33                </h1>
     34                <div className="taxonomy-description" />
     35            </header>
     36            { plugins.map( ( slug ) => <PluginCard key={ slug } slug={ slug } /> ) }
     37        </div>
     38    );
     39};
    1740
    18         return (
    19             <div>
    20                 <header className="page-header">
    21                     <h1 className="page-title">Search results for: <strong>{ this.props.params.searchTerm }</strong></h1>
    22                     <div className="taxonomy-description"></div>
    23                 </header>
    24                 { this.props.plugins.map( slug =>
    25                     <PluginCard key={ slug } slug={ slug } />
    26                 ) }
    27             </div>
    28         );
    29     }
    30 } );
     41Search.propTypes = {
     42    params: PropTypes.object,
     43    plugins: PropTypes.arrayOf( PropTypes.string ),
     44    translate: PropTypes.func,
     45};
     46
     47Search.defaultProps = {
     48    params: {},
     49    plugins: [],
     50    translate: identity,
     51};
     52
     53export default connect(
     54    ( state ) => ( {
     55        plugins: getSearchResults( state ),
     56    } ),
     57)( localize( Search ) );
Note: See TracChangeset for help on using the changeset viewer.