0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-11 17:42:42 +00:00

getting the debounced saving working

This commit is contained in:
Scott Tolksdorf
2016-05-10 00:38:38 -04:00
parent ed7decb42b
commit 743bcb0c74
6 changed files with 65 additions and 178 deletions

View File

@@ -1,51 +1,8 @@
var React = require('react'); var React = require('react');
var _ = require('lodash');
var cx = require('classnames');
//var striptags = require('striptags');
var Nav = require('naturalcrit/nav/nav.jsx'); var Nav = require('naturalcrit/nav/nav.jsx');
const MAX_URL_SIZE = 2083; module.exports = function(props){
const MAIN_URL = "https://www.reddit.com/r/UnearthedArcana/submit?selftext=true" return <Nav.item newTab={true} href='https://github.com/stolksdorf/naturalcrit/issues' color='red' icon='fa-bug'>
report issue
</Nav.item>
var RedditShare = React.createClass({ };
getDefaultProps: function() {
return {
brew : {
title : '',
sharedId : '',
text : ''
}
};
},
getText : function(){
},
handleClick : function(){
var url = [
MAIN_URL,
'title=' + encodeURIComponent(this.props.brew.title ? this.props.brew.title : 'Check out my brew!'),
'text=' + encodeURIComponent(this.props.brew.text)
].join('&');
window.open(url, '_blank');
},
render : function(){
return <Nav.item icon='fa-reddit-alien' color='red' onClick={this.handleClick}>
share on reddit
</Nav.item>
},
});
module.exports = RedditShare;

View File

@@ -19,7 +19,7 @@
margin : 0; margin : 0;
padding : 2px; padding : 2px;
width : 250px; width : 250px;
background-color : #333; background-color : #444;
font-family : 'Open Sans', sans-serif; font-family : 'Open Sans', sans-serif;
font-size : 12px; font-size : 12px;
font-weight : 800; font-weight : 800;

View File

@@ -1,51 +1,8 @@
var React = require('react'); var React = require('react');
var _ = require('lodash');
var cx = require('classnames');
//var striptags = require('striptags');
var Nav = require('naturalcrit/nav/nav.jsx'); var Nav = require('naturalcrit/nav/nav.jsx');
const MAX_URL_SIZE = 2083; module.exports = function(props){
const MAIN_URL = "https://www.reddit.com/r/UnearthedArcana/submit?selftext=true" return <Nav.item newTab={true} href={'/homebrew/print/' + props.sharedId} color='purple' icon='fa-print'>
print
</Nav.item>
var RedditShare = React.createClass({ };
getDefaultProps: function() {
return {
brew : {
title : '',
sharedId : '',
text : ''
}
};
},
getText : function(){
},
handleClick : function(){
var url = [
MAIN_URL,
'title=' + encodeURIComponent(this.props.brew.title ? this.props.brew.title : 'Check out my brew!'),
'text=' + encodeURIComponent(this.props.brew.text)
].join('&');
window.open(url, '_blank');
},
render : function(){
return <Nav.item icon='fa-reddit-alien' color='red' onClick={this.handleClick}>
share on reddit
</Nav.item>
},
});
module.exports = RedditShare;

View File

@@ -1,51 +0,0 @@
var React = require('react');
var _ = require('lodash');
var cx = require('classnames');
//var striptags = require('striptags');
var Nav = require('naturalcrit/nav/nav.jsx');
const MAX_URL_SIZE = 2083;
const MAIN_URL = "https://www.reddit.com/r/UnearthedArcana/submit?selftext=true"
var RedditShare = React.createClass({
getDefaultProps: function() {
return {
brew : {
title : '',
sharedId : '',
text : ''
}
};
},
getText : function(){
},
handleClick : function(){
var url = [
MAIN_URL,
'title=' + encodeURIComponent(this.props.brew.title ? this.props.brew.title : 'Check out my brew!'),
'text=' + encodeURIComponent(this.props.brew.text)
].join('&');
window.open(url, '_blank');
},
render : function(){
return <Nav.item icon='fa-reddit-alien' color='red' onClick={this.handleClick}>
share on reddit
</Nav.item>
},
});
module.exports = RedditShare;

View File

@@ -8,6 +8,8 @@ var Nav = require('naturalcrit/nav/nav.jsx');
var Navbar = require('../../navbar/navbar.jsx'); var Navbar = require('../../navbar/navbar.jsx');
var EditTitle = require('../../navbar/editTitle.navitem.jsx'); var EditTitle = require('../../navbar/editTitle.navitem.jsx');
var ReportIssue = require('../../navbar/issue.navitem.jsx');
var PrintLink = require('../../navbar/print.navitem.jsx');
var SplitPane = require('naturalcrit/splitPane/splitPane.jsx'); var SplitPane = require('naturalcrit/splitPane/splitPane.jsx');
@@ -49,19 +51,27 @@ var EditPage = React.createClass({
return { return {
title : this.props.brew.title, title : this.props.brew.title,
text: this.props.brew.text, text: this.props.brew.text,
isSaving : false, isSaving : false,
isPending : false,
errors : null, errors : null,
pending : false,
lastUpdated : this.props.brew.updatedAt lastUpdated : this.props.brew.updatedAt
}; };
}, },
componentDidMount: function() { savedBrew : null,
var self = this;
window.onbeforeunload = function(){
if(!self.state.pending) return; componentDidMount: function(){
return "You have unsaved changes!"; this.debounceSave = _.debounce(this.save, SAVE_TIMEOUT);
window.onbeforeunload = ()=>{
//do state checks
//return "You have unsaved changes!";
} }
}, },
componentWillUnmount: function() { componentWillUnmount: function() {
@@ -77,7 +87,8 @@ var EditPage = React.createClass({
title : title, title : title,
pending : true pending : true
}); });
this.save();
(this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel());
}, },
handleTextChange : function(text){ handleTextChange : function(text){
@@ -85,7 +96,8 @@ var EditPage = React.createClass({
text : text, text : text,
pending : true pending : true
}); });
this.save();
(this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel());
}, },
handleDelete : function(){ handleDelete : function(){
@@ -99,17 +111,43 @@ var EditPage = React.createClass({
}); });
}, },
save : _.debounce(function(){ hasChanges : function(){
if(this.savedBrew){
if(this.state.text !== this.savedBrew.text) return true;
if(this.state.title !== this.savedBrew.title) return true;
}else{
if(this.state.text !== this.props.brew.text) return true;
if(this.state.title !== this.props.brew.title) return true;
}
return false;
},
save : function(){
console.log('saving!');
this.debounceSave.cancel();
request request
.put('/homebrew/api/update/' + this.props.id) .put('/homebrew/api/update/' + this.props.brew.editId)
.send({text : this.state.text}) .send({text : this.state.text})
.end((err, res) => { .end((err, res) => {
console.log('done', res.body);
this.savedBrew = res.body;
this.setState({ this.setState({
pending : false, pending : false,
lastUpdated : res.body.updatedAt lastUpdated : res.body.updatedAt
}) })
}) })
}, SAVE_TIMEOUT), },
renderSaveButton : function(){
if(!this.state.isPending && !this.state.isSaving){
//saved
}else if(this.state.isPending && this.hasChanges()){
//save now
}else if(this.state.isSaving){
//saving
}
},
@@ -120,22 +158,13 @@ var EditPage = React.createClass({
</Nav.section> </Nav.section>
<Nav.section> <Nav.section>
<Nav.item newTab={true} href='https://github.com/stolksdorf/naturalcrit/issues' color='red' icon='fa-bug'>
report issue
</Nav.item>
<Nav.item newTab={true} href={'/homebrew/share/' + this.props.brew.shareId} color='teal' icon='fa-share'> <Nav.item newTab={true} href={'/homebrew/share/' + this.props.brew.shareId} color='teal' icon='fa-share'>
Share Share
</Nav.item> </Nav.item>
<PrintLink shareId={this.props.brew.shareId} />
<Nav.item newTab={true} href={'/homebrew/print/' + this.props.brew.sharedId} color='orange' icon='fa-print'> <Nav.item color='red' icon='fa-trash' onClick={this.handleDelete}>
print
</Nav.item>
<Nav.item color='lightred' icon='fa-trash' onClick={this.handleDelete}>
Delete Delete
</Nav.item> </Nav.item>
</Nav.section> </Nav.section>
</Navbar> </Navbar>
}, },

11
todo.md
View File

@@ -14,23 +14,18 @@ X Update the admin page with pagnition and a query box
X Test the old/small brew filtering for deleteion X Test the old/small brew filtering for deleteion
X Partial rendering kills style tags on unrendered pages. Detect if pages have style tags and render them. X Partial rendering kills style tags on unrendered pages. Detect if pages have style tags and render them.
- Add in the link of Pateron? - Add in the link of Pateron?
- Add in brew title, use for metadata?
- Add in specific entry point rendering in server.js
- Add in a tutorial page?
X Add in a localstorage fallback on the `/new` page, clear it when they save X Add in a localstorage fallback on the `/new` page, clear it when they save
X Rename `/client/naturalCrit` -> `/client/main` X Rename `/client/naturalCrit` -> `/client/main`
- Move snippets into their new groups - Move snippets into their new groups
- Replace pseudo-elements with encoded images - Replace pseudo-elements with encoded images
## v1.6 ## v1.6
- Add in brew title, use for metadata?
- Add error handling to the saving wdiget in the status bar - Add error handling to the saving wdiget in the status bar
- Should provide error dump to copy and a link to github issues page - Should provide error dump to copy and a link to github issues page
- Add in the pane splitter
- Add in CodeMIrror of markdown
- Code Editor should display errors at bottom
- Add in Descriptive name box for a brew
- Look into improving the metadata on pages for linking - Look into improving the metadata on pages for linking
- Add in a tutorial page?
## v1.7 ## v1.7
- User accounts! - User accounts!