Changeset 5024 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/search-form/index.jsx
- Timestamp:
- 03/01/2017 06:08:54 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/search-form/index.jsx
r4223 r5024 1 import React from 'react'; 1 /** 2 * Internal dependencies. 3 */ 4 import React, { Component, PropTypes } from 'react'; 5 import { connect } from 'react-redux'; 2 6 import { withRouter } from 'react-router'; 3 7 … … 5 9 * Internal dependencies. 6 10 */ 11 import { getSearchTerm } from 'state/selectors'; 7 12 import SearchForm from './search-form'; 8 13 9 const SearchFormContainer = React.createClass( { 10 getInitialState() { 11 return { 12 searchTerm: this.props.searchTerm 13 }; 14 }, 14 export class SearchFormContainer extends Component { 15 static propTypes = { 16 router: PropTypes.object, 17 search: PropTypes.string, 18 }; 15 19 16 onChange( searchTerm ) { 17 this.setState( { 18 searchTerm: searchTerm 19 } ); 20 }, 20 static defaultProps = { 21 router: {}, 22 search: '', 23 }; 21 24 22 componentWillReceiveProps( nextProps ) { 23 this.setState( { 24 searchTerm: nextProps.searchTerm 25 } ); 26 }, 25 onChange = ( search ) => { 26 this.setState( { search } ); 27 }; 27 28 28 onSubmit ( event ){29 var searchTerm = encodeURIComponent( this.state.searchTerm);29 onSubmit = ( event ) => { 30 const search = encodeURIComponent( this.state.search ); 30 31 event.preventDefault(); 31 32 32 if ( search Term) {33 this.props.router.push( `/search/${ search Term}/` );33 if ( search ) { 34 this.props.router.push( `/search/${ search }/` ); 34 35 } else { 35 36 this.props.router.push( '/' ); 36 37 } 37 }, 38 }; 39 40 constructor() { 41 super( ...arguments ); 42 43 this.state = { 44 search: this.props.search, 45 }; 46 } 47 48 componentWillReceiveProps( { search } ) { 49 this.setState( { search } ); 50 } 38 51 39 52 render() { 40 return <SearchForm searchTerm={ this.state.searchTerm }onSubmit={ this.onSubmit } onChange={ this.onChange } />;53 return <SearchForm onSubmit={ this.onSubmit } onChange={ this.onChange } />; 41 54 } 42 } );55 } 43 56 44 export default withRouter( SearchFormContainer ); 57 export default withRouter( connect( 58 ( state ) => ( { 59 search: getSearchTerm( state ), 60 } ), 61 )( SearchFormContainer ) );
Note: See TracChangeset
for help on using the changeset viewer.