mirror of https://gitlab.com/ecentrics/concordia
Apostolos Fanakis
4 years ago
6 changed files with 115 additions and 20 deletions
@ -1,5 +0,0 @@ |
|||
import React from 'react'; |
|||
|
|||
const HomeContainer = () => (<p>TODO: Home Container</p>); |
|||
|
|||
export default HomeContainer; |
@ -0,0 +1,53 @@ |
|||
import React, { useMemo, useState } from 'react'; |
|||
import { Header } from 'semantic-ui-react'; |
|||
import { connect } from 'react-redux'; |
|||
import _ from 'lodash'; |
|||
import { useTranslation } from 'react-i18next'; |
|||
|
|||
const Board = (props) => { |
|||
const { numberOfTopics, userHasSignedUp } = props; |
|||
const [topicIds, setTopicIds] = useState([]); |
|||
const { t } = useTranslation(); |
|||
|
|||
const boardContents = useMemo(() => { |
|||
if (numberOfTopics > 0) { |
|||
setTopicIds(_.range(0, numberOfTopics)); |
|||
|
|||
return (<div>TODO</div>); |
|||
} if (!userHasSignedUp) { |
|||
return ( |
|||
<div className="vertical-center-in-parent"> |
|||
<Header textAlign="center" as="h2"> |
|||
{t('board.header.no.topics.message')} |
|||
</Header> |
|||
<Header textAlign="center" as="h3"> |
|||
{t('board.sub.header.no.topics.guest')} |
|||
</Header> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
return ( |
|||
<div className="vertical-center-in-parent"> |
|||
<Header textAlign="center" as="h2"> |
|||
{t('board.header.no.topics.message')} |
|||
</Header> |
|||
<Header textAlign="center" as="h3"> |
|||
{t('board.sub.header.no.topics.user')} |
|||
</Header> |
|||
</div> |
|||
); |
|||
}, [numberOfTopics, userHasSignedUp, t]); |
|||
|
|||
return ( |
|||
<div> |
|||
{boardContents} |
|||
</div> |
|||
); |
|||
}; |
|||
|
|||
const mapStateToProps = (state) => ({ |
|||
userHasSignedUp: state.user.hasSignedUp, |
|||
}); |
|||
|
|||
export default connect(mapStateToProps)(Board); |
@ -0,0 +1,34 @@ |
|||
import React, { |
|||
useContext, useEffect, useMemo, useState, |
|||
} from 'react'; |
|||
import { Container } from 'semantic-ui-react'; |
|||
import { connect } from 'react-redux'; |
|||
import AppContext from '../../components/AppContext'; |
|||
import Board from './Board'; |
|||
|
|||
const Home = (props) => { |
|||
const { getNumberOfTopicsResults } = props; |
|||
const { drizzle: { contracts: { Forum: { methods: { getNumberOfTopics } } } } } = useContext(AppContext.Context); |
|||
const [numberOfTopicsCallHash, setNumberOfTopicsCallHash] = useState(''); |
|||
|
|||
useEffect(() => { |
|||
setNumberOfTopicsCallHash(getNumberOfTopics.cacheCall()); |
|||
}, [getNumberOfTopics]); |
|||
|
|||
const numberOfTopics = useMemo(() => (getNumberOfTopicsResults[numberOfTopicsCallHash] !== undefined |
|||
? parseInt(getNumberOfTopicsResults[numberOfTopicsCallHash].value, 10) |
|||
: null), |
|||
[getNumberOfTopicsResults, numberOfTopicsCallHash]); |
|||
|
|||
return ( |
|||
<Container textAlign="center"> |
|||
{numberOfTopics !== null && <Board numberOfTopics={numberOfTopics} />} |
|||
</Container> |
|||
); |
|||
}; |
|||
|
|||
const mapStateToProps = (state) => ({ |
|||
getNumberOfTopicsResults: state.contracts.Forum.getNumberOfTopics, |
|||
}); |
|||
|
|||
export default connect(mapStateToProps)(Home); |
Loading…
Reference in new issue