mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-01 13:02:43 +00:00
Print page can now load from local storage
This commit is contained in:
@@ -9,6 +9,7 @@ var EditPage = require('./pages/editPage/editPage.jsx');
|
||||
var SharePage = require('./pages/sharePage/sharePage.jsx');
|
||||
var NewPage = require('./pages/newPage/newPage.jsx');
|
||||
var ErrorPage = require('./pages/errorPage/errorPage.jsx');
|
||||
var PrintPage = require('./pages/printPage/printPage.jsx');
|
||||
|
||||
var Router;
|
||||
var Homebrew = React.createClass({
|
||||
@@ -32,35 +33,37 @@ var Homebrew = React.createClass({
|
||||
Router = CreateRouter({
|
||||
'/edit/:id' : (args) => {
|
||||
if(!this.props.brew.editId){
|
||||
return <ErrorPage ver={this.props.version} errorId={args.id}/>
|
||||
return <ErrorPage errorId={args.id}/>
|
||||
}
|
||||
|
||||
return <EditPage
|
||||
ver={this.props.version}
|
||||
id={args.id}
|
||||
brew={this.props.brew} />
|
||||
},
|
||||
|
||||
'/share/:id' : (args) => {
|
||||
if(!this.props.brew.shareId){
|
||||
return <ErrorPage ver={this.props.version} errorId={args.id}/>
|
||||
return <ErrorPage errorId={args.id}/>
|
||||
}
|
||||
|
||||
return <SharePage
|
||||
ver={this.props.version}
|
||||
id={args.id}
|
||||
brew={this.props.brew} />
|
||||
},
|
||||
'/changelog' : (args) => {
|
||||
return <SharePage
|
||||
ver={this.props.version}
|
||||
brew={{title : 'Changelog', text : this.props.changelog}} />
|
||||
},
|
||||
'/print/:id' : (args, query) => {
|
||||
return <PrintPage brew={this.props.brew} query={query}/>;
|
||||
},
|
||||
'/print' : (args, query) => {
|
||||
return <PrintPage query={query}/>;
|
||||
},
|
||||
'/new' : (args) => {
|
||||
return <NewPage ver={this.props.version} />
|
||||
return <NewPage />
|
||||
},
|
||||
'*' : <HomePage
|
||||
ver={this.props.version}
|
||||
welcomeText={this.props.welcomeText} />,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
.homebrew{
|
||||
height : 100%;
|
||||
|
||||
//TODO: Consider making backgroudn color lighter
|
||||
background-color : @steel;
|
||||
.page{
|
||||
display : flex;
|
||||
height : 100%;
|
||||
background-color : @steel;
|
||||
flex-direction : column;
|
||||
.content{
|
||||
position : relative;
|
||||
|
||||
@@ -91,6 +91,17 @@ const NewPage = React.createClass({
|
||||
}
|
||||
},
|
||||
|
||||
handlePrintClick : 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.handlePrintClick}>
|
||||
get PDF
|
||||
</Nav.item>
|
||||
},
|
||||
|
||||
renderNavbar : function(){
|
||||
return <Navbar ver={this.props.ver}>
|
||||
<Nav.section>
|
||||
@@ -99,6 +110,7 @@ const NewPage = React.createClass({
|
||||
|
||||
<Nav.section>
|
||||
{this.renderSaveButton()}
|
||||
{this.renderLocalPrintButton()}
|
||||
<IssueNavItem />
|
||||
</Nav.section>
|
||||
</Navbar>
|
||||
|
||||
50
client/homebrew/pages/printPage/printPage.jsx
Normal file
50
client/homebrew/pages/printPage/printPage.jsx
Normal file
@@ -0,0 +1,50 @@
|
||||
const React = require('react');
|
||||
const _ = require('lodash');
|
||||
const cx = require('classnames');
|
||||
|
||||
//const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
||||
|
||||
var Markdown = require('naturalcrit/markdown.js');
|
||||
|
||||
const PrintPage = React.createClass({
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
query : {},
|
||||
brew : {
|
||||
text : '',
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
brewText: this.props.brew.text
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
if(this.props.query.local){
|
||||
this.setState({ brewText : localStorage.getItem(this.props.query.local)});
|
||||
}
|
||||
|
||||
if(this.props.query.dialog) window.print();
|
||||
},
|
||||
|
||||
renderPages : function(){
|
||||
return _.map(this.state.brewText.split('\\page'), (page, index) => {
|
||||
return <div
|
||||
className='phb'
|
||||
id={`p${index + 1}`}
|
||||
dangerouslySetInnerHTML={{__html:Markdown.render(page)}}
|
||||
key={index} />;
|
||||
});
|
||||
},
|
||||
|
||||
render : function(){
|
||||
return <div>
|
||||
{this.renderPages()}
|
||||
</div>
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = PrintPage;
|
||||
3
client/homebrew/pages/printPage/printPage.less
Normal file
3
client/homebrew/pages/printPage/printPage.less
Normal file
@@ -0,0 +1,3 @@
|
||||
.printPage{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user