Browse Source

Replace mapStateToProps with hook

develop
Apostolos Fanakis 4 years ago
parent
commit
3d35f5df5c
  1. 14
      packages/concordia-app/src/layouts/MainLayout/MainLayoutMenu/index.jsx
  2. 11
      packages/concordia-app/src/views/Home/Board/index.jsx
  3. 12
      packages/concordia-app/src/views/Home/index.jsx

14
packages/concordia-app/src/layouts/MainLayout/MainLayoutMenu/index.jsx

@ -2,12 +2,12 @@ import React from 'react';
import { Menu } from 'semantic-ui-react'; import { Menu } from 'semantic-ui-react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router'; import { useHistory } from 'react-router';
import { connect } from 'react-redux'; import { useSelector } from 'react-redux';
import AppContext from '../../../components/AppContext'; import AppContext from '../../../components/AppContext';
import appLogo from '../../../assets/images/app_logo.png'; import appLogo from '../../../assets/images/app_logo.png';
const MainLayoutMenu = (props) => { const MainLayoutMenu = () => {
const { user: { hasSignedUp } } = props; const hasSignedUp = useSelector((state) => state.user.hasSignedUp);
const history = useHistory(); const history = useHistory();
const { t } = useTranslation(); const { t } = useTranslation();
@ -24,7 +24,7 @@ const MainLayoutMenu = (props) => {
<img src={appLogo} alt="app_logo" /> <img src={appLogo} alt="app_logo" />
</Menu.Item> </Menu.Item>
<Menu.Menu position="right"> <Menu.Menu position="right">
{hasSignedUp && history.location.pathname === '/' && ( {hasSignedUp && history.location.pathname === '/home' && (
<Menu.Item <Menu.Item
link link
name="create-topic" name="create-topic"
@ -63,8 +63,4 @@ const MainLayoutMenu = (props) => {
); );
}; };
const mapStateToProps = (state) => ({ export default MainLayoutMenu;
user: state.user,
});
export default connect(mapStateToProps)(MainLayoutMenu);

11
packages/concordia-app/src/views/Home/Board/index.jsx

@ -1,11 +1,12 @@
import React, { useMemo, useState } from 'react'; import React, { useMemo, useState } from 'react';
import { Header } from 'semantic-ui-react'; import { Header } from 'semantic-ui-react';
import { connect } from 'react-redux';
import _ from 'lodash'; import _ from 'lodash';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
const Board = (props) => { const Board = (props) => {
const { numberOfTopics, userHasSignedUp } = props; const { numberOfTopics } = props;
const userHasSignedUp = useSelector((state) => state.user.hasSignedUp);
const [topicIds, setTopicIds] = useState([]); const [topicIds, setTopicIds] = useState([]);
const { t } = useTranslation(); const { t } = useTranslation();
@ -46,8 +47,4 @@ const Board = (props) => {
); );
}; };
const mapStateToProps = (state) => ({ export default Board;
userHasSignedUp: state.user.hasSignedUp,
});
export default connect(mapStateToProps)(Board);

12
packages/concordia-app/src/views/Home/index.jsx

@ -2,12 +2,12 @@ import React, {
useContext, useEffect, useMemo, useState, useContext, useEffect, useMemo, useState,
} from 'react'; } from 'react';
import { Container } from 'semantic-ui-react'; import { Container } from 'semantic-ui-react';
import { connect } from 'react-redux'; import { useSelector } from 'react-redux';
import AppContext from '../../components/AppContext'; import AppContext from '../../components/AppContext';
import Board from './Board'; import Board from './Board';
const Home = (props) => { const Home = () => {
const { getNumberOfTopicsResults } = props; const getNumberOfTopicsResults = useSelector((state) => state.contracts.Forum.getNumberOfTopics);
const { drizzle: { contracts: { Forum: { methods: { getNumberOfTopics } } } } } = useContext(AppContext.Context); const { drizzle: { contracts: { Forum: { methods: { getNumberOfTopics } } } } } = useContext(AppContext.Context);
const [numberOfTopicsCallHash, setNumberOfTopicsCallHash] = useState(''); const [numberOfTopicsCallHash, setNumberOfTopicsCallHash] = useState('');
@ -27,8 +27,4 @@ const Home = (props) => {
); );
}; };
const mapStateToProps = (state) => ({ export default Home;
getNumberOfTopicsResults: state.contracts.Forum.getNumberOfTopics,
});
export default connect(mapStateToProps)(Home);

Loading…
Cancel
Save