From 9e54b6938dda06cf85876d570d5eee411ff00ea2 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Thu, 19 Nov 2020 20:51:17 +0200 Subject: [PATCH 1/7] Fix invalid prop errors --- packages/concordia-app/src/components/PostCreate/index.jsx | 1 - .../concordia-app/src/components/PostList/PostListRow/index.jsx | 1 - packages/concordia-app/src/components/PostList/index.jsx | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/concordia-app/src/components/PostCreate/index.jsx b/packages/concordia-app/src/components/PostCreate/index.jsx index 124696c..be2ba0b 100644 --- a/packages/concordia-app/src/components/PostCreate/index.jsx +++ b/packages/concordia-app/src/components/PostCreate/index.jsx @@ -93,7 +93,6 @@ const PostCreate = (props) => { size="big" inverted color="black" - verticalAlign="middle" /> )} diff --git a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx index 0fff102..06fe0a0 100644 --- a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx +++ b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx @@ -104,7 +104,6 @@ const PostListRow = (props) => { size="big" inverted color="black" - verticalAlign="middle" /> )} diff --git a/packages/concordia-app/src/components/PostList/index.jsx b/packages/concordia-app/src/components/PostList/index.jsx index 991fc2f..2c93daf 100644 --- a/packages/concordia-app/src/components/PostList/index.jsx +++ b/packages/concordia-app/src/components/PostList/index.jsx @@ -55,7 +55,7 @@ const PostList = (props) => { }, [getPostCallHashes, loading, postIds]); return ( - + {posts} From f5fc3ffdf7368eb2af28ee26427a90cb92746322 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Thu, 19 Nov 2020 21:32:02 +0200 Subject: [PATCH 2/7] Add contract and orbit interactions on posting --- .../src/components/PostCreate/index.jsx | 67 ++++++++++++++++--- .../components/PostList/PostListRow/index.jsx | 9 ++- .../src/components/PostList/index.jsx | 3 +- .../src/views/Topic/TopicView/index.jsx | 3 +- 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/packages/concordia-app/src/components/PostCreate/index.jsx b/packages/concordia-app/src/components/PostCreate/index.jsx index be2ba0b..aadf71d 100644 --- a/packages/concordia-app/src/components/PostCreate/index.jsx +++ b/packages/concordia-app/src/components/PostCreate/index.jsx @@ -8,19 +8,29 @@ import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import determineKVAddress from '../../utils/orbitUtils'; -import { USER_DATABASE } from '../../constants/OrbitDatabases'; +import { POSTS_DATABASE, USER_DATABASE } from '../../constants/OrbitDatabases'; import { FETCH_USER_DATABASE } from '../../redux/actions/peerDbReplicationActions'; import { USER_PROFILE_PICTURE } from '../../constants/UserDatabaseKeys'; -import { breeze } from '../../redux/store'; +import { breeze, drizzle } from '../../redux/store'; import './styles.css'; +import { TRANSACTION_ERROR, TRANSACTION_SUCCESS } from '../../constants/TransactionStatus'; +import { POST_CONTENT, POST_SUBJECT } from '../../constants/PostsDatabaseKeys'; +const { contracts: { Forum: { methods: { createPost } } } } = drizzle; const { orbit } = breeze; const PostCreate = (props) => { - const { id: postId, initialPostSubject } = props; + const { + topicId, postIndexInTopic, initialPostSubject, account, + } = props; + const transactionStack = useSelector((state) => state.transactionStack); + const transactions = useSelector((state) => state.transactions); const [postSubject, setPostSubject] = useState(initialPostSubject); const [postContent, setPostContent] = useState(''); const [userProfilePictureUrl, setUserProfilePictureUrl] = useState(); + const [postSubjectInputEmptySubmit, setPostSubjectInputEmptySubmit] = useState(false); + const [postContentInputEmptySubmit, setPostContentInputEmptySubmit] = useState(false); + const [createPostCacheSendStackId, setCreatePostCacheSendStackId] = useState(''); const [posting, setPosting] = useState(false); const userAddress = useSelector((state) => state.user.address); const users = useSelector((state) => state.orbitData.users); @@ -68,13 +78,49 @@ const PostCreate = (props) => { } }, [posting]); + useEffect(() => { + if (posting && transactionStack && transactionStack[createPostCacheSendStackId] + && transactions[transactionStack[createPostCacheSendStackId]]) { + if (transactions[transactionStack[createPostCacheSendStackId]].status === TRANSACTION_ERROR) { + setPosting(false); + } else if (transactions[transactionStack[createPostCacheSendStackId]].status === TRANSACTION_SUCCESS) { + const { + receipt: { events: { PostCreated: { returnValues: { postID: contractPostId } } } }, + } = transactions[transactionStack[createPostCacheSendStackId]]; + + const { stores } = orbit; + const postsDb = Object.values(stores).find((store) => store.dbname === POSTS_DATABASE); + + postsDb + .put(contractPostId, { + [POST_SUBJECT]: postSubject, + [POST_CONTENT]: postContent, + }, { pin: true }) + .then(() => { + setPostSubject(initialPostSubject); + setPostContent(''); + }) + .catch((reason) => { + console.log(reason); + }); + } + } + }, [createPostCacheSendStackId, postContent, postSubject, posting, transactionStack, transactions]); + const savePost = useCallback(() => { - if (postSubject === '' || postContent === '') { + if (postSubject === '') { + setPostSubjectInputEmptySubmit(true); + return; + } + + if (postContent === '') { + setPostContentInputEmptySubmit(true); return; } setPosting(true); - }, [postContent, postSubject]); + setCreatePostCacheSendStackId(createPost.cacheSend(...[topicId], { from: account })); + }, [account, postContent, postSubject, topicId]); return ( @@ -104,11 +150,12 @@ const PostCreate = (props) => { name="postSubject" className="subject-input" size="mini" + error={postSubjectInputEmptySubmit} value={postSubject} onChange={handleInputChange} /> - {t('post.list.row.post.id', { id: postId })} + {t('post.list.row.post.id', { id: postIndexInTopic })} @@ -120,6 +167,7 @@ const PostCreate = (props) => { className="content-input" size="mini" rows={4} + error={postContentInputEmptySubmit} value={postContent} onChange={handleInputChange} /> @@ -132,8 +180,8 @@ const PostCreate = (props) => { animated type="button" color="green" - disabled={posting} - onClick={savePost || postSubject === '' || postContent === ''} + disabled={posting || postSubject === '' || postContent === ''} + onClick={savePost} > {t('post.create.form.send.button')} @@ -151,7 +199,8 @@ const PostCreate = (props) => { }; PostCreate.propTypes = { - id: PropTypes.number.isRequired, + topicId: PropTypes.number.isRequired, + postIndexInTopic: PropTypes.number.isRequired, initialPostSubject: PropTypes.string.isRequired, }; diff --git a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx index 06fe0a0..1b7e666 100644 --- a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx +++ b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx @@ -20,7 +20,9 @@ import { POST_CONTENT, POST_SUBJECT } from '../../../constants/PostsDatabaseKeys const { orbit } = breeze; const PostListRow = (props) => { - const { id: postId, postCallHash, loading } = props; + const { + id: postId, postIndexInTopic, postCallHash, loading, + } = props; const getPostResults = useSelector((state) => state.contracts.Forum.getPost); const [postAuthorAddress, setPostAuthorAddress] = useState(null); const [postAuthor, setPostAuthor] = useState(null); @@ -114,7 +116,7 @@ const PostListRow = (props) => { ? postSubject : } - {t('post.list.row.post.id', { id: postId })} + {t('post.list.row.post.id', { id: postIndexInTopic })} {postAuthor !== null && timeAgo !== null @@ -133,7 +135,7 @@ const PostListRow = (props) => { - ), [loading, postAuthor, postAuthorMeta, postId, postContent, postSubject, t, timeAgo]); + ), [loading, postAuthor, postAuthorMeta, postContent, postIndexInTopic, postSubject, t, timeAgo]); }; PostListRow.defaultProps = { @@ -142,6 +144,7 @@ PostListRow.defaultProps = { PostListRow.propTypes = { id: PropTypes.number.isRequired, + postIndexInTopic: PropTypes.number.isRequired, postCallHash: PropTypes.string, loading: PropTypes.bool, }; diff --git a/packages/concordia-app/src/components/PostList/index.jsx b/packages/concordia-app/src/components/PostList/index.jsx index 2c93daf..c4fe149 100644 --- a/packages/concordia-app/src/components/PostList/index.jsx +++ b/packages/concordia-app/src/components/PostList/index.jsx @@ -40,12 +40,13 @@ const PostList = (props) => { return null; } return postIds - .map((postId) => { + .map((postId, index) => { const postHash = getPostCallHashes.find((getPostCallHash) => getPostCallHash.id === postId); return ( { {topicSubject !== null && postIds !== null && ( )} From 13d3b27e3ac7f0128464c9c1941dd14f7590f32f Mon Sep 17 00:00:00 2001 From: Apostolof Date: Thu, 19 Nov 2020 21:35:30 +0200 Subject: [PATCH 3/7] Fix old users unchanged filter --- packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js b/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js index cd54388..5e30042 100644 --- a/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js +++ b/packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js @@ -31,7 +31,7 @@ function* updateReduxState({ database }) { if (database.dbname === USER_DATABASE) { const oldUsersUnchanged = users - .filter((user) => !database.id !== user.id); + .filter((user) => database.id !== user.id); yield put({ type: UPDATE_ORBIT_DATA, From af9ec235aff919da77b103599303bc5ae576f825 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Thu, 19 Nov 2020 22:11:07 +0200 Subject: [PATCH 4/7] Add links to user profiles --- .../components/PostList/PostListRow/index.jsx | 51 +++++++++++------ .../TopicList/TopicListRow/index.jsx | 55 +++++++++++++------ .../src/views/Topic/TopicView/index.jsx | 48 +++++++++------- 3 files changed, 97 insertions(+), 57 deletions(-) diff --git a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx index 1b7e666..06b5bdb 100644 --- a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx +++ b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx @@ -9,6 +9,7 @@ import { useTranslation } from 'react-i18next'; import moment from 'moment'; import { useHistory } from 'react-router'; import { useDispatch, useSelector } from 'react-redux'; +import { Link } from 'react-router-dom'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import { breeze } from '../../../redux/store'; import './styles.css'; @@ -90,24 +91,38 @@ const PostListRow = (props) => { } }, [postAuthorAddress, users]); + const authorAvatar = useMemo(() => (postAuthorMeta !== null && postAuthorMeta[USER_PROFILE_PICTURE] + ? ( + + ) + : ( + + )), [postAuthorMeta]); + + const authorAvatarLink = useMemo(() => { + if (postAuthorAddress) { + return ( + + {authorAvatar} + + ); + } + + return authorAvatar; + }, [authorAvatar, postAuthorAddress]); + return useMemo(() => ( - {postAuthorMeta !== null && postAuthorMeta[USER_PROFILE_PICTURE] - ? ( - - ) - : ( - - )} + {authorAvatarLink} @@ -119,12 +134,12 @@ const PostListRow = (props) => { {t('post.list.row.post.id', { id: postIndexInTopic })} - {postAuthor !== null && timeAgo !== null + {postAuthor !== null && setPostAuthorAddress !== null && timeAgo !== null ? ( <> {t('post.list.row.author.pre')}   - {postAuthor} + {postAuthor} {timeAgo} ) @@ -135,7 +150,7 @@ const PostListRow = (props) => { - ), [loading, postAuthor, postAuthorMeta, postContent, postIndexInTopic, postSubject, t, timeAgo]); + ), [authorAvatarLink, loading, postAuthor, postContent, postIndexInTopic, postSubject, t, timeAgo]); }; PostListRow.defaultProps = { diff --git a/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx b/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx index 4e6196d..f77cd59 100644 --- a/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx +++ b/packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx @@ -9,6 +9,7 @@ import { useTranslation } from 'react-i18next'; import moment from 'moment'; import { useHistory } from 'react-router'; import { useDispatch, useSelector } from 'react-redux'; +import { Link } from 'react-router-dom'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import { breeze } from '../../../redux/store'; import './styles.css'; @@ -88,6 +89,40 @@ const TopicListRow = (props) => { } }, [topicAuthorAddress, users]); + const stopClickPropagation = (event) => { + event.stopPropagation(); + }; + + const authorAvatar = useMemo(() => (topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE] + ? ( + + ) + : ( + + )), [topicAuthorMeta]); + + const authorAvatarLink = useMemo(() => { + if (topicAuthorAddress) { + return ( + + {authorAvatar} + + ); + } + + return authorAvatar; + }, [authorAvatar, topicAuthorAddress]); + return useMemo(() => { const handleTopicClick = () => { history.push(`/topics/${topicId}`); @@ -95,23 +130,7 @@ const TopicListRow = (props) => { return ( - {topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE] - ? ( - - ) - : ( - - )} + {authorAvatarLink} @@ -148,7 +167,7 @@ const TopicListRow = (props) => { ); - }, [history, loading, numberOfReplies, t, timeAgo, topicAuthor, topicAuthorMeta, topicId, topicSubject]); + }, [authorAvatarLink, history, loading, numberOfReplies, t, timeAgo, topicAuthor, topicId, topicSubject]); }; TopicListRow.defaultProps = { diff --git a/packages/concordia-app/src/views/Topic/TopicView/index.jsx b/packages/concordia-app/src/views/Topic/TopicView/index.jsx index eb22308..9f4ddb3 100644 --- a/packages/concordia-app/src/views/Topic/TopicView/index.jsx +++ b/packages/concordia-app/src/views/Topic/TopicView/index.jsx @@ -5,6 +5,8 @@ import { Container, Dimmer, Icon, Image, Placeholder, Step, } from 'semantic-ui-react'; import moment from 'moment'; +import { useHistory } from 'react-router'; +import { Link } from 'react-router-dom'; import { breeze, drizzle } from '../../../redux/store'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import './styles.css'; @@ -36,7 +38,7 @@ const TopicView = (props) => { const [timestamp, setTimestamp] = useState(initialTimestamp || null); const [postIds, setPostIds] = useState(initialPostIds || null); const [topicSubject, setTopicSubject] = useState(null); - + const history = useHistory(); const dispatch = useDispatch(); useEffect(() => { @@ -114,28 +116,32 @@ const TopicView = (props) => { > - {topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE] - ? ( - - ) - : ( - - )} + + {topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE] + ? ( + + ) + : ( + + )} + - {topicAuthor || ( - - - - )} + + {topicAuthor || ( + + + + )} + From 26707baf1d1e34c4f0a06cdd581fb74977afd017 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Thu, 19 Nov 2020 22:17:12 +0200 Subject: [PATCH 5/7] Fix lint issues --- packages/concordia-app/src/components/PostCreate/index.jsx | 4 +++- .../src/components/PostList/PostListRow/index.jsx | 6 +++--- packages/concordia-app/src/options/web3Options.js | 4 +++- packages/concordia-app/src/views/Topic/TopicView/index.jsx | 2 -- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/concordia-app/src/components/PostCreate/index.jsx b/packages/concordia-app/src/components/PostCreate/index.jsx index aadf71d..b84217b 100644 --- a/packages/concordia-app/src/components/PostCreate/index.jsx +++ b/packages/concordia-app/src/components/PostCreate/index.jsx @@ -105,7 +105,9 @@ const PostCreate = (props) => { }); } } - }, [createPostCacheSendStackId, postContent, postSubject, posting, transactionStack, transactions]); + }, [ + createPostCacheSendStackId, initialPostSubject, postContent, postSubject, posting, transactionStack, transactions, + ]); const savePost = useCallback(() => { if (postSubject === '') { diff --git a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx index 06b5bdb..4549dc7 100644 --- a/packages/concordia-app/src/components/PostList/PostListRow/index.jsx +++ b/packages/concordia-app/src/components/PostList/PostListRow/index.jsx @@ -7,7 +7,6 @@ import { import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; import moment from 'moment'; -import { useHistory } from 'react-router'; import { useDispatch, useSelector } from 'react-redux'; import { Link } from 'react-router-dom'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; @@ -35,7 +34,6 @@ const PostListRow = (props) => { const posts = useSelector((state) => state.orbitData.posts); const users = useSelector((state) => state.orbitData.users); const dispatch = useDispatch(); - const history = useHistory(); const { t } = useTranslation(); useEffect(() => { @@ -150,7 +148,9 @@ const PostListRow = (props) => { - ), [authorAvatarLink, loading, postAuthor, postContent, postIndexInTopic, postSubject, t, timeAgo]); + ), [ + authorAvatarLink, loading, postAuthor, postAuthorAddress, postContent, postIndexInTopic, postSubject, t, timeAgo, + ]); }; PostListRow.defaultProps = { diff --git a/packages/concordia-app/src/options/web3Options.js b/packages/concordia-app/src/options/web3Options.js index 49d20fa..1957de8 100644 --- a/packages/concordia-app/src/options/web3Options.js +++ b/packages/concordia-app/src/options/web3Options.js @@ -3,7 +3,9 @@ import Web3 from 'web3'; const { WEB3_URL, WEB3_PORT } = process.env; // We need fallback ws://127.0.0.1:8545 because drizzle has not the patched web3 we use here -const web3 = (WEB3_URL && WEB3_PORT) ? `ws://${WEB3_URL}:${WEB3_PORT}` : new Web3(Web3.givenProvider || new Web3.providers.WebsocketProvider('ws://127.0.0.1:8545')); +const web3 = (WEB3_URL && WEB3_PORT) + ? `ws://${WEB3_URL}:${WEB3_PORT}` + : new Web3(Web3.givenProvider || new Web3.providers.WebsocketProvider('ws://127.0.0.1:8545')); const web3Options = { web3, diff --git a/packages/concordia-app/src/views/Topic/TopicView/index.jsx b/packages/concordia-app/src/views/Topic/TopicView/index.jsx index 9f4ddb3..885fb82 100644 --- a/packages/concordia-app/src/views/Topic/TopicView/index.jsx +++ b/packages/concordia-app/src/views/Topic/TopicView/index.jsx @@ -5,7 +5,6 @@ import { Container, Dimmer, Icon, Image, Placeholder, Step, } from 'semantic-ui-react'; import moment from 'moment'; -import { useHistory } from 'react-router'; import { Link } from 'react-router-dom'; import { breeze, drizzle } from '../../../redux/store'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; @@ -38,7 +37,6 @@ const TopicView = (props) => { const [timestamp, setTimestamp] = useState(initialTimestamp || null); const [postIds, setPostIds] = useState(initialPostIds || null); const [topicSubject, setTopicSubject] = useState(null); - const history = useHistory(); const dispatch = useDispatch(); useEffect(() => { From 4e372974c4f51244f904d61fcb109d9d50a656ed Mon Sep 17 00:00:00 2001 From: Apostolof Date: Thu, 19 Nov 2020 22:28:16 +0200 Subject: [PATCH 6/7] Redirect to home on invalid topic url --- .../concordia-app/src/views/Topic/TopicView/index.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/concordia-app/src/views/Topic/TopicView/index.jsx b/packages/concordia-app/src/views/Topic/TopicView/index.jsx index 885fb82..79a6109 100644 --- a/packages/concordia-app/src/views/Topic/TopicView/index.jsx +++ b/packages/concordia-app/src/views/Topic/TopicView/index.jsx @@ -6,6 +6,7 @@ import { } from 'semantic-ui-react'; import moment from 'moment'; import { Link } from 'react-router-dom'; +import { useHistory } from 'react-router'; import { breeze, drizzle } from '../../../redux/store'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import './styles.css'; @@ -37,6 +38,7 @@ const TopicView = (props) => { const [timestamp, setTimestamp] = useState(initialTimestamp || null); const [postIds, setPostIds] = useState(initialPostIds || null); const [topicSubject, setTopicSubject] = useState(null); + const history = useHistory(); const dispatch = useDispatch(); useEffect(() => { @@ -54,6 +56,11 @@ const TopicView = (props) => { useEffect(() => { if (getTopicCallHash && getTopicResults && getTopicResults[getTopicCallHash]) { + if (getTopicResults[getTopicCallHash].value == null) { + history.push('/'); + return; + } + setTopicAuthorAddress(getTopicResults[getTopicCallHash].value[0]); setTopicAuthor(getTopicResults[getTopicCallHash].value[1]); setTimestamp(getTopicResults[getTopicCallHash].value[2]); @@ -71,7 +78,7 @@ const TopicView = (props) => { }); } } - }, [dispatch, getTopicCallHash, getTopicResults, topicId, topics, userAddress]); + }, [dispatch, getTopicCallHash, getTopicResults, history, topicId, topics, userAddress]); useEffect(() => { if (topicAuthorAddress !== null) { From 8d5d4f738ac5d793591eea1372f7deeec97eb94f Mon Sep 17 00:00:00 2001 From: Apostolof Date: Thu, 19 Nov 2020 22:46:54 +0200 Subject: [PATCH 7/7] Fix post storing to orbit --- .../src/components/PostCreate/index.jsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/concordia-app/src/components/PostCreate/index.jsx b/packages/concordia-app/src/components/PostCreate/index.jsx index b84217b..0047247 100644 --- a/packages/concordia-app/src/components/PostCreate/index.jsx +++ b/packages/concordia-app/src/components/PostCreate/index.jsx @@ -32,6 +32,7 @@ const PostCreate = (props) => { const [postContentInputEmptySubmit, setPostContentInputEmptySubmit] = useState(false); const [createPostCacheSendStackId, setCreatePostCacheSendStackId] = useState(''); const [posting, setPosting] = useState(false); + const [storingPost, setStoringPost] = useState(false); const userAddress = useSelector((state) => state.user.address); const users = useSelector((state) => state.orbitData.users); const dispatch = useDispatch(); @@ -79,7 +80,7 @@ const PostCreate = (props) => { }, [posting]); useEffect(() => { - if (posting && transactionStack && transactionStack[createPostCacheSendStackId] + if (posting && !storingPost && transactionStack && transactionStack[createPostCacheSendStackId] && transactions[transactionStack[createPostCacheSendStackId]]) { if (transactions[transactionStack[createPostCacheSendStackId]].status === TRANSACTION_ERROR) { setPosting(false); @@ -99,14 +100,21 @@ const PostCreate = (props) => { .then(() => { setPostSubject(initialPostSubject); setPostContent(''); + setPosting(false); + setPostSubjectInputEmptySubmit(false); + setPostContentInputEmptySubmit(false); + setCreatePostCacheSendStackId(''); }) .catch((reason) => { console.log(reason); }); + + setStoringPost(true); } } }, [ - createPostCacheSendStackId, initialPostSubject, postContent, postSubject, posting, transactionStack, transactions, + createPostCacheSendStackId, initialPostSubject, postContent, postSubject, posting, storingPost, transactionStack, + transactions, ]); const savePost = useCallback(() => {