Skip to content

Commit 3e55a5f

Browse files
committed
Use hooks instead of props in DashboardView.
1 parent 1f0b6c0 commit 3e55a5f

File tree

1 file changed

+16
-36
lines changed

1 file changed

+16
-36
lines changed

client/modules/User/pages/DashboardView.jsx

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import PropTypes from 'prop-types';
21
import React, { useState, useCallback } from 'react';
3-
import { connect } from 'react-redux';
2+
import { useDispatch, useSelector } from 'react-redux';
43
import MediaQuery from 'react-responsive';
5-
import { withTranslation } from 'react-i18next';
4+
import { useLocation, useParams } from 'react-router-dom';
5+
import { useTranslation } from 'react-i18next';
66

77
import Button from '../../../common/Button';
88
import Nav from '../../IDE/components/Header/Nav';
@@ -12,7 +12,7 @@ import AssetSize from '../../IDE/components/AssetSize';
1212
import CollectionList from '../../IDE/components/CollectionList';
1313
import SketchList from '../../IDE/components/SketchList';
1414
import RootPage from '../../../components/RootPage';
15-
import * as ProjectActions from '../../IDE/actions/project';
15+
import { newProject } from '../../IDE/actions/project';
1616
import {
1717
CollectionSearchbar,
1818
SketchSearchbar
@@ -23,11 +23,20 @@ import DashboardTabSwitcherPublic, {
2323
TabKey
2424
} from '../components/DashboardTabSwitcher';
2525

26-
const DashboardView = ({ newProject, location, params, user, t }) => {
26+
const DashboardView = () => {
27+
const { t } = useTranslation();
28+
29+
const params = useParams();
30+
const location = useLocation();
31+
32+
const dispatch = useDispatch();
33+
34+
const user = useSelector((state) => state.user);
35+
2736
const [collectionCreateVisible, setCollectionCreateVisible] = useState(false);
2837

2938
const createNewSketch = () => {
30-
newProject();
39+
dispatch(newProject());
3140
};
3241

3342
const selectedTabKey = useCallback(() => {
@@ -142,33 +151,4 @@ const DashboardView = ({ newProject, location, params, user, t }) => {
142151
);
143152
};
144153

145-
DashboardView.defaultProps = {
146-
user: null
147-
};
148-
149-
DashboardView.propTypes = {
150-
newProject: PropTypes.func.isRequired,
151-
location: PropTypes.shape({
152-
pathname: PropTypes.string.isRequired
153-
}).isRequired,
154-
params: PropTypes.shape({
155-
username: PropTypes.string.isRequired
156-
}).isRequired,
157-
user: PropTypes.shape({
158-
username: PropTypes.string
159-
}),
160-
t: PropTypes.func.isRequired
161-
};
162-
163-
const mapStateToProps = (state) => ({
164-
previousPath: state.ide.previousPath,
165-
user: state.user
166-
});
167-
168-
const mapDispatchToProps = {
169-
...ProjectActions
170-
};
171-
172-
export default withTranslation()(
173-
connect(mapStateToProps, mapDispatchToProps)(DashboardView)
174-
);
154+
export default DashboardView;

0 commit comments

Comments
 (0)