mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-13 03:45:56 +00:00
Added additional protection against debounce saving
This commit is contained in:
@@ -51,8 +51,8 @@ var getFeature = (level)=>{
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
full : function(classname){
|
||||
classname = classname || _.sample(classnames)
|
||||
full : function(){
|
||||
classname = _.sample(classnames)
|
||||
|
||||
var maxes = [4,3,3,3,3,2,2,1,1]
|
||||
var drawSlots = function(Slots){
|
||||
@@ -91,8 +91,8 @@ module.exports = {
|
||||
}).join('\n') +'\n</div>\n\n';
|
||||
},
|
||||
|
||||
half : function(classname){
|
||||
classname = classname || _.sample(classnames)
|
||||
half : function(){
|
||||
classname = _.sample(classnames)
|
||||
|
||||
var featureScore = 1
|
||||
return "<div class='classTable'>\n##### The " + classname + "\n" +
|
||||
|
||||
@@ -11,18 +11,15 @@ const PrintLink = require('../../navbar/print.navitem.jsx');
|
||||
const Account = require('../../navbar/account.navitem.jsx');
|
||||
//const RecentlyEdited = require('../../navbar/recent.navitem.jsx').edited;
|
||||
|
||||
|
||||
const SplitPane = require('naturalcrit/splitPane/splitPane.jsx');
|
||||
const Editor = require('../../editor/editor.jsx');
|
||||
const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
||||
|
||||
const Markdown = require('naturalcrit/markdown.js');
|
||||
|
||||
|
||||
const SAVE_TIMEOUT = 3000;
|
||||
|
||||
|
||||
|
||||
const EditPage = React.createClass({
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
@@ -47,7 +44,6 @@ const EditPage = React.createClass({
|
||||
return {
|
||||
brew : this.props.brew,
|
||||
|
||||
|
||||
isSaving : false,
|
||||
isPending : false,
|
||||
errors : null,
|
||||
@@ -58,7 +54,7 @@ const EditPage = React.createClass({
|
||||
savedBrew : null,
|
||||
|
||||
componentDidMount: function(){
|
||||
this.debounceSave = _.debounce(this.save, SAVE_TIMEOUT);
|
||||
this.trySave();
|
||||
window.onbeforeunload = ()=>{
|
||||
if(this.state.isSaving || this.state.isPending){
|
||||
return 'You have unsaved changes!';
|
||||
@@ -98,8 +94,7 @@ const EditPage = React.createClass({
|
||||
brew : _.merge({}, this.state.brew, metadata),
|
||||
isPending : true,
|
||||
}, ()=>{
|
||||
console.log(this.hasChanges());
|
||||
(this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel());
|
||||
this.trySave();
|
||||
});
|
||||
|
||||
},
|
||||
@@ -116,7 +111,7 @@ const EditPage = React.createClass({
|
||||
htmlErrors : htmlErrors
|
||||
});
|
||||
|
||||
(this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel());
|
||||
this.trySave();
|
||||
},
|
||||
|
||||
hasChanges : function(){
|
||||
@@ -128,8 +123,18 @@ const EditPage = React.createClass({
|
||||
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(){
|
||||
this.debounceSave.cancel();
|
||||
if(this.debounceSave && this.debounceSave.cancel) this.debounceSave.cancel();
|
||||
|
||||
this.setState({
|
||||
isSaving : true,
|
||||
errors : null,
|
||||
@@ -163,7 +168,6 @@ const EditPage = React.createClass({
|
||||
errMsg += '```\n' + JSON.stringify(this.state.errors.response.error, null, ' ') + '\n```';
|
||||
}catch(e){}
|
||||
|
||||
|
||||
return <Nav.item className='save error' icon="fa-warning">
|
||||
Oops!
|
||||
<div className='errorContainer'>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "homebrewery",
|
||||
"description": "Create authentic looking D&D homebrews using only markdown",
|
||||
"version": "2.6.0",
|
||||
"version": "2.6.1",
|
||||
"scripts": {
|
||||
"build": "node_modules/.bin/gulp prod",
|
||||
"watch": "node_modules/.bin/gulp",
|
||||
|
||||
Reference in New Issue
Block a user