Add optional timestamp to saved file names (#430)

* Add timestamp to file name save

* Add .DS_Store to .gitignore

* Add setting to toggle timestamp on file save

* Tweak timestamp format
main
erick 6 years ago committed by Michael Fix
parent e92e4567de
commit d0d3589dc4

1
.gitignore vendored

@ -4,3 +4,4 @@ node_modules
cypress/videos cypress/videos
cypress/screenshots cypress/screenshots
.idea .idea
.DS_Store

@ -143,8 +143,15 @@ class Editor extends React.Component {
save({ id: format = 'png' }) { save({ id: format = 'png' }) {
const link = document.createElement('a') const link = document.createElement('a')
const timezoneOffset = (new Date()).getTimezoneOffset() * 60000
const timeString = (new Date(Date.now() - timezoneOffset)).toISOString()
.slice(0, 19)
.replace(/:/g,'-')
.replace('T','_')
const timestamp = this.state.timestamp ? `_${timeString}` : ''
return this.getCarbonImage({ format, type: 'blob' }).then(url => { return this.getCarbonImage({ format, type: 'blob' }).then(url => {
link.download = `carbon.${format}` link.download = `carbon${timestamp}.${format}`
link.href = url link.href = url
document.body.appendChild(link) document.body.appendChild(link)
link.click() link.click()

@ -114,6 +114,11 @@ class Settings extends React.Component {
enabled={this.props.watermark} enabled={this.props.watermark}
onChange={this.props.onChange.bind(null, 'watermark')} onChange={this.props.onChange.bind(null, 'watermark')}
/> />
<Toggle
label="Timestamp file name"
enabled={this.props.timestamp}
onChange={this.props.onChange.bind(null, 'timestamp')}
/>
<ExportSizeSelect <ExportSizeSelect
selected={this.props.exportSize || '2x'} selected={this.props.exportSize || '2x'}
onChange={this.props.onChange.bind(null, 'exportSize')} onChange={this.props.onChange.bind(null, 'exportSize')}

@ -500,5 +500,6 @@ export const DEFAULT_SETTINGS = {
exportSize: '2x', exportSize: '2x',
titleBar: '', titleBar: '',
watermark: false, watermark: false,
squaredImage: false squaredImage: false,
timestamp: true
} }

@ -36,7 +36,8 @@ const mappings = [
{ field: 'si:squaredImage', type: 'bool' }, { field: 'si:squaredImage', type: 'bool' },
{ field: 'code:code' }, { field: 'code:code' },
{ field: 'es:exportSize' }, { field: 'es:exportSize' },
{ field: 'wm:watermark', type: 'bool' } { field: 'wm:watermark', type: 'bool' },
{ field: 'ts:timestamp', type: 'bool' }
] ]
const reverseMappings = mappings.map(mapping => const reverseMappings = mappings.map(mapping =>

Loading…
Cancel
Save