const flux = require('pico-flux') const React = require('react'); const _ = require('lodash'); const cx = require('classnames'); const Nav = require('naturalcrit/nav/nav.jsx'); const Store = require('homebrewery/brew.store.js'); const Actions = require('homebrewery/brew.actions.js'); const onStoreChange = () => { return { status : Store.getStatus(), errors : Store.getErrors() } }; const ContinousSave = React.createClass({ getDefaultProps: function() { return { status : 'ready', errors : undefined }; }, componentDidMount: function() { flux.actionEmitter.on('dispatch', this.actionHandler); window.onbeforeunload = ()=>{ if(this.props.status !== 'ready') return 'You have unsaved changes!'; }; }, componentWillUnmount: function() { flux.actionEmitter.removeListener('dispatch', this.actionHandler); window.onbeforeunload = function(){}; }, actionHandler : function(actionType){ if(actionType == 'UPDATE_BREW_TEXT' || actionType == 'UPDATE_META'){ Actions.pendingSave(); } }, handleClick : function(){ Actions.save(); }, renderError : function(){ let errMsg = ''; try{ errMsg += this.state.errors.toString() + '\n\n'; errMsg += '```\n' + JSON.stringify(this.state.errors.response.error, null, ' ') + '\n```'; }catch(e){} return Oops!
Looks like there was a problem saving.
Report the issue here .
}, render : function(){ if(this.props.status == 'error') return this.renderError(); if(this.props.status == 'saving'){ return saving... } if(this.props.status == 'pending'){ return Save Now } if(this.props.status == 'ready'){ return saved. } }, }); module.exports = Store.createSmartComponent(ContinousSave, onStoreChange);