From b5bc901479fd95eb565e4f7e07031ef698d0d030 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Thu, 25 Feb 2021 21:08:42 +0200 Subject: [PATCH] Refactoring --- .../Pagination/PaginatedTopicList/styles.css | 4 -- .../index.jsx => PaginationComponent.jsx} | 0 .../src/components/PostList/index.jsx | 23 ++----- .../src/components/TopicList/index.jsx | 14 ++-- .../src/views/Home/Board/index.jsx | 67 ------------------- .../src/views/Home/Board/styles.css | 15 ----- .../Home/HomeTopicList}/index.jsx | 31 +++++---- .../concordia-app/src/views/Home/index.jsx | 55 +++++++++++++-- .../concordia-app/src/views/Home/styles.css | 18 ++++- .../concordia-contracts/contracts/Forum.sol | 31 ++++++++- 10 files changed, 132 insertions(+), 126 deletions(-) delete mode 100644 packages/concordia-app/src/components/Pagination/PaginatedTopicList/styles.css rename packages/concordia-app/src/components/{Pagination/index.jsx => PaginationComponent.jsx} (100%) delete mode 100644 packages/concordia-app/src/views/Home/Board/index.jsx delete mode 100644 packages/concordia-app/src/views/Home/Board/styles.css rename packages/concordia-app/src/{components/Pagination/PaginatedTopicList => views/Home/HomeTopicList}/index.jsx (72%) diff --git a/packages/concordia-app/src/components/Pagination/PaginatedTopicList/styles.css b/packages/concordia-app/src/components/Pagination/PaginatedTopicList/styles.css deleted file mode 100644 index 6bbac7b..0000000 --- a/packages/concordia-app/src/components/Pagination/PaginatedTopicList/styles.css +++ /dev/null @@ -1,4 +0,0 @@ -#topic-list{ - height: auto; - clear: both; -} diff --git a/packages/concordia-app/src/components/Pagination/index.jsx b/packages/concordia-app/src/components/PaginationComponent.jsx similarity index 100% rename from packages/concordia-app/src/components/Pagination/index.jsx rename to packages/concordia-app/src/components/PaginationComponent.jsx diff --git a/packages/concordia-app/src/components/PostList/index.jsx b/packages/concordia-app/src/components/PostList/index.jsx index e2ca121..064d5a0 100644 --- a/packages/concordia-app/src/components/PostList/index.jsx +++ b/packages/concordia-app/src/components/PostList/index.jsx @@ -20,23 +20,14 @@ const PostList = (props) => { useEffect(() => { if (drizzleInitialized && !drizzleInitializationFailed && !loading) { - const newPostsFound = postIds - .filter((postId) => !getPostCallHashes - .map((getPostCallHash) => getPostCallHash.id) - .includes(postId)); - - if (newPostsFound.length > 0) { - setGetPostCallHashes([ - ...getPostCallHashes, - ...newPostsFound - .map((postId) => ({ - id: postId, - hash: getPostChainData(postId), - })), - ]); - } + setGetPostCallHashes( + postIds.map((postId) => ({ + id: postId, + hash: getPostChainData(postId), + })), + ); } - }, [drizzleInitializationFailed, drizzleInitialized, getPostCallHashes, loading, postIds]); + }, [drizzleInitializationFailed, drizzleInitialized, loading, postIds]); const posts = useMemo(() => { if (loading) { diff --git a/packages/concordia-app/src/components/TopicList/index.jsx b/packages/concordia-app/src/components/TopicList/index.jsx index 2941848..8ebde2a 100644 --- a/packages/concordia-app/src/components/TopicList/index.jsx +++ b/packages/concordia-app/src/components/TopicList/index.jsx @@ -6,13 +6,14 @@ import { useSelector } from 'react-redux'; import { List } from 'semantic-ui-react'; import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames'; import TopicListRow from './TopicListRow'; +import PaginationComponent from '../PaginationComponent'; import { drizzle } from '../../redux/store'; import './styles.css'; const { contracts: { [FORUM_CONTRACT]: { methods: { getTopic: { cacheCall: getTopicChainData } } } } } = drizzle; const TopicList = (props) => { - const { topicIds } = props; + const { topicIds, numberOfItems, onPageChange } = props; const [getTopicCallHashes, setGetTopicCallHashes] = useState([]); const drizzleInitialized = useSelector((state) => state.drizzleStatus.initialized); const drizzleInitializationFailed = useSelector((state) => state.drizzleStatus.failed); @@ -44,14 +45,19 @@ const TopicList = (props) => { }), [getTopicCallHashes, topicIds]); return ( - - {topics} - +
+ + {topics} + + +
); }; TopicList.propTypes = { topicIds: PropTypes.arrayOf(PropTypes.number).isRequired, + numberOfItems: PropTypes.number.isRequired, + onPageChange: PropTypes.func, }; export default TopicList; diff --git a/packages/concordia-app/src/views/Home/Board/index.jsx b/packages/concordia-app/src/views/Home/Board/index.jsx deleted file mode 100644 index 618ea7f..0000000 --- a/packages/concordia-app/src/views/Home/Board/index.jsx +++ /dev/null @@ -1,67 +0,0 @@ -import React, { useMemo } from 'react'; -import { Button, Header } from 'semantic-ui-react'; -import { useSelector } from 'react-redux'; -import { useHistory } from 'react-router'; -import { useTranslation } from 'react-i18next'; -import PropTypes from 'prop-types'; -import PaginatedTopicList from '../../../components/Pagination/PaginatedTopicList'; -import './styles.css'; - -const Board = (props) => { - const { numberOfTopics } = props; - const hasSignedUp = useSelector((state) => state.user.hasSignedUp); - const history = useHistory(); - const { t } = useTranslation(); - - const boardContents = useMemo(() => ( - <> - {hasSignedUp - ? ( -