0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-14 23:42:41 +00:00

Added additional protection against debounce saving

This commit is contained in:
Scott Tolksdorf
2016-12-12 10:28:37 -05:00
parent 63aee2dedf
commit 1f1bd669fe
3 changed files with 19 additions and 15 deletions

View File

@@ -51,8 +51,8 @@ var getFeature = (level)=>{
} }
module.exports = { module.exports = {
full : function(classname){ full : function(){
classname = classname || _.sample(classnames) classname = _.sample(classnames)
var maxes = [4,3,3,3,3,2,2,1,1] var maxes = [4,3,3,3,3,2,2,1,1]
var drawSlots = function(Slots){ var drawSlots = function(Slots){
@@ -91,8 +91,8 @@ module.exports = {
}).join('\n') +'\n</div>\n\n'; }).join('\n') +'\n</div>\n\n';
}, },
half : function(classname){ half : function(){
classname = classname || _.sample(classnames) classname = _.sample(classnames)
var featureScore = 1 var featureScore = 1
return "<div class='classTable'>\n##### The " + classname + "\n" + return "<div class='classTable'>\n##### The " + classname + "\n" +

View File

@@ -11,18 +11,15 @@ const PrintLink = require('../../navbar/print.navitem.jsx');
const Account = require('../../navbar/account.navitem.jsx'); const Account = require('../../navbar/account.navitem.jsx');
//const RecentlyEdited = require('../../navbar/recent.navitem.jsx').edited; //const RecentlyEdited = require('../../navbar/recent.navitem.jsx').edited;
const SplitPane = require('naturalcrit/splitPane/splitPane.jsx'); const SplitPane = require('naturalcrit/splitPane/splitPane.jsx');
const Editor = require('../../editor/editor.jsx'); const Editor = require('../../editor/editor.jsx');
const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx'); const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
const Markdown = require('naturalcrit/markdown.js'); const Markdown = require('naturalcrit/markdown.js');
const SAVE_TIMEOUT = 3000; const SAVE_TIMEOUT = 3000;
const EditPage = React.createClass({ const EditPage = React.createClass({
getDefaultProps: function() { getDefaultProps: function() {
return { return {
@@ -47,7 +44,6 @@ const EditPage = React.createClass({
return { return {
brew : this.props.brew, brew : this.props.brew,
isSaving : false, isSaving : false,
isPending : false, isPending : false,
errors : null, errors : null,
@@ -58,7 +54,7 @@ const EditPage = React.createClass({
savedBrew : null, savedBrew : null,
componentDidMount: function(){ componentDidMount: function(){
this.debounceSave = _.debounce(this.save, SAVE_TIMEOUT); this.trySave();
window.onbeforeunload = ()=>{ window.onbeforeunload = ()=>{
if(this.state.isSaving || this.state.isPending){ if(this.state.isSaving || this.state.isPending){
return 'You have unsaved changes!'; return 'You have unsaved changes!';
@@ -98,8 +94,7 @@ const EditPage = React.createClass({
brew : _.merge({}, this.state.brew, metadata), brew : _.merge({}, this.state.brew, metadata),
isPending : true, isPending : true,
}, ()=>{ }, ()=>{
console.log(this.hasChanges()); this.trySave();
(this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel());
}); });
}, },
@@ -116,7 +111,7 @@ const EditPage = React.createClass({
htmlErrors : htmlErrors htmlErrors : htmlErrors
}); });
(this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel()); this.trySave();
}, },
hasChanges : function(){ hasChanges : function(){
@@ -128,8 +123,18 @@ const EditPage = React.createClass({
return false; return false;
}, },
trySave : function(){
if(!this.debounceSave) this.debounceSave = _.debounce(this.save, SAVE_TIMEOUT);
if(this.hasChanges()){
this.debounceSave();
}else{
this.debounceSave.cancel();
}
},
save : function(){ save : function(){
this.debounceSave.cancel(); if(this.debounceSave && this.debounceSave.cancel) this.debounceSave.cancel();
this.setState({ this.setState({
isSaving : true, isSaving : true,
errors : null, errors : null,
@@ -163,7 +168,6 @@ const EditPage = React.createClass({
errMsg += '```\n' + JSON.stringify(this.state.errors.response.error, null, ' ') + '\n```'; errMsg += '```\n' + JSON.stringify(this.state.errors.response.error, null, ' ') + '\n```';
}catch(e){} }catch(e){}
return <Nav.item className='save error' icon="fa-warning"> return <Nav.item className='save error' icon="fa-warning">
Oops! Oops!
<div className='errorContainer'> <div className='errorContainer'>

View File

@@ -1,7 +1,7 @@
{ {
"name": "homebrewery", "name": "homebrewery",
"description": "Create authentic looking D&D homebrews using only markdown", "description": "Create authentic looking D&D homebrews using only markdown",
"version": "2.6.0", "version": "2.6.1",
"scripts": { "scripts": {
"build": "node_modules/.bin/gulp prod", "build": "node_modules/.bin/gulp prod",
"watch": "node_modules/.bin/gulp", "watch": "node_modules/.bin/gulp",