mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-27 00:42:40 +00:00
getting the debounced saving working
This commit is contained in:
@@ -1,51 +1,8 @@
|
||||
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;
|
||||
module.exports = function(props){
|
||||
return <Nav.item newTab={true} href='https://github.com/stolksdorf/naturalcrit/issues' color='red' icon='fa-bug'>
|
||||
report issue
|
||||
</Nav.item>
|
||||
};
|
||||
@@ -19,7 +19,7 @@
|
||||
margin : 0;
|
||||
padding : 2px;
|
||||
width : 250px;
|
||||
background-color : #333;
|
||||
background-color : #444;
|
||||
font-family : 'Open Sans', sans-serif;
|
||||
font-size : 12px;
|
||||
font-weight : 800;
|
||||
|
||||
@@ -1,51 +1,8 @@
|
||||
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;
|
||||
module.exports = function(props){
|
||||
return <Nav.item newTab={true} href={'/homebrew/print/' + props.sharedId} color='purple' icon='fa-print'>
|
||||
print
|
||||
</Nav.item>
|
||||
};
|
||||
@@ -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;
|
||||
@@ -8,6 +8,8 @@ var Nav = require('naturalcrit/nav/nav.jsx');
|
||||
var Navbar = require('../../navbar/navbar.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');
|
||||
@@ -49,19 +51,27 @@ var EditPage = React.createClass({
|
||||
return {
|
||||
title : this.props.brew.title,
|
||||
text: this.props.brew.text,
|
||||
|
||||
isSaving : false,
|
||||
|
||||
isPending : false,
|
||||
|
||||
errors : null,
|
||||
pending : false,
|
||||
|
||||
lastUpdated : this.props.brew.updatedAt
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
var self = this;
|
||||
window.onbeforeunload = function(){
|
||||
if(!self.state.pending) return;
|
||||
return "You have unsaved changes!";
|
||||
savedBrew : null,
|
||||
|
||||
|
||||
componentDidMount: function(){
|
||||
this.debounceSave = _.debounce(this.save, SAVE_TIMEOUT);
|
||||
|
||||
window.onbeforeunload = ()=>{
|
||||
//do state checks
|
||||
|
||||
//return "You have unsaved changes!";
|
||||
}
|
||||
},
|
||||
componentWillUnmount: function() {
|
||||
@@ -77,7 +87,8 @@ var EditPage = React.createClass({
|
||||
title : title,
|
||||
pending : true
|
||||
});
|
||||
this.save();
|
||||
|
||||
(this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel());
|
||||
},
|
||||
|
||||
handleTextChange : function(text){
|
||||
@@ -85,7 +96,8 @@ var EditPage = React.createClass({
|
||||
text : text,
|
||||
pending : true
|
||||
});
|
||||
this.save();
|
||||
|
||||
(this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel());
|
||||
},
|
||||
|
||||
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
|
||||
.put('/homebrew/api/update/' + this.props.id)
|
||||
.put('/homebrew/api/update/' + this.props.brew.editId)
|
||||
.send({text : this.state.text})
|
||||
.end((err, res) => {
|
||||
console.log('done', res.body);
|
||||
this.savedBrew = res.body;
|
||||
this.setState({
|
||||
pending : false,
|
||||
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.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'>
|
||||
Share
|
||||
</Nav.item>
|
||||
|
||||
<Nav.item newTab={true} href={'/homebrew/print/' + this.props.brew.sharedId} color='orange' icon='fa-print'>
|
||||
print
|
||||
</Nav.item>
|
||||
|
||||
<Nav.item color='lightred' icon='fa-trash' onClick={this.handleDelete}>
|
||||
<PrintLink shareId={this.props.brew.shareId} />
|
||||
<Nav.item color='red' icon='fa-trash' onClick={this.handleDelete}>
|
||||
Delete
|
||||
</Nav.item>
|
||||
|
||||
</Nav.section>
|
||||
</Navbar>
|
||||
},
|
||||
|
||||
11
todo.md
11
todo.md
@@ -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 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 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 Rename `/client/naturalCrit` -> `/client/main`
|
||||
- Move snippets into their new groups
|
||||
- Replace pseudo-elements with encoded images
|
||||
|
||||
## v1.6
|
||||
- Add in brew title, use for metadata?
|
||||
- Add error handling to the saving wdiget in the status bar
|
||||
- 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
|
||||
|
||||
- Add in a tutorial page?
|
||||
|
||||
## v1.7
|
||||
- User accounts!
|
||||
|
||||
Reference in New Issue
Block a user