diff --git a/src/components/node/CommentForm/index.tsx b/src/components/node/CommentForm/index.tsx index b0a78080..833da807 100644 --- a/src/components/node/CommentForm/index.tsx +++ b/src/components/node/CommentForm/index.tsx @@ -1,18 +1,20 @@ -import React, { FC, useCallback, useState } from 'react'; +import React, { FC, useCallback, useEffect } from 'react'; import { Textarea } from '~/components/input/Textarea'; import { CommentWrapper } from '~/components/containers/CommentWrapper'; import * as styles from './styles.scss'; import { Filler } from '~/components/containers/Filler'; import { Button } from '~/components/input/Button'; import assocPath from 'ramda/es/assocPath'; -import { InputHandler, INode, IComment } from '~/redux/types'; +import { InputHandler, INode } from '~/redux/types'; import { connect } from 'react-redux'; import * as NODE_ACTIONS from '~/redux/node/actions'; -import { EMPTY_COMMENT } from '~/redux/node/constants'; +import { store } from '~/redux/store'; +import { selectNode } from '~/redux/node/selectors'; -const mapStateToProps = () => ({}); +const mapStateToProps = selectNode; const mapDispatchToProps = { nodePostComment: NODE_ACTIONS.nodePostComment, + nodeSetCommentData: NODE_ACTIONS.nodeSetCommentData, }; type IProps = ReturnType & @@ -20,29 +22,38 @@ type IProps = ReturnType & id: INode['id']; }; -const CommentFormUnconnected: FC = ({ nodePostComment, id }) => { - const [data, setData] = useState({ ...EMPTY_COMMENT }); +const CommentFormUnconnected: FC = ({ + nodePostComment, + nodeSetCommentData, + comment_data, + id, +}) => { + // const [data, setData] = useState({ ...EMPTY_COMMENT }); const onInput = useCallback( text => { - setData(assocPath(['text'], text, data)); + nodeSetCommentData(assocPath(['text'], text, comment_data)); }, - [setData, data] + [nodeSetCommentData, comment_data] ); const onSubmit = useCallback( event => { event.preventDefault(); - nodePostComment(data, id); + nodePostComment(); }, - [data, nodePostComment, id] + [nodePostComment] ); + useEffect(() => { + store.subscribe(console.log); + }, []); + return (
-