-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3209 from processing/react-fc-conversion-2
React component conversion(class to functional) - 2
- Loading branch information
Showing
4 changed files
with
65 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
import { bindActionCreators } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import React from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import i18next from 'i18next'; | ||
import * as SortingActions from '../../actions/sorting'; | ||
|
||
import Searchbar from './Searchbar'; | ||
|
||
const scope = 'collection'; | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
searchLabel: i18next.t('Searchbar.SearchCollection'), | ||
searchTerm: state.search[`${scope}SearchTerm`] | ||
const SearchbarContainer = () => { | ||
const dispatch = useDispatch(); | ||
const searchLabel = i18next.t('Searchbar.SearchCollection'); | ||
const searchTerm = useSelector((state) => state.search[`${scope}SearchTerm`]); | ||
|
||
const setSearchTerm = (term) => { | ||
dispatch(SortingActions.setSearchTerm(scope, term)); | ||
}; | ||
} | ||
|
||
function mapDispatchToProps(dispatch) { | ||
const actions = { | ||
setSearchTerm: (term) => SortingActions.setSearchTerm(scope, term), | ||
resetSearchTerm: () => SortingActions.resetSearchTerm(scope) | ||
const resetSearchTerm = () => { | ||
dispatch(SortingActions.resetSearchTerm(scope)); | ||
}; | ||
return bindActionCreators(Object.assign({}, actions), dispatch); | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Searchbar); | ||
return ( | ||
<Searchbar | ||
searchLabel={searchLabel} | ||
searchTerm={searchTerm} | ||
setSearchTerm={setSearchTerm} | ||
resetSearchTerm={resetSearchTerm} | ||
/> | ||
); | ||
}; | ||
|
||
export default SearchbarContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,32 @@ | ||
import { bindActionCreators } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import React from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import i18next from 'i18next'; | ||
import * as SortingActions from '../../actions/sorting'; | ||
|
||
import Searchbar from './Searchbar'; | ||
|
||
const scope = 'sketch'; | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
searchLabel: i18next.t('Searchbar.SearchSketch'), | ||
searchTerm: state.search[`${scope}SearchTerm`] | ||
const SearchbarContainer = () => { | ||
const dispatch = useDispatch(); | ||
const searchLabel = i18next.t('Searchbar.SearchSketch'); | ||
const searchTerm = useSelector((state) => state.search[`${scope}SearchTerm`]); | ||
|
||
const setSearchTerm = (term) => { | ||
dispatch(SortingActions.setSearchTerm(scope, term)); | ||
}; | ||
} | ||
|
||
function mapDispatchToProps(dispatch) { | ||
const actions = { | ||
setSearchTerm: (term) => SortingActions.setSearchTerm(scope, term), | ||
resetSearchTerm: () => SortingActions.resetSearchTerm(scope) | ||
const resetSearchTerm = () => { | ||
dispatch(SortingActions.resetSearchTerm(scope)); | ||
}; | ||
return bindActionCreators(Object.assign({}, actions), dispatch); | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Searchbar); | ||
return ( | ||
<Searchbar | ||
searchLabel={searchLabel} | ||
searchTerm={searchTerm} | ||
setSearchTerm={setSearchTerm} | ||
resetSearchTerm={resetSearchTerm} | ||
/> | ||
); | ||
}; | ||
|
||
export default SearchbarContainer; |