mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-22 13:57:51 +00:00
Refactor ErrorNavItem to not need "this" parameter
Toward making edit/new/home pages functional, which do not have "this"
This commit is contained in:
@@ -1,32 +1,14 @@
|
||||
require('./error-navitem.less');
|
||||
const React = require('react');
|
||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||
const createClass = require('create-react-class');
|
||||
|
||||
const ErrorNavItem = createClass({
|
||||
getDefaultProps : function() {
|
||||
return {
|
||||
error : '',
|
||||
parent : null
|
||||
};
|
||||
},
|
||||
render : function() {
|
||||
const clearError = ()=>{
|
||||
const state = {
|
||||
error : null
|
||||
};
|
||||
if(this.props.parent.state.isSaving) {
|
||||
state.isSaving = false;
|
||||
}
|
||||
this.props.parent.setState(state);
|
||||
};
|
||||
|
||||
const error = this.props.error;
|
||||
const ErrorNavItem = ({error = '', clearError})=>{
|
||||
const response = error.response;
|
||||
const status = response?.status;
|
||||
const errorCode = error.code
|
||||
const status = response?.status;
|
||||
const HBErrorCode = response?.body?.HBErrorCode;
|
||||
const message = response?.body?.message;
|
||||
|
||||
let errMsg = '';
|
||||
try {
|
||||
errMsg += `${error.toString()}\n\n`;
|
||||
@@ -151,7 +133,6 @@ const ErrorNavItem = createClass({
|
||||
</a>.
|
||||
</div>
|
||||
</Nav.item>;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = ErrorNavItem;
|
||||
|
||||
@@ -438,6 +438,13 @@ const EditPage = createClass({
|
||||
return `https://www.reddit.com/r/UnearthedArcana/submit?title=${encodeURIComponent(title.toWellFormed())}&text=${encodeURIComponent(text)}`;
|
||||
},
|
||||
|
||||
clearError : function(){
|
||||
setState({
|
||||
error : null,
|
||||
isSaving : false
|
||||
})
|
||||
},
|
||||
|
||||
renderNavbar : function(){
|
||||
const shareLink = this.processShareId();
|
||||
|
||||
@@ -449,7 +456,7 @@ const EditPage = createClass({
|
||||
<Nav.section>
|
||||
{this.renderGoogleDriveIcon()}
|
||||
{this.state.error ?
|
||||
<ErrorNavItem error={this.state.error} parent={this}></ErrorNavItem> :
|
||||
<ErrorNavItem error={this.state.error} clearError={clearError}></ErrorNavItem> :
|
||||
<Nav.dropdown className='save-menu'>
|
||||
{this.renderSaveButton()}
|
||||
{this.renderAutoSaveButton()}
|
||||
|
||||
@@ -80,11 +80,19 @@ const HomePage = createClass({
|
||||
brew : { ...prevState.brew, text: text },
|
||||
}));
|
||||
},
|
||||
|
||||
clearError : function(){
|
||||
setState({
|
||||
error : null,
|
||||
isSaving : false
|
||||
})
|
||||
},
|
||||
|
||||
renderNavbar : function(){
|
||||
return <Navbar ver={this.props.ver}>
|
||||
<Nav.section>
|
||||
{this.state.error ?
|
||||
<ErrorNavItem error={this.state.error} parent={this}></ErrorNavItem> :
|
||||
<ErrorNavItem error={this.state.error} clearError={clearError}></ErrorNavItem> :
|
||||
null
|
||||
}
|
||||
<NewBrewItem />
|
||||
|
||||
@@ -211,6 +211,13 @@ const NewPage = createClass({
|
||||
}
|
||||
},
|
||||
|
||||
clearError : function(){
|
||||
setState({
|
||||
error : null,
|
||||
isSaving : false
|
||||
})
|
||||
},
|
||||
|
||||
renderNavbar : function(){
|
||||
return <Navbar>
|
||||
|
||||
@@ -220,7 +227,7 @@ const NewPage = createClass({
|
||||
|
||||
<Nav.section>
|
||||
{this.state.error ?
|
||||
<ErrorNavItem error={this.state.error} parent={this}></ErrorNavItem> :
|
||||
<ErrorNavItem error={this.state.error} clearError={clearError}></ErrorNavItem> :
|
||||
this.renderSaveButton()
|
||||
}
|
||||
<PrintNavItem />
|
||||
|
||||
@@ -39,10 +39,14 @@ const UserPage = (props)=>{
|
||||
}] : [])
|
||||
];
|
||||
|
||||
const clearError = ()=>{
|
||||
setError(null);
|
||||
};
|
||||
|
||||
const navItems = (
|
||||
<Navbar>
|
||||
<Nav.section>
|
||||
{error && (<ErrorNavItem error={error} parent={null}></ErrorNavItem>)}
|
||||
{error && (<ErrorNavItem error={error} clearError={clearError}></ErrorNavItem>)}
|
||||
<NewBrew />
|
||||
<HelpNavItem />
|
||||
<VaultNavitem />
|
||||
|
||||
Reference in New Issue
Block a user