From 1990783fa3cfc81474bce9422d05da59ffc7dd9c Mon Sep 17 00:00:00 2001 From: muerwre Date: Tue, 27 Aug 2019 21:33:46 +0700 Subject: [PATCH] comment form --- src/components/input/Button/styles.scss | 5 +++ src/components/input/Textarea/index.tsx | 8 +++- src/components/node/CommentForm/index.tsx | 46 ++++++++++++++------- src/components/node/CommentForm/styles.scss | 4 ++ src/containers/node/NodeLayout/index.tsx | 2 +- src/redux/node/actions.ts | 8 ++-- src/redux/node/handlers.ts | 4 +- src/redux/node/reducer.ts | 4 +- src/redux/node/sagas.ts | 19 +++++---- 9 files changed, 67 insertions(+), 33 deletions(-) diff --git a/src/components/input/Button/styles.scss b/src/components/input/Button/styles.scss index 7a850656..92c811b5 100644 --- a/src/components/input/Button/styles.scss +++ b/src/components/input/Button/styles.scss @@ -42,6 +42,11 @@ flex: 1; } + &:global(.disabled) { + touch-action: none; + pointer-events: none; + } + &:hover { opacity: 1; diff --git a/src/components/input/Textarea/index.tsx b/src/components/input/Textarea/index.tsx index 92d2aac3..06539651 100644 --- a/src/components/input/Textarea/index.tsx +++ b/src/components/input/Textarea/index.tsx @@ -6,6 +6,8 @@ import React, { useLayoutEffect, useRef, useState, + HTMLAttributes, + TextareaHTMLAttributes, } from 'react'; import { getStyle } from '~/utils/dom'; import classNames from 'classnames'; @@ -13,7 +15,7 @@ import classNames from 'classnames'; import * as styles from '~/styles/inputs.scss'; import { Icon } from '../Icon'; -interface IProps { +type IProps = TextareaHTMLAttributes & { value: string; placeholder?: string; rows?: number; @@ -24,7 +26,7 @@ interface IProps { required?: boolean; status?: 'error' | 'success' | ''; title?: string; -} +}; const Textarea = memo( ({ @@ -37,6 +39,7 @@ const Textarea = memo( required = false, title = '', status = '', + ...props }) => { const [rows, setRows] = useState(minRows || 1); const [focused, setFocused] = useState(false); @@ -99,6 +102,7 @@ const Textarea = memo( ref={textarea} onFocus={onFocus} onBlur={onBlur} + {...props} /> diff --git a/src/components/node/CommentForm/index.tsx b/src/components/node/CommentForm/index.tsx index 833da807..9fea3d83 100644 --- a/src/components/node/CommentForm/index.tsx +++ b/src/components/node/CommentForm/index.tsx @@ -1,4 +1,4 @@ -import React, { FC, useCallback, useEffect } from 'react'; +import React, { FC, useCallback, KeyboardEventHandler } from 'react'; import { Textarea } from '~/components/input/Textarea'; import { CommentWrapper } from '~/components/containers/CommentWrapper'; import * as styles from './styles.scss'; @@ -8,8 +8,9 @@ import assocPath from 'ramda/es/assocPath'; import { InputHandler, INode } from '~/redux/types'; import { connect } from 'react-redux'; import * as NODE_ACTIONS from '~/redux/node/actions'; -import { store } from '~/redux/store'; import { selectNode } from '~/redux/node/selectors'; +import { LoaderCircle } from '~/components/input/LoaderCircle'; +import { Group } from '~/components/containers/Group'; const mapStateToProps = selectNode; const mapDispatchToProps = { @@ -19,48 +20,63 @@ const mapDispatchToProps = { type IProps = ReturnType & typeof mapDispatchToProps & { - id: INode['id']; + id: number; }; const CommentFormUnconnected: FC = ({ nodePostComment, nodeSetCommentData, comment_data, + is_sending_comment, id, }) => { // const [data, setData] = useState({ ...EMPTY_COMMENT }); const onInput = useCallback( text => { - nodeSetCommentData(assocPath(['text'], text, comment_data)); + nodeSetCommentData(id, assocPath(['text'], text, comment_data[id])); }, - [nodeSetCommentData, comment_data] + [nodeSetCommentData, comment_data, id] ); const onSubmit = useCallback( event => { - event.preventDefault(); - nodePostComment(); + if (event) event.preventDefault(); + nodePostComment(id); }, - [nodePostComment] + [nodePostComment, id] ); - useEffect(() => { - store.subscribe(console.log); - }, []); + const onKeyDown = useCallback>( + ({ ctrlKey, key }) => { + if (!!ctrlKey && key === 'Enter') onSubmit(null); + }, + [onSubmit] + ); + + const comment = comment_data[id]; return (
-