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/plugin-card/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';
    3 import find from 'lodash/find';
    46
    57/**
     
    79 */
    810import PluginCard from './plugin-card';
    9 import { getPlugin } from 'actions';
     11import { fetchPlugin } from 'state/plugins/actions';
     12import { getPlugin } from 'state/selectors';
    1013
    11 const PluginCardContainer = React.createClass( {
     14export class PluginCardContainer extends Component {
     15    static propTypes = {
     16        fetchPlugin: PropTypes.func,
     17        plugin: PropTypes.object,
     18        slug: PropTypes.string,
     19    };
     20
     21    static defaultProps = {
     22        fetchPlugin: () => {},
     23        plugin: {},
     24        slug: '',
     25    };
     26
    1227    componentDidMount() {
    13         this.getPlugin();
    14     },
     28        this.fetchPlugin();
     29    }
    1530
    16     componentDidUpdate( previousProps ) {
    17         if ( this.props.slug !== previousProps.slug ) {
    18             this.getPlugin();
     31    componentDidUpdate( { plugin, slug } ) {
     32        if ( this.props.slug !== slug || this.props.plugin !== plugin ) {
     33            this.fetchPlugin();
    1934        }
    20     },
     35    }
    2136
    22     getPlugin() {
    23         this.props.dispatch( getPlugin( this.props.slug ) );
    24     },
     37    fetchPlugin() {
     38    //  this.props.fetchPlugin( this.props.slug );
     39    }
    2540
    2641    render() {
    27         return <PluginCard { ...this.props } />;
     42        return <PluginCard plugin={ this.props.plugin } />;
    2843    }
    29 } );
     44}
    3045
    31 const mapStateToProps = ( state, ownProps ) => ( {
    32     plugin: find( state.plugins, { slug: ownProps.slug } )
    33 } );
    34 
    35 export default connect( mapStateToProps )( PluginCardContainer );
    36 
    37 
     46export default connect(
     47    ( state, { plugin, slug } ) => ( {
     48        plugin: plugin || getPlugin( state, slug ),
     49    } ),
     50    {
     51        fetchPlugin,
     52    },
     53)( PluginCardContainer );
Note: See TracChangeset for help on using the changeset viewer.