Skip to content

Commit 2b9cb0a

Browse files
authored
Merge pull request #3209 from processing/react-fc-conversion-2
React component conversion(class to functional) - 2
2 parents 87b4199 + 4b19f9e commit 2b9cb0a

File tree

4 files changed

+65
-38
lines changed

4 files changed

+65
-38
lines changed

client/modules/IDE/components/QuickAddList/QuickAddList.jsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,21 @@ const Item = ({ isAdded, onSelect, name, url }) => {
1010
const buttonLabel = isAdded
1111
? t('QuickAddList.ButtonRemoveARIA')
1212
: t('QuickAddList.ButtonAddToCollectionARIA');
13+
14+
const handleKeyDown = (event) => {
15+
if (event.key === 'Enter' || event.key === ' ') {
16+
onSelect(event);
17+
}
18+
};
19+
1320
return (
14-
<li className="quick-add__item" onClick={onSelect}> { /* eslint-disable-line */ }
21+
<div
22+
role="button"
23+
className="quick-add__item"
24+
onClick={onSelect}
25+
onKeyDown={handleKeyDown}
26+
tabIndex={0}
27+
>
1528
<button
1629
className="quick-add__item-toggle"
1730
onClick={onSelect}
@@ -28,7 +41,7 @@ const Item = ({ isAdded, onSelect, name, url }) => {
2841
>
2942
{t('QuickAddList.View')}
3043
</Link>
31-
</li>
44+
</div>
3245
);
3346
};
3447

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
import { bindActionCreators } from 'redux';
2-
import { connect } from 'react-redux';
1+
import React from 'react';
2+
import { useDispatch, useSelector } from 'react-redux';
33
import i18next from 'i18next';
44
import * as SortingActions from '../../actions/sorting';
55

66
import Searchbar from './Searchbar';
77

88
const scope = 'collection';
99

10-
function mapStateToProps(state) {
11-
return {
12-
searchLabel: i18next.t('Searchbar.SearchCollection'),
13-
searchTerm: state.search[`${scope}SearchTerm`]
10+
const SearchbarContainer = () => {
11+
const dispatch = useDispatch();
12+
const searchLabel = i18next.t('Searchbar.SearchCollection');
13+
const searchTerm = useSelector((state) => state.search[`${scope}SearchTerm`]);
14+
15+
const setSearchTerm = (term) => {
16+
dispatch(SortingActions.setSearchTerm(scope, term));
1417
};
15-
}
1618

17-
function mapDispatchToProps(dispatch) {
18-
const actions = {
19-
setSearchTerm: (term) => SortingActions.setSearchTerm(scope, term),
20-
resetSearchTerm: () => SortingActions.resetSearchTerm(scope)
19+
const resetSearchTerm = () => {
20+
dispatch(SortingActions.resetSearchTerm(scope));
2121
};
22-
return bindActionCreators(Object.assign({}, actions), dispatch);
23-
}
2422

25-
export default connect(mapStateToProps, mapDispatchToProps)(Searchbar);
23+
return (
24+
<Searchbar
25+
searchLabel={searchLabel}
26+
searchTerm={searchTerm}
27+
setSearchTerm={setSearchTerm}
28+
resetSearchTerm={resetSearchTerm}
29+
/>
30+
);
31+
};
32+
33+
export default SearchbarContainer;

client/modules/IDE/components/Searchbar/Searchbar.jsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import React, { useState, useCallback, useEffect } from 'react';
22
import PropTypes from 'prop-types';
33
import { throttle } from 'lodash';
4-
import { withTranslation } from 'react-i18next';
4+
import { useTranslation } from 'react-i18next';
55
import i18next from 'i18next';
66
import SearchIcon from '../../../../images/magnifyingglass.svg';
77

88
const Searchbar = ({
99
searchTerm,
1010
setSearchTerm,
1111
resetSearchTerm,
12-
searchLabel,
13-
t
12+
searchLabel
1413
}) => {
14+
const { t } = useTranslation();
1515
const [searchValue, setSearchValue] = useState(searchTerm);
1616

1717
const throttledSearchChange = useCallback(
1818
throttle((value) => {
1919
setSearchTerm(value.trim());
2020
}, 500),
21-
[]
21+
[setSearchTerm]
2222
);
2323

2424
const handleResetSearch = () => {
@@ -65,12 +65,11 @@ Searchbar.propTypes = {
6565
searchTerm: PropTypes.string.isRequired,
6666
setSearchTerm: PropTypes.func.isRequired,
6767
resetSearchTerm: PropTypes.func.isRequired,
68-
searchLabel: PropTypes.string,
69-
t: PropTypes.func.isRequired
68+
searchLabel: PropTypes.string
7069
};
7170

7271
Searchbar.defaultProps = {
7372
searchLabel: i18next.t('Searchbar.SearchSketch')
7473
};
7574

76-
export default withTranslation()(Searchbar);
75+
export default Searchbar;
Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
import { bindActionCreators } from 'redux';
2-
import { connect } from 'react-redux';
1+
import React from 'react';
2+
import { useDispatch, useSelector } from 'react-redux';
33
import i18next from 'i18next';
44
import * as SortingActions from '../../actions/sorting';
5-
65
import Searchbar from './Searchbar';
76

87
const scope = 'sketch';
98

10-
function mapStateToProps(state) {
11-
return {
12-
searchLabel: i18next.t('Searchbar.SearchSketch'),
13-
searchTerm: state.search[`${scope}SearchTerm`]
9+
const SearchbarContainer = () => {
10+
const dispatch = useDispatch();
11+
const searchLabel = i18next.t('Searchbar.SearchSketch');
12+
const searchTerm = useSelector((state) => state.search[`${scope}SearchTerm`]);
13+
14+
const setSearchTerm = (term) => {
15+
dispatch(SortingActions.setSearchTerm(scope, term));
1416
};
15-
}
1617

17-
function mapDispatchToProps(dispatch) {
18-
const actions = {
19-
setSearchTerm: (term) => SortingActions.setSearchTerm(scope, term),
20-
resetSearchTerm: () => SortingActions.resetSearchTerm(scope)
18+
const resetSearchTerm = () => {
19+
dispatch(SortingActions.resetSearchTerm(scope));
2120
};
22-
return bindActionCreators(Object.assign({}, actions), dispatch);
23-
}
2421

25-
export default connect(mapStateToProps, mapDispatchToProps)(Searchbar);
22+
return (
23+
<Searchbar
24+
searchLabel={searchLabel}
25+
searchTerm={searchTerm}
26+
setSearchTerm={setSearchTerm}
27+
resetSearchTerm={resetSearchTerm}
28+
/>
29+
);
30+
};
31+
32+
export default SearchbarContainer;

0 commit comments

Comments
 (0)