From 46a0712af2e1e7c6ae4864d6c97714211d379a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Daniel=20Xalambr=C3=AD?= Date: Wed, 24 May 2017 20:22:16 -0500 Subject: [PATCH] [update] auto save files after 300ms before your last change --- renderer/pages/index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/renderer/pages/index.js b/renderer/pages/index.js index ff289e5..c8ca803 100644 --- a/renderer/pages/index.js +++ b/renderer/pages/index.js @@ -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 { @@ -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() @@ -78,6 +92,7 @@ export default class extends Component {