From 3e3fd07832e70dab3db5df64f7caeb7d7cb34ec5 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 1 Mar 2021 15:05:39 +0200 Subject: [PATCH] feat: add Concordia status segment --- .../src/components/Status/StatusSegment.jsx | 2 +- .../src/components/Status/StatusValueRow.jsx | 2 +- .../src/components/Status/styles.css | 4 + .../MainLayoutConcordiaStatus/index.jsx | 84 +++++++++++++++++++ .../src/layouts/MainLayout/index.jsx | 2 + 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 packages/concordia-app/src/layouts/MainLayout/MainLayoutConcordiaStatus/index.jsx diff --git a/packages/concordia-app/src/components/Status/StatusSegment.jsx b/packages/concordia-app/src/components/Status/StatusSegment.jsx index 7c95004..c0ccebf 100644 --- a/packages/concordia-app/src/components/Status/StatusSegment.jsx +++ b/packages/concordia-app/src/components/Status/StatusSegment.jsx @@ -9,7 +9,7 @@ const StatusKeyRow = (props) => { return (
- + {headerTitle}
diff --git a/packages/concordia-app/src/components/Status/StatusValueRow.jsx b/packages/concordia-app/src/components/Status/StatusValueRow.jsx index dda44f3..3c71c59 100644 --- a/packages/concordia-app/src/components/Status/StatusValueRow.jsx +++ b/packages/concordia-app/src/components/Status/StatusValueRow.jsx @@ -4,7 +4,7 @@ import { CopyToClipboard } from 'react-copy-to-clipboard'; const StatusValueRow = (props) => { const { value } = props; - return (value) ? ( + return (value || value === 0) ? ( diff --git a/packages/concordia-app/src/components/Status/styles.css b/packages/concordia-app/src/components/Status/styles.css index abfeccd..0ce2141 100644 --- a/packages/concordia-app/src/components/Status/styles.css +++ b/packages/concordia-app/src/components/Status/styles.css @@ -2,6 +2,10 @@ border: 1px solid var(--secondary-color) !important; } +.status-header-image{ + width: 2.5rem !important; +} + .status-key { background-color: var(--secondary-color); color: white; diff --git a/packages/concordia-app/src/layouts/MainLayout/MainLayoutConcordiaStatus/index.jsx b/packages/concordia-app/src/layouts/MainLayout/MainLayoutConcordiaStatus/index.jsx new file mode 100644 index 0000000..25a327a --- /dev/null +++ b/packages/concordia-app/src/layouts/MainLayout/MainLayoutConcordiaStatus/index.jsx @@ -0,0 +1,84 @@ +import React, { useEffect, useState } from 'react'; +import { useSelector } from 'react-redux'; +import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; +import { drizzle } from '../../../redux/store'; +import StatusSegment from '../../../components/Status/StatusSegment'; +import StatusKeyRow from '../../../components/Status/StatusKeyRow'; +import StatusValueRow from '../../../components/Status/StatusValueRow'; +import appLogo from '../../../assets/images/app_logo_circle.svg'; + +const MainLayoutConcordiaStatus = () => { + const { + contracts: { + [FORUM_CONTRACT]: { + methods: { + numUsers: { cacheCall: numUsersChainData }, + numTopics: { cacheCall: numTopicsChainData }, + numPosts: { cacheCall: numPostsChainData }, + }, + }, + }, + } = drizzle; + + const [numUsers, setNumUsers] = useState(null); + const [numTopics, setNumTopics] = useState(null); + const [numPosts, setNumPosts] = useState(null); + const [numUsersCallHash, setNumUsersCallHash] = useState(null); + const [numTopicsCallHash, setNumTopicsCallHash] = useState(null); + const [numPostsCallHash, setNumPostsCallHash] = useState(null); + const numUsersResult = useSelector((state) => state.contracts[FORUM_CONTRACT].numUsers[numUsersCallHash]); + const numTopicsResult = useSelector((state) => state.contracts[FORUM_CONTRACT].numTopics[numTopicsCallHash]); + const numPostsResult = useSelector((state) => state.contracts[FORUM_CONTRACT].numPosts[numPostsCallHash]); + + useEffect(() => { + if (numUsersCallHash === null) { + setNumUsersCallHash(numUsersChainData()); + } + }, [numUsersCallHash, numUsersChainData]); + + useEffect(() => { + if (numTopicsCallHash === null) { + setNumTopicsCallHash(numTopicsChainData()); + } + }, [numTopicsCallHash, numTopicsChainData]); + + useEffect(() => { + if (numPostsCallHash === null) { + setNumPostsCallHash(numPostsChainData()); + } + }, [numPostsCallHash, numPostsChainData]); + + useEffect(() => { + if (numUsersResult) { + setNumUsers(parseInt(numUsersResult.value, 10)); + } + }, [numUsersResult]); + + useEffect(() => { + if (numTopicsResult) { + setNumTopics(parseInt(numTopicsResult.value, 10)); + } + }, [numTopicsResult]); + + useEffect(() => { + if (numPostsResult) { + setNumPosts(parseInt(numPostsResult.value, 10)); + } + }, [numPostsResult]); + + return ( + + + + + + + + + ); +}; + +export default MainLayoutConcordiaStatus; diff --git a/packages/concordia-app/src/layouts/MainLayout/index.jsx b/packages/concordia-app/src/layouts/MainLayout/index.jsx index 23d96f8..1300e3b 100644 --- a/packages/concordia-app/src/layouts/MainLayout/index.jsx +++ b/packages/concordia-app/src/layouts/MainLayout/index.jsx @@ -4,6 +4,7 @@ import { Grid } from 'semantic-ui-react'; import Particles from 'react-particles-js'; import particlesOptions from '../../assets/particles'; import MainLayoutMenu from './MainLayoutMenu'; +import MainLayoutConcordiaStatus from './MainLayoutConcordiaStatus'; import MainLayoutEthereumStatus from './MainLayoutEthereumStatus'; import MainLayoutIPFSStatus from './MainLayoutIPFSStatus'; import './styles.css'; @@ -21,6 +22,7 @@ const MainLayout = (props) => { {children} +