Skip to content

Commit

Permalink
[update] auto save files after 300ms before your last change
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodxa committed May 25, 2017
1 parent 3062d3b commit 46a0712
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion renderer/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from 'react'
import { shell } from 'electron'
import { ipcRenderer, shell } from 'electron'
import { string, func } from 'prop-types'
import { Editor, ButtonGroup, ButtonBar, Field, Preview, EmojiBar } from 'pulse-editor'
import {
Expand Down Expand Up @@ -60,8 +60,22 @@ export default class extends Component {

setFileName = fileName => this.setState({ fileName })

save = content => {
clearTimeout(this.timer)
this.timer = setTimeout(
() => ipcRenderer.send('save-file', content, this.state.fileName),
300
)
}

handleDrop = event => event.preventDefault()

handleChange= event => {
if (event.markdown && this.state.fileName) {
this.save(event.markdown)
}
}

handlePreviewLinkClick = event => {
if (event.target.nodeName === 'A') {
event.preventDefault()
Expand All @@ -78,6 +92,7 @@ export default class extends Component {
<Editor
editorRef={this.setRef}
onDrop={this.handleDrop}
onChange={this.handleChange}
name='main-editor'
>
<ButtonBar>
Expand Down

0 comments on commit 46a0712

Please sign in to comment.