From 45d6e9a05226409029f1d272c3771414a16dc086 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Tue, 3 Dec 2019 15:31:32 +0700 Subject: [PATCH] fixed locked_audios --- .../node/CommentContent/styles.scss | 2 +- src/components/node/CommentForm/index.tsx | 61 +++++++++++-------- src/components/node/CommentForm/styles.scss | 3 - 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/components/node/CommentContent/styles.scss b/src/components/node/CommentContent/styles.scss index 0d807c5d..556bd770 100644 --- a/src/components/node/CommentContent/styles.scss +++ b/src/components/node/CommentContent/styles.scss @@ -88,7 +88,7 @@ .block_audio { align-items: stretch; justify-content: center; - // padding-bottom: 0 !important; + padding-bottom: 0 !important; } .block_image { diff --git a/src/components/node/CommentForm/index.tsx b/src/components/node/CommentForm/index.tsx index 14107403..9cfb433b 100644 --- a/src/components/node/CommentForm/index.tsx +++ b/src/components/node/CommentForm/index.tsx @@ -17,17 +17,14 @@ import * as UPLOAD_ACTIONS from '~/redux/uploads/actions'; import { selectUploads } from '~/redux/uploads/selectors'; import { IState } from '~/redux/store'; import { getFileType } from '~/utils/uploader'; -import { selectUser } from '~/redux/auth/selectors'; import { ButtonGroup } from '~/components/input/ButtonGroup'; import { SortableImageGrid } from '~/components/editors/SortableImageGrid'; import { moveArrItem } from '~/utils/fn'; import { SortEnd } from 'react-sortable-hoc'; import { SortableAudioGrid } from '~/components/editors/SortableAudioGrid'; -import { NodeCommentForm } from '../NodeCommentForm'; const mapStateToProps = (state: IState) => ({ node: selectNode(state), - user: selectUser(state), uploads: selectUploads(state), }); @@ -46,7 +43,6 @@ type IProps = ReturnType & const CommentFormUnconnected: FC = ({ node: { comment_data, is_sending_comment }, uploads: { statuses, files }, - user, id, is_before = false, nodePostComment, @@ -87,21 +83,6 @@ const CommentFormUnconnected: FC = ({ [nodeSetCommentData, comment_data, id] ); - const onSubmit = useCallback( - event => { - if (event) event.preventDefault(); - nodePostComment(id, is_before); - }, - [nodePostComment, id, is_before] - ); - - const onKeyDown = useCallback>( - ({ ctrlKey, key }) => { - if (!!ctrlKey && key === 'Enter') onSubmit(null); - }, - [onSubmit] - ); - useEffect(() => { const temp_ids = (comment_data && comment_data[id] && comment_data[id].temp_ids) || []; const added_files = temp_ids @@ -126,6 +107,25 @@ const CommentFormUnconnected: FC = ({ const comment = comment_data[id]; + const is_uploading_files = useMemo(() => comment.temp_ids.length > 0, [comment.temp_ids]); + + const onSubmit = useCallback( + event => { + if (event) event.preventDefault(); + if (is_uploading_files || is_sending_comment) return; + + nodePostComment(id, is_before); + }, + [nodePostComment, id, is_before, is_uploading_files, is_sending_comment] + ); + + const onKeyDown = useCallback>( + ({ ctrlKey, key }) => { + if (!!ctrlKey && key === 'Enter') onSubmit(null); + }, + [onSubmit] + ); + const images = useMemo( () => comment.files.filter(file => file && file.type === UPLOAD_TYPES.IMAGE), [comment.files] @@ -144,6 +144,14 @@ const CommentFormUnconnected: FC = ({ [comment.files] ); + const locked_audios = useMemo( + () => + comment.temp_ids + .filter(temp => statuses[temp] && statuses[temp].type === UPLOAD_TYPES.AUDIO) + .map(temp_id => statuses[temp_id]), + [statuses, comment.temp_ids] + ); + const onFileDrop = useCallback( (file_id: IFile['id']) => { nodeSetCommentData( @@ -215,13 +223,13 @@ const CommentFormUnconnected: FC = ({ /> )} - {!!audios.length && ( + {(!!audios.length || !!locked_audios.length) && ( @@ -242,10 +250,15 @@ const CommentFormUnconnected: FC = ({ - {is_sending_comment && } + {(is_sending_comment || is_uploading_files) && } - diff --git a/src/components/node/CommentForm/styles.scss b/src/components/node/CommentForm/styles.scss index 8b197ccf..910b24d5 100644 --- a/src/components/node/CommentForm/styles.scss +++ b/src/components/node/CommentForm/styles.scss @@ -35,7 +35,4 @@ .attaches { @include outer_shadow(); - - padding: $gap; - // background: darken($comment_bg, 2%); }