Making WordPress.org


Ignore:
Timestamp:
03/01/2017 06:08:54 PM (7 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/archive/browse/index.jsx

    r4223 r5024  
    1 import React from 'react';
     1/**
     2 * External dependencies.
     3 */
     4import React, { Component, PropTypes } from 'react';
    25import { connect } from 'react-redux';
    36
    4 import { getBrowse } from 'actions';
     7/**
     8 * Internal dependencies.
     9 */
     10import { fetchSection, fetchSections } from 'state/sections/actions';
     11import { getSection } from 'state/selectors';
    512import Browse from './browse';
    613
    7 const BrowseContainer = React.createClass( {
     14export class BrowseContainer extends Component {
     15    static propTypes = {
     16        fetchSection: PropTypes.func,
     17        params: PropTypes.object,
     18    };
     19
     20    static defaultProps = {
     21        fetchSection: () => {},
     22        params: {},
     23    };
     24
    825    componentDidMount() {
    9         this.getBrowse();
    10     },
     26        this.fetchSection();
     27    }
    1128
    12     componentDidUpdate( previousProps ) {
    13         if ( this.props.params.type !== previousProps.params.type ) {
    14             this.getBrowse();
     29    componentDidUpdate( { params } ) {
     30        if ( this.props.params.type !== params.type ) {
     31            this.fetchSection();
    1532        }
    16     },
     33    }
    1734
    18     getBrowse() {
    19         this.props.dispatch( getBrowse( this.props.params.type ) );
    20     },
     35    fetchSection() {
     36        if ( ! this.props.section ) {
     37            this.props.fetchSections();
     38        }
     39        this.props.fetchSection( this.props.params.type );
     40    }
    2141
    2242    render() {
    23         return <Browse { ...this.props } />;
     43        return <Browse type={ this.props.params.type } />;
    2444    }
    25 } );
     45}
    2646
    27 const mapStateToProps = ( state, ownProps ) => ( {
    28     plugins: state.browse[ ownProps.params.type ]
    29 } );
    30 
    31 export default connect( mapStateToProps )( BrowseContainer );
    32 
    33 
     47export default connect(
     48    ( state, { params } ) => ( {
     49        section: getSection( state, params.type ),
     50    } ),
     51    {
     52        fetchSection,
     53        fetchSections,
     54    },
     55)( BrowseContainer );
Note: See TracChangeset for help on using the changeset viewer.