Skip to content

Commit

Permalink
Add file name adjustments (noneditable). Need to compose it
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix22 committed Feb 25, 2017
1 parent 0ae2f9b commit bd088b9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const execS = require('child_process').exec

const { replaceSpaceCharacters, concatFiles } = require('./helpers/util')
const { replaceSpaceCharacters, createOutputFileName } = require('./helpers/util')

const convert = ({ files, outputPath, outputType, name }) => {
// eslint-disable-next-line dot-notation
Expand All @@ -10,7 +9,7 @@ const convert = ({ files, outputPath, outputType, name }) => {
execS('which convert', (error) => {
if (error) reject(error)

const outputName = name || `ALCHEMY-${concatFiles(files)}.${outputType || 'pdf'}`
const outputName = name || createOutputFileName({ files, outputType })
const command = [
'convert',
...files.map(replaceSpaceCharacters), // input files
Expand Down
12 changes: 7 additions & 5 deletions src/components/Converter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ArrowDown from './svg/ArrowDown'
import Cancel from './svg/Cancel'

import { convert } from '../api'
import { removeByKey, uniqueFiles } from '../helpers/util'
import { removeByKey, uniqueFiles, displayOutputFileName, filterImages } from '../helpers/util'
import {
fileTypes,
MERGE,
Expand Down Expand Up @@ -123,7 +123,11 @@ class Sanitizer extends Component {
case CONVERTING: return <Converting />
case STAGING: return (
<div className="staging">
<input type="text" value="Alchemy-1.txt" />
{/* TODO make this compose better */}
<input
type="text"
value={displayOutputFileName(this.state.files)(this.state.outputType)}
/>
<div className="row">
<div className="switch">
<button
Expand Down Expand Up @@ -179,9 +183,7 @@ class Sanitizer extends Component {
}

convert() {
const filtered = Object.keys(this.state.files)
.map(key => this.state.files[key])
.filter(file => file.type.includes('image'))
const filtered = filterImages(this.state.files)

if (filtered.length) {
this.setState({
Expand Down
22 changes: 22 additions & 0 deletions src/helpers/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ const concatFiles = files =>
.replace(/\s/g, '')
.substr(0, 50)

const filterImages = files => Object.keys(files)
.map(key => files[key])
.filter(file => file.type.includes('image'))

const createOutputFileName = ({ files, outputType }) => `ALCHEMY-${concatFiles(files)}.${outputType || 'pdf'}`

const centerEllipsis = str => (
(str.length > 15) ?
`${str.substr(0, 7)}...${str.substr(str.length - 7, str.length)}` :
str
)

const displayOutputFileName = files => outputType =>
centerEllipsis(createOutputFileName({
files: filterImages(files).map(f => f.path),
outputType
}))

const uniqueFiles = (files, newArray) =>
newArray.reduce((accum, next) => {
if (accum[next.path]) return accum
Expand All @@ -24,6 +42,10 @@ const removeByKey = (myObj, deleteKey) => {
}

module.exports = {
displayOutputFileName,
centerEllipsis,
filterImages,
createOutputFileName,
concatFiles,
removeByKey,
replaceSpaceCharacters,
Expand Down

0 comments on commit bd088b9

Please sign in to comment.