mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-14 02:02:51 +00:00
newPage is now working, working on editpage
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
const flux = require('pico-flux')
|
||||
const React = require('react');
|
||||
const _ = require('lodash');
|
||||
const cx = require('classnames');
|
||||
|
||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||
|
||||
const Store = require('homebrewery/brew.store.js');
|
||||
const Actions = require('homebrewery/brew.actions.js');
|
||||
|
||||
const onStoreChange = () => {
|
||||
return {
|
||||
status : Store.getStatus(),
|
||||
errors : Store.getErrors()
|
||||
}
|
||||
};
|
||||
|
||||
const ContinousSave = React.createClass({
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
status : 'ready',
|
||||
errors : undefined
|
||||
};
|
||||
},
|
||||
componentDidMount: function() {
|
||||
flux.actionEmitter.on('dispatch', this.actionHandler);
|
||||
window.onbeforeunload = ()=>{
|
||||
if(this.props.status !== 'ready') return 'You have unsaved changes!';
|
||||
};
|
||||
},
|
||||
componentWillUnmount: function() {
|
||||
flux.actionEmitter.removeListener('dispatch', this.actionHandler);
|
||||
window.onbeforeunload = function(){};
|
||||
},
|
||||
actionHandler : function(actionType){
|
||||
if(actionType == 'UPDATE_BREW_TEXT' || actionType == 'UPDATE_META'){
|
||||
Actions.pendingSave();
|
||||
}
|
||||
},
|
||||
handleClick : function(){
|
||||
Actions.save();
|
||||
},
|
||||
renderError : function(){
|
||||
let errMsg = '';
|
||||
try{
|
||||
errMsg += this.state.errors.toString() + '\n\n';
|
||||
errMsg += '```\n' + JSON.stringify(this.state.errors.response.error, null, ' ') + '\n```';
|
||||
}catch(e){}
|
||||
|
||||
return <Nav.item className='continousSave error' icon="fa-warning">
|
||||
Oops!
|
||||
<div className='errorContainer'>
|
||||
Looks like there was a problem saving. <br />
|
||||
Report the issue <a target='_blank' href={'https://github.com/stolksdorf/naturalcrit/issues/new?body='+ encodeURIComponent(errMsg)}>
|
||||
here
|
||||
</a>.
|
||||
</div>
|
||||
</Nav.item>
|
||||
},
|
||||
render : function(){
|
||||
if(this.props.status == 'error') return this.renderError();
|
||||
|
||||
if(this.props.status == 'saving'){
|
||||
return <Nav.item className='continousSave' icon="fa-spinner fa-spin">saving...</Nav.item>
|
||||
}
|
||||
if(this.props.status == 'pending'){
|
||||
return <Nav.item className='continousSave' onClick={this.handleClick} color='blue' icon='fa-save'>Save Now</Nav.item>
|
||||
}
|
||||
if(this.props.status == 'ready'){
|
||||
return <Nav.item className='continousSave saved'>saved.</Nav.item>
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
module.exports = Store.createSmartComponent(ContinousSave, onStoreChange);
|
||||
@@ -125,4 +125,11 @@
|
||||
text-align : center;
|
||||
}
|
||||
}
|
||||
|
||||
.staticSave.navItem{
|
||||
background-color: @orange;
|
||||
&:hover{
|
||||
background-color: @green;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
client/homebrew/navbar/staticSave.navitem.jsx
Normal file
37
client/homebrew/navbar/staticSave.navitem.jsx
Normal file
@@ -0,0 +1,37 @@
|
||||
const React = require('react');
|
||||
const _ = require('lodash');
|
||||
const cx = require('classnames');
|
||||
|
||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||
const Store = require('homebrewery/brew.store.js');
|
||||
const Actions = require('homebrewery/brew.actions.js');
|
||||
|
||||
const StaticSave = React.createClass({
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
status : 'ready'
|
||||
};
|
||||
},
|
||||
handleClick : function(){
|
||||
Actions.saveNew();
|
||||
},
|
||||
render : function(){
|
||||
if(this.props.status === 'saving'){
|
||||
return <Nav.item icon='fa-spinner fa-spin' className='staticSave'>
|
||||
save...
|
||||
</Nav.item>
|
||||
}
|
||||
if(this.props.status === 'ready'){
|
||||
return <Nav.item icon='fa-save' className='staticSave' onClick={this.handleClick}>
|
||||
save
|
||||
</Nav.item>
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
module.exports = Store.createSmartComponent(StaticSave, ()=>{
|
||||
return {
|
||||
status : Store.getStatus()
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user