mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-02 06:22:43 +00:00
Merge importPage functions into newPage.
This commit is contained in:
committed by
Trevor Buckner
parent
ed23578dcf
commit
2f9bd00d70
@@ -9,7 +9,7 @@ const EditPage = require('./pages/editPage/editPage.jsx');
|
|||||||
const UserPage = require('./pages/userPage/userPage.jsx');
|
const UserPage = require('./pages/userPage/userPage.jsx');
|
||||||
const SharePage = require('./pages/sharePage/sharePage.jsx');
|
const SharePage = require('./pages/sharePage/sharePage.jsx');
|
||||||
const NewPage = require('./pages/newPage/newPage.jsx');
|
const NewPage = require('./pages/newPage/newPage.jsx');
|
||||||
const ImportPage = require('./pages/importPage/importPage.jsx');
|
//const ImportPage = require('./pages/importPage/importPage.jsx');
|
||||||
//const ErrorPage = require('./pages/errorPage/errorPage.jsx');
|
//const ErrorPage = require('./pages/errorPage/errorPage.jsx');
|
||||||
const PrintPage = require('./pages/printPage/printPage.jsx');
|
const PrintPage = require('./pages/printPage/printPage.jsx');
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ const Homebrew = createClass({
|
|||||||
<Switch>
|
<Switch>
|
||||||
<Route path='/edit/:id' component={(routeProps)=><EditPage id={routeProps.match.params.id} brew={this.props.brew} />}/>
|
<Route path='/edit/:id' component={(routeProps)=><EditPage id={routeProps.match.params.id} brew={this.props.brew} />}/>
|
||||||
<Route path='/share/:id' component={(routeProps)=><SharePage id={routeProps.match.params.id} brew={this.props.brew} />}/>
|
<Route path='/share/:id' component={(routeProps)=><SharePage id={routeProps.match.params.id} brew={this.props.brew} />}/>
|
||||||
<Route path='/new/:id' component={(routeProps)=><ImportPage id={routeProps.match.params.id} brew={this.props.brew} />}/>
|
<Route path='/new/:id' component={(routeProps)=><NewPage id={routeProps.match.params.id} brew={this.props.brew} />}/>
|
||||||
<Route path='/user/:username' component={(routeProps)=><UserPage username={routeProps.match.params.username} brews={this.props.brews} />}/>
|
<Route path='/user/:username' component={(routeProps)=><UserPage username={routeProps.match.params.username} brews={this.props.brews} />}/>
|
||||||
<Route path='/print/:id' component={(routeProps)=><PrintPage brew={this.props.brew} query={queryString.parse(routeProps.location.search)} /> } />
|
<Route path='/print/:id' component={(routeProps)=><PrintPage brew={this.props.brew} query={queryString.parse(routeProps.location.search)} /> } />
|
||||||
<Route path='/print' exact component={(routeProps)=><PrintPage query={queryString.parse(routeProps.location.search)} /> } />
|
<Route path='/print' exact component={(routeProps)=><PrintPage query={queryString.parse(routeProps.location.search)} /> } />
|
||||||
|
|||||||
@@ -1,207 +0,0 @@
|
|||||||
require('./importPage.less');
|
|
||||||
const React = require('react');
|
|
||||||
const createClass = require('create-react-class');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const request = require('superagent');
|
|
||||||
|
|
||||||
const Markdown = require('naturalcrit/markdown.js');
|
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
|
||||||
const Navbar = require('../../navbar/navbar.jsx');
|
|
||||||
const AccountNavItem = require('../../navbar/account.navitem.jsx');
|
|
||||||
const RecentNavItem = require('../../navbar/recent.navitem.jsx').both;
|
|
||||||
const IssueNavItem = require('../../navbar/issue.navitem.jsx');
|
|
||||||
|
|
||||||
const SplitPane = require('naturalcrit/splitPane/splitPane.jsx');
|
|
||||||
const Editor = require('../../editor/editor.jsx');
|
|
||||||
const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
|
||||||
|
|
||||||
|
|
||||||
const KEY = 'homebrewery-new';
|
|
||||||
|
|
||||||
const ImportPage = createClass({
|
|
||||||
getDefaultProps : function() {
|
|
||||||
return {
|
|
||||||
brew : {
|
|
||||||
text : '',
|
|
||||||
shareId : null,
|
|
||||||
editId : null,
|
|
||||||
createdAt : null,
|
|
||||||
updatedAt : null,
|
|
||||||
gDrive : false,
|
|
||||||
|
|
||||||
title : '',
|
|
||||||
description : '',
|
|
||||||
tags : '',
|
|
||||||
published : false,
|
|
||||||
authors : [],
|
|
||||||
systems : []
|
|
||||||
}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
getInitialState : function() {
|
|
||||||
return {
|
|
||||||
metadata : {
|
|
||||||
gDrive : false,
|
|
||||||
title : '',
|
|
||||||
description : '',
|
|
||||||
tags : '',
|
|
||||||
published : false,
|
|
||||||
authors : [],
|
|
||||||
systems : []
|
|
||||||
},
|
|
||||||
|
|
||||||
text : this.props.brew.text,
|
|
||||||
isSaving : false,
|
|
||||||
saveGoogle : (global.account && global.account.googleId ? true : false),
|
|
||||||
errors : []
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
componentDidMount : function() {
|
|
||||||
const storage = localStorage.getItem(KEY);
|
|
||||||
if(storage){
|
|
||||||
this.setState({
|
|
||||||
text : storage
|
|
||||||
});
|
|
||||||
}
|
|
||||||
document.addEventListener('keydown', this.handleControlKeys);
|
|
||||||
},
|
|
||||||
componentWillUnmount : function() {
|
|
||||||
document.removeEventListener('keydown', this.handleControlKeys);
|
|
||||||
},
|
|
||||||
|
|
||||||
handleControlKeys : function(e){
|
|
||||||
if(!(e.ctrlKey || e.metaKey)) return;
|
|
||||||
const S_KEY = 83;
|
|
||||||
const P_KEY = 80;
|
|
||||||
if(e.keyCode == S_KEY) this.save();
|
|
||||||
if(e.keyCode == P_KEY) this.print();
|
|
||||||
if(e.keyCode == P_KEY || e.keyCode == S_KEY){
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
handleSplitMove : function(){
|
|
||||||
this.refs.editor.update();
|
|
||||||
},
|
|
||||||
|
|
||||||
handleMetadataChange : function(metadata){
|
|
||||||
this.setState({
|
|
||||||
metadata : _.merge({}, this.state.metadata, metadata)
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
handleTextChange : function(text){
|
|
||||||
this.setState({
|
|
||||||
text : text,
|
|
||||||
errors : Markdown.validate(text)
|
|
||||||
});
|
|
||||||
localStorage.setItem(KEY, text);
|
|
||||||
},
|
|
||||||
|
|
||||||
save : async function(){
|
|
||||||
this.setState({
|
|
||||||
isSaving : true
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('saving new brew');
|
|
||||||
|
|
||||||
if(this.state.saveGoogle) {
|
|
||||||
const res = await request
|
|
||||||
.post('/api/newGoogle/')
|
|
||||||
.send(_.merge({}, this.state.metadata, { text: this.state.text }))
|
|
||||||
.catch((err)=>{
|
|
||||||
console.log(err.status === 401
|
|
||||||
? 'Not signed in!'
|
|
||||||
: 'Error Creating New Google Brew!');
|
|
||||||
this.setState({ isSaving: false });
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
|
|
||||||
const brew = res.body;
|
|
||||||
localStorage.removeItem(KEY);
|
|
||||||
window.location = `/edit/${brew.googleId}${brew.editId}`;
|
|
||||||
} else {
|
|
||||||
request.post('/api')
|
|
||||||
.send(_.merge({}, this.state.metadata, {
|
|
||||||
text : this.state.text
|
|
||||||
}))
|
|
||||||
.end((err, res)=>{
|
|
||||||
if(err){
|
|
||||||
this.setState({
|
|
||||||
isSaving : false
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
window.onbeforeunload = function(){};
|
|
||||||
const brew = res.body;
|
|
||||||
localStorage.removeItem(KEY);
|
|
||||||
window.location = `/edit/${brew.editId}`;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
renderSaveButton : function(){
|
|
||||||
if(this.state.isSaving){
|
|
||||||
return <Nav.item icon='fa-spinner fa-spin' className='saveButton'>
|
|
||||||
save...
|
|
||||||
</Nav.item>;
|
|
||||||
} else {
|
|
||||||
return <Nav.item icon='fa-save' className='saveButton' onClick={this.save}>
|
|
||||||
save
|
|
||||||
</Nav.item>;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
print : function(){
|
|
||||||
localStorage.setItem('print', this.state.text);
|
|
||||||
window.open('/print?dialog=true&local=print', '_blank');
|
|
||||||
},
|
|
||||||
|
|
||||||
renderLocalPrintButton : function(){
|
|
||||||
return <Nav.item color='purple' icon='fa-file-pdf-o' onClick={this.print}>
|
|
||||||
get PDF
|
|
||||||
</Nav.item>;
|
|
||||||
},
|
|
||||||
|
|
||||||
renderNavbar : function(){
|
|
||||||
return <Navbar>
|
|
||||||
|
|
||||||
<Nav.section>
|
|
||||||
<Nav.item className='brewTitle'>{this.state.metadata.title}</Nav.item>
|
|
||||||
</Nav.section>
|
|
||||||
|
|
||||||
<Nav.section>
|
|
||||||
{this.renderSaveButton()}
|
|
||||||
{this.renderLocalPrintButton()}
|
|
||||||
<IssueNavItem />
|
|
||||||
<RecentNavItem />
|
|
||||||
<AccountNavItem />
|
|
||||||
</Nav.section>
|
|
||||||
</Navbar>;
|
|
||||||
},
|
|
||||||
|
|
||||||
render : function(){
|
|
||||||
return <div className='importPage page'>
|
|
||||||
{this.renderNavbar()}
|
|
||||||
<div className='content'>
|
|
||||||
<SplitPane onDragFinish={this.handleSplitMove} ref='pane'>
|
|
||||||
<Editor
|
|
||||||
ref='editor'
|
|
||||||
value={this.state.text}
|
|
||||||
onChange={this.handleTextChange}
|
|
||||||
metadata={this.state.metadata}
|
|
||||||
onMetadataChange={this.handleMetadataChange}
|
|
||||||
/>
|
|
||||||
<BrewRenderer text={this.state.text} errors={this.state.errors} />
|
|
||||||
</SplitPane>
|
|
||||||
</div>
|
|
||||||
</div>;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = ImportPage;
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
.importPage{
|
|
||||||
|
|
||||||
.saveButton{
|
|
||||||
background-color: @orange;
|
|
||||||
&:hover{
|
|
||||||
background-color: @green;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -20,10 +20,30 @@ const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
|||||||
const KEY = 'homebrewery-new';
|
const KEY = 'homebrewery-new';
|
||||||
|
|
||||||
const NewPage = createClass({
|
const NewPage = createClass({
|
||||||
|
getDefaultProps : function() {
|
||||||
|
return {
|
||||||
|
brew : {
|
||||||
|
text : '',
|
||||||
|
shareId : null,
|
||||||
|
editId : null,
|
||||||
|
createdAt : null,
|
||||||
|
updatedAt : null,
|
||||||
|
gDrive : false,
|
||||||
|
|
||||||
|
title : '',
|
||||||
|
description : '',
|
||||||
|
tags : '',
|
||||||
|
published : false,
|
||||||
|
authors : [],
|
||||||
|
systems : []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
brew : {
|
brew : {
|
||||||
text : '',
|
text : this.props.brew.text,
|
||||||
gDrive : false,
|
gDrive : false,
|
||||||
title : '',
|
title : '',
|
||||||
description : '',
|
description : '',
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ app.get('/edit/:id', (req, res, next)=>{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Import Page
|
//New Page
|
||||||
app.get('/new/:id', (req, res, next)=>{
|
app.get('/new/:id', (req, res, next)=>{
|
||||||
res.header('Cache-Control', 'no-cache, no-store'); //reload the latest saved brew when pressing back button, not the cached version before save.
|
res.header('Cache-Control', 'no-cache, no-store'); //reload the latest saved brew when pressing back button, not the cached version before save.
|
||||||
if(req.params.id.length > 12) {
|
if(req.params.id.length > 12) {
|
||||||
|
|||||||
Reference in New Issue
Block a user