diff --git a/src/components/Converter.jsx b/src/components/Converter.jsx index be61a8b..2323af4 100644 --- a/src/components/Converter.jsx +++ b/src/components/Converter.jsx @@ -12,7 +12,7 @@ import ArrowDown from './svg/ArrowDown' import Cancel from './svg/Cancel' import { convert } from '../api' -import { removeByKey, uniqueFiles, displayOutputFileName, filterImages } from '../helpers/util' +import { removeByKey, uniqueAndValidFiles, displayOutputFileName, filterImages } from '../helpers/util' import { fileTypes, MERGE, @@ -26,10 +26,10 @@ import { const drop = (props, monitor, component) => { const { files } = monitor.getItem() - const filesUnique = uniqueFiles(component.state.files, files) + const stagingFiles = uniqueAndValidFiles(component.state.files, files) component.setState({ - status: Object.keys(filesUnique).length ? STAGING : IDLE, - files: filesUnique + status: Object.keys(stagingFiles).length ? STAGING : IDLE, + files: stagingFiles }) if (component.state.shifted) { diff --git a/src/helpers/util.js b/src/helpers/util.js index 0b4cd33..339edb2 100644 --- a/src/helpers/util.js +++ b/src/helpers/util.js @@ -1,4 +1,5 @@ const { pluck, compose, map } = require('./functional') +const { fileTypes } = require('./constants') const replaceSpaceCharacters = str => str.replace(/\s/g, '\\ ') @@ -26,9 +27,15 @@ function centerEllipsis(str, length = 7) { const displayOutputFileName = outputType => compose(filterImages, map(pluck('path')), createOutputFileName(outputType), centerEllipsis) -const uniqueFiles = (files, newArray) => +const fileTypesArr = [].concat(...(Object.keys(fileTypes).map(key => fileTypes[key]))) + +const isValidFileType = fileType => fileTypesArr.indexOf(fileType) > -1 + +const getFileType = fileName => fileName.split('.').pop() + +const uniqueAndValidFiles = (files, newArray) => newArray.reduce((accum, next) => { - if (accum[next.path]) return accum + if (accum[next.path] || !isValidFileType(getFileType(next.name))) return accum return Object.assign(accum, { [next.path]: next }) @@ -48,5 +55,5 @@ module.exports = { concatFiles, removeByKey, replaceSpaceCharacters, - uniqueFiles + uniqueAndValidFiles, }