1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

fixed locked_audios

This commit is contained in:
Fedor Katurov 2019-12-03 15:31:32 +07:00
parent 11ec71766f
commit 45d6e9a052
3 changed files with 38 additions and 28 deletions

View file

@ -88,7 +88,7 @@
.block_audio { .block_audio {
align-items: stretch; align-items: stretch;
justify-content: center; justify-content: center;
// padding-bottom: 0 !important; padding-bottom: 0 !important;
} }
.block_image { .block_image {

View file

@ -17,17 +17,14 @@ import * as UPLOAD_ACTIONS from '~/redux/uploads/actions';
import { selectUploads } from '~/redux/uploads/selectors'; import { selectUploads } from '~/redux/uploads/selectors';
import { IState } from '~/redux/store'; import { IState } from '~/redux/store';
import { getFileType } from '~/utils/uploader'; import { getFileType } from '~/utils/uploader';
import { selectUser } from '~/redux/auth/selectors';
import { ButtonGroup } from '~/components/input/ButtonGroup'; import { ButtonGroup } from '~/components/input/ButtonGroup';
import { SortableImageGrid } from '~/components/editors/SortableImageGrid'; import { SortableImageGrid } from '~/components/editors/SortableImageGrid';
import { moveArrItem } from '~/utils/fn'; import { moveArrItem } from '~/utils/fn';
import { SortEnd } from 'react-sortable-hoc'; import { SortEnd } from 'react-sortable-hoc';
import { SortableAudioGrid } from '~/components/editors/SortableAudioGrid'; import { SortableAudioGrid } from '~/components/editors/SortableAudioGrid';
import { NodeCommentForm } from '../NodeCommentForm';
const mapStateToProps = (state: IState) => ({ const mapStateToProps = (state: IState) => ({
node: selectNode(state), node: selectNode(state),
user: selectUser(state),
uploads: selectUploads(state), uploads: selectUploads(state),
}); });
@ -46,7 +43,6 @@ type IProps = ReturnType<typeof mapStateToProps> &
const CommentFormUnconnected: FC<IProps> = ({ const CommentFormUnconnected: FC<IProps> = ({
node: { comment_data, is_sending_comment }, node: { comment_data, is_sending_comment },
uploads: { statuses, files }, uploads: { statuses, files },
user,
id, id,
is_before = false, is_before = false,
nodePostComment, nodePostComment,
@ -87,21 +83,6 @@ const CommentFormUnconnected: FC<IProps> = ({
[nodeSetCommentData, comment_data, id] [nodeSetCommentData, comment_data, id]
); );
const onSubmit = useCallback(
event => {
if (event) event.preventDefault();
nodePostComment(id, is_before);
},
[nodePostComment, id, is_before]
);
const onKeyDown = useCallback<KeyboardEventHandler<HTMLTextAreaElement>>(
({ ctrlKey, key }) => {
if (!!ctrlKey && key === 'Enter') onSubmit(null);
},
[onSubmit]
);
useEffect(() => { useEffect(() => {
const temp_ids = (comment_data && comment_data[id] && comment_data[id].temp_ids) || []; const temp_ids = (comment_data && comment_data[id] && comment_data[id].temp_ids) || [];
const added_files = temp_ids const added_files = temp_ids
@ -126,6 +107,25 @@ const CommentFormUnconnected: FC<IProps> = ({
const comment = comment_data[id]; 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<KeyboardEventHandler<HTMLTextAreaElement>>(
({ ctrlKey, key }) => {
if (!!ctrlKey && key === 'Enter') onSubmit(null);
},
[onSubmit]
);
const images = useMemo( const images = useMemo(
() => comment.files.filter(file => file && file.type === UPLOAD_TYPES.IMAGE), () => comment.files.filter(file => file && file.type === UPLOAD_TYPES.IMAGE),
[comment.files] [comment.files]
@ -144,6 +144,14 @@ const CommentFormUnconnected: FC<IProps> = ({
[comment.files] [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( const onFileDrop = useCallback(
(file_id: IFile['id']) => { (file_id: IFile['id']) => {
nodeSetCommentData( nodeSetCommentData(
@ -215,13 +223,13 @@ const CommentFormUnconnected: FC<IProps> = ({
/> />
)} )}
{!!audios.length && ( {(!!audios.length || !!locked_audios.length) && (
<SortableAudioGrid <SortableAudioGrid
items={audios} items={audios}
onDrop={onFileDrop} onDrop={onFileDrop}
onSortEnd={onAudioMove} onSortEnd={onAudioMove}
axis="y" axis="y"
locked={[]} locked={locked_audios}
pressDelay={50} pressDelay={50}
helperClass={styles.helper} helperClass={styles.helper}
/> />
@ -242,10 +250,15 @@ const CommentFormUnconnected: FC<IProps> = ({
<Filler /> <Filler />
{is_sending_comment && <LoaderCircle size={20} />} {(is_sending_comment || is_uploading_files) && <LoaderCircle size={20} />}
<Button size="small" color="gray" iconRight="enter" disabled={is_sending_comment}> <Button
Сказать size="small"
color="gray"
iconRight={id === 0 ? 'enter' : 'check'}
disabled={is_sending_comment || is_uploading_files}
>
{id === 0 ? 'Сказать' : 'Сохранить'}
</Button> </Button>
</Group> </Group>
</form> </form>

View file

@ -35,7 +35,4 @@
.attaches { .attaches {
@include outer_shadow(); @include outer_shadow();
padding: $gap;
// background: darken($comment_bg, 2%);
} }