0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-10 13:32:45 +00:00

Print page can now load from local storage

This commit is contained in:
Scott Tolksdorf
2016-11-14 21:31:01 -05:00
parent d7463ec28e
commit 6672dff938
7 changed files with 95 additions and 42 deletions

View File

@@ -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>

View 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;

View File

@@ -0,0 +1,3 @@
.printPage{
}