mirror of https://gitlab.com/ecentrics/concordia
Apostolos Fanakis
4 years ago
7 changed files with 83 additions and 92 deletions
@ -1,31 +1,34 @@ |
|||||
import React, { |
import React, { |
||||
useContext, useEffect, useMemo, useState, |
memo, useEffect, useMemo, useState, |
||||
} from 'react'; |
} from 'react'; |
||||
import { Container } from 'semantic-ui-react'; |
import { Container } from 'semantic-ui-react'; |
||||
import { useSelector } from 'react-redux'; |
import { useSelector } from 'react-redux'; |
||||
import AppContext from '../../components/AppContext'; |
|
||||
import Board from './Board'; |
import Board from './Board'; |
||||
import './styles.css'; |
import './styles.css'; |
||||
|
import { drizzle } from '../../redux/store'; |
||||
|
|
||||
|
const { contracts: { Forum: { methods: { getNumberOfTopics } } } } = drizzle; |
||||
|
|
||||
const Home = () => { |
const Home = () => { |
||||
const { drizzle: { contracts: { Forum: { methods: { getNumberOfTopics } } } } } = useContext(AppContext.Context); |
|
||||
const [numberOfTopicsCallHash, setNumberOfTopicsCallHash] = useState(''); |
const [numberOfTopicsCallHash, setNumberOfTopicsCallHash] = useState(''); |
||||
const getNumberOfTopicsResults = useSelector((state) => state.contracts.Forum.getNumberOfTopics); |
const getNumberOfTopicsResults = useSelector((state) => state.contracts.Forum.getNumberOfTopics); |
||||
|
|
||||
useEffect(() => { |
useEffect(() => { |
||||
setNumberOfTopicsCallHash(getNumberOfTopics.cacheCall()); |
setNumberOfTopicsCallHash(getNumberOfTopics.cacheCall()); |
||||
}, [getNumberOfTopics]); |
}, []); |
||||
|
|
||||
const numberOfTopics = useMemo(() => (getNumberOfTopicsResults[numberOfTopicsCallHash] !== undefined |
const numberOfTopics = useMemo(() => (getNumberOfTopicsResults[numberOfTopicsCallHash] !== undefined |
||||
? parseInt(getNumberOfTopicsResults[numberOfTopicsCallHash].value, 10) |
? parseInt(getNumberOfTopicsResults[numberOfTopicsCallHash].value, 10) |
||||
: null), |
: null), |
||||
[getNumberOfTopicsResults, numberOfTopicsCallHash]); |
[getNumberOfTopicsResults, numberOfTopicsCallHash]); |
||||
|
|
||||
return ( |
return useMemo(() => ( |
||||
<Container id="home-container" textAlign="center"> |
<Container id="home-container" textAlign="center"> |
||||
{numberOfTopics !== null && <Board numberOfTopics={numberOfTopics} />} |
{numberOfTopics !== null && <Board numberOfTopics={numberOfTopics} />} |
||||
</Container> |
</Container> |
||||
); |
), [numberOfTopics]); |
||||
}; |
}; |
||||
|
|
||||
export default Home; |
Home.whyDidYouRender = true; |
||||
|
|
||||
|
export default memo(Home); |
||||
|
Loading…
Reference in new issue