From ad0dff510d515a1558799c28d978df782373175b Mon Sep 17 00:00:00 2001 From: Apostolof Date: Fri, 6 Nov 2020 22:07:07 +0200 Subject: [PATCH] Put subject and message to orbit after topic creation --- .../src/views/Topic/TopicCreate/index.jsx | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx b/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx index 70e2c9a..4640651 100644 --- a/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx +++ b/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx @@ -21,9 +21,13 @@ const TopicCreate = (props) => { }, }, }, + breeze: { + orbit: { + stores, + }, + }, } = useContext(AppContext.Context); - const orbit = useSelector((state) => state.orbit); const transactionStack = useSelector((state) => state.transactionStack); const transactions = useSelector((state) => state.transactions); @@ -73,23 +77,26 @@ const TopicCreate = (props) => { }, } = transactions[transactionStack[createTopicCacheSendStackId]]; - // Promise.all( - // orbit.topicsDB - // .put(topicId, { subject: subjectInput }), - // orbit.postsDB - // .put(postId, { - // subject: subjectInput, - // content: messageInput, - // }), - // ).then((value) => { - // console.log(value); - // history.push('/'); - // }) - // .catch((reason) => console.log(reason)); + const topicsDb = Object.values(stores).find((store) => store.dbname === 'topics'); + const postsDb = Object.values(stores).find((store) => store.dbname === 'posts'); + + topicsDb + .put(topicId, { subject: subjectInput }) + .then(() => postsDb + .put(postId, { + subject: subjectInput, + content: messageInput, + })) + .then(() => { + history.push(`/topics/${topicId}`); + }) + .catch((reason) => { + console.log(reason); + }); } } }, [ - transactions, transactionStack, history, posting, createTopicCacheSendStackId, orbit, subjectInput, messageInput, + transactions, transactionStack, history, posting, createTopicCacheSendStackId, subjectInput, messageInput, stores, ]); const validateAndPost = useCallback(() => {