0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-07 14:12:43 +00:00

Save button is functional

This commit is contained in:
Scott Tolksdorf
2016-05-10 00:50:17 -04:00
parent 743bcb0c74
commit eb4117b35b
4 changed files with 28 additions and 16 deletions

View File

@@ -2,7 +2,7 @@ var React = require('react');
var Nav = require('naturalcrit/nav/nav.jsx'); var Nav = require('naturalcrit/nav/nav.jsx');
module.exports = function(props){ module.exports = function(props){
return <Nav.item newTab={true} href={'/homebrew/print/' + props.sharedId} color='purple' icon='fa-print'> return <Nav.item newTab={true} href={'/homebrew/print/' + props.shareId} color='purple' icon='fa-print'>
print print
</Nav.item> </Nav.item>
}; };

View File

@@ -85,7 +85,7 @@ var EditPage = React.createClass({
handleTitleChange : function(title){ handleTitleChange : function(title){
this.setState({ this.setState({
title : title, title : title,
pending : true isPending : true
}); });
(this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel()); (this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel());
@@ -94,7 +94,7 @@ var EditPage = React.createClass({
handleTextChange : function(text){ handleTextChange : function(text){
this.setState({ this.setState({
text : text, text : text,
pending : true isPending : true
}); });
(this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel()); (this.hasChanges() ? this.debounceSave() : this.debounceSave.cancel());
@@ -125,6 +125,10 @@ var EditPage = React.createClass({
save : function(){ save : function(){
console.log('saving!'); console.log('saving!');
this.debounceSave.cancel(); this.debounceSave.cancel();
this.setState({
isSaving : true
});
request request
.put('/homebrew/api/update/' + this.props.brew.editId) .put('/homebrew/api/update/' + this.props.brew.editId)
.send({text : this.state.text}) .send({text : this.state.text})
@@ -132,19 +136,28 @@ var EditPage = React.createClass({
console.log('done', res.body); console.log('done', res.body);
this.savedBrew = res.body; this.savedBrew = res.body;
this.setState({ this.setState({
pending : false, isPending : false,
isSaving : false,
lastUpdated : res.body.updatedAt lastUpdated : res.body.updatedAt
}) })
}) })
}, },
renderSaveButton : function(){ renderSaveButton : function(){
if(this.state.isSaving){
return <Nav.item icon="fa-spinner fa-spin">saving...</Nav.item>
}
if(!this.state.isPending && !this.state.isSaving){ if(!this.state.isPending && !this.state.isSaving){
//saved return <Nav.item>saved.</Nav.item>
}else if(this.state.isPending && this.hasChanges()){ }
//save now
}else if(this.state.isSaving){ if(this.state.isPending && this.hasChanges()){
//saving return <Nav.item onClick={this.save} color='blue'>Save Now</Nav.item>
} }
}, },
@@ -158,6 +171,8 @@ var EditPage = React.createClass({
</Nav.section> </Nav.section>
<Nav.section> <Nav.section>
{this.renderSaveButton()}
<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>

View File

@@ -86,7 +86,7 @@ var NewPage = React.createClass({
renderSaveButton : function(){ renderSaveButton : function(){
if(this.state.isSaving){ if(this.state.isSaving){
return <Nav.item icon='fa-spinner sa-spin' className='saveButton'> return <Nav.item icon='fa-spinner fa-spin' className='saveButton'>
save... save...
</Nav.item> </Nav.item>
}else{ }else{

View File

@@ -5,6 +5,8 @@ var cx = require('classnames');
var Nav = require('naturalcrit/nav/nav.jsx'); var Nav = require('naturalcrit/nav/nav.jsx');
var Navbar = require('../../navbar/navbar.jsx'); var Navbar = require('../../navbar/navbar.jsx');
var PrintLink = require('../../navbar/print.navitem.jsx');
var BrewRenderer = require('../../brewRenderer/brewRenderer.jsx'); var BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
var replaceAll = function(str, find, replace) { var replaceAll = function(str, find, replace) {
@@ -34,9 +36,6 @@ var SharePage = React.createClass({
render : function(){ render : function(){
console.log('brew', this.props.brew);
return <div className='sharePage page'> return <div className='sharePage page'>
<Navbar> <Navbar>
<Nav.section> <Nav.section>
@@ -44,9 +43,7 @@ var SharePage = React.createClass({
</Nav.section> </Nav.section>
<Nav.section> <Nav.section>
<Nav.item newTab={true} href={'/homebrew/print/' + this.props.brew.sharedId} color='orange' icon='fa-print'> <PrintLink shareId={this.props.brew.shareId} />
print
</Nav.item>
<Nav.item onClick={this.openSourceWindow} color='teal' icon='fa-code'> <Nav.item onClick={this.openSourceWindow} color='teal' icon='fa-code'>
source source
</Nav.item> </Nav.item>