From a9d4be064e546dd2badfeb9e026ed0f60c034ea3 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Mon, 21 Oct 2019 17:13:58 +0700 Subject: [PATCH] audio editor images --- src/components/editors/AudioEditor/index.tsx | 56 ++++++++++++++++---- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/src/components/editors/AudioEditor/index.tsx b/src/components/editors/AudioEditor/index.tsx index b3ef026f..a22ea0d1 100644 --- a/src/components/editors/AudioEditor/index.tsx +++ b/src/components/editors/AudioEditor/index.tsx @@ -1,14 +1,52 @@ -import React, { FC, useCallback } from 'react'; +import React, { FC, useCallback, useMemo } from 'react'; import { INode } from '~/redux/types'; -import path from 'ramda/es/path'; +import { connect } from 'react-redux'; +import { UPLOAD_TYPES } from '~/redux/uploads/constants'; +import { ImageGrid } from '../ImageGrid'; +import * as UPLOAD_ACTIONS from '~/redux/uploads/actions'; +import { selectUploads } from '~/redux/uploads/selectors'; -interface IProps { - data: INode; - setData: (val: INode) => void; -} - -const AudioEditor: FC = ({ data, setData }) => { - return
something!
; +const mapStateToProps = selectUploads; +const mapDispatchToProps = { + uploadUploadFiles: UPLOAD_ACTIONS.uploadUploadFiles, }; +type IProps = ReturnType & + typeof mapDispatchToProps & { + data: INode; + setData: (val: INode) => void; + temp: string[]; + setTemp: (val: string[]) => void; + }; + +const AudioEditorUnconnected: FC = ({ data, setData, temp, statuses }) => { + const images = useMemo( + () => data.files.filter(file => file && file.type === UPLOAD_TYPES.IMAGE), + [data.files] + ); + + const pending_images = useMemo(() => temp.filter(id => !!statuses[id]).map(id => statuses[id]), [ + temp, + statuses, + ]); + + const audios = useMemo( + () => data.files.filter(file => file && file.type === UPLOAD_TYPES.AUDIO), + [data.files] + ); + + const setImages = useCallback(files => setData({ ...data, files: [...files, ...audios] }), [ + setData, + data, + audios, + ]); + + return ; +}; + +const AudioEditor = connect( + mapStateToProps, + mapDispatchToProps +)(AudioEditorUnconnected); + export { AudioEditor };