Skip to content

Commit

Permalink
fix #268 lastExportedProject, fix export to images func import and fi…
Browse files Browse the repository at this point in the history
…le names
  • Loading branch information
kmcb777 committed May 20, 2019
1 parent c62a487 commit 5d9b73e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/actions/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import trash from 'trash'
import { replace } from 'react-router-redux'
import kebabCase from 'lodash/kebabCase'

import takeScreenshot from 'helpers/takeScreenshot'
import { takeScreenshot } from 'helpers/takeScreenshot'

import { addAlert } from 'reducers/alerts'
import { openExternalFileOverlay, closeExternalFileOverlay } from 'reducers/externalFileOverlay'
Expand Down Expand Up @@ -181,14 +181,14 @@ async function massExport(state, asyncJob) {
const projBaseName = path.basename(p.get('path'))
const projSafeName = `${kebabCase(projBaseName)}.html`
const filePath = path.join(targetPath, projSafeName)
await asyncJob(filePath, p)
await asyncJob(filePath, p, targetPath)
}
return targetPath
}

export function exportSelectedProjectsToHTML() {
return (dispatch, getState) => {
const targetPath = massExport(getState(), (filePath, p) => fsWriteFile(filePath, p.get('html')))
return async (dispatch, getState) => {
const targetPath = await massExport(getState(), (filePath, p) => fsWriteFile(filePath, p.get('html')))
if (targetPath) {
dispatch(saveLastExportedFolder(targetPath))
}
Expand All @@ -198,17 +198,18 @@ export function exportSelectedProjectsToHTML() {
export function exportSelectedProjectsToImages(done) {
return async (dispatch, getState) => {
const state = getState()
const targetPath = await massExport(state, async (filePath, p) => {

const targetPath = await massExport(state, async (filePath, p, targetDir) => {
const html = p.get('html')
const previewSize = state.settings.get('previewSize')
const [mobileWidth, desktopWidth] = [previewSize.get('mobile'), previewSize.get('desktop')]
const [mobileScreenshot, desktopScreenshot] = await Promise.all([
takeScreenshot(html, mobileWidth),
takeScreenshot(html, desktopWidth),
takeScreenshot(html, mobileWidth, targetDir),
takeScreenshot(html, desktopWidth, targetDir),
])
await Promise.all([
fsWriteFile(`${filePath}_mobile.png`, mobileScreenshot),
fsWriteFile(`${filePath}_desktop.png`, desktopScreenshot),
fsWriteFile(`${filePath.replace(/.html$/, '')}_mobile.png`, mobileScreenshot),
fsWriteFile(`${filePath.replace(/.html$/, '')}_desktop.png`, desktopScreenshot),
])
})
if (targetPath) {
Expand Down

0 comments on commit 5d9b73e

Please sign in to comment.