mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-01 17:22:42 +00:00
Use same brew object throughout
Rather than using separate `brewText` and `styleText` state variables when printing from /new, just load the files into the same `brew` object the rest of the page uses. Also load localstorage in the same way as on `/new` via BREWKEY and STYLEKEY for consistency, rather than passing it in as a separate `brew` item in localstorage
This commit is contained in:
@@ -274,7 +274,6 @@ const NewPage = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
print : function(){
|
print : function(){
|
||||||
localStorage.setItem('print', `<style>\n${this.state.brew.style}\n</style>\n\n${this.state.brew.text}`);
|
|
||||||
window.open('/print?dialog=true&local=print', '_blank');
|
window.open('/print?dialog=true&local=print', '_blank');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ const { Meta } = require('vitreum/headtags');
|
|||||||
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
|
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
|
||||||
const Markdown = require('naturalcrit/markdown.js');
|
const Markdown = require('naturalcrit/markdown.js');
|
||||||
|
|
||||||
|
const BREWKEY = 'homebrewery-new';
|
||||||
|
const STYLEKEY = 'homebrewery-new-style';
|
||||||
const METAKEY = 'homebrewery-new-meta';
|
const METAKEY = 'homebrewery-new-meta';
|
||||||
|
|
||||||
const PrintPage = createClass({
|
const PrintPage = createClass({
|
||||||
@@ -23,33 +25,42 @@ const PrintPage = createClass({
|
|||||||
|
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
brewText : this.props.brew.text,
|
brew : {
|
||||||
brewRenderer : this.props.brew.renderer
|
text : this.props.brew.text || '',
|
||||||
|
style : this.props.brew.style || undefined,
|
||||||
|
renderer : this.props.brew.renderer || 'legacy'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount : function() {
|
componentDidMount : function() {
|
||||||
if(this.props.query.local){
|
if(this.props.query.local == 'print'){
|
||||||
const localText = localStorage.getItem(prevProps.query.local);
|
const brewStorage = localStorage.getItem(BREWKEY);
|
||||||
const localRenderer = JSON.parse(localStorage.getItem(METAKEY)).renderer || 'legacy';
|
const styleStorage = localStorage.getItem(STYLEKEY);
|
||||||
this.setState((prevState, prevProps)=>({
|
const metaStorage = JSON.parse(localStorage.getItem(METAKEY));
|
||||||
brewText : localText,
|
|
||||||
brewRenderer : localRenderer
|
this.setState((prevState, prevProps)=>{
|
||||||
}
|
return {
|
||||||
}));
|
brew : {
|
||||||
|
text : brewStorage,
|
||||||
|
style : styleStorage,
|
||||||
|
renderer : metaStorage.renderer || 'legacy'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.props.query.dialog) window.print();
|
if(this.props.query.dialog) window.print();
|
||||||
},
|
},
|
||||||
|
|
||||||
renderStyle : function() {
|
renderStyle : function() {
|
||||||
if(!this.props.brew.style) return;
|
if(!this.state.brew.style) return;
|
||||||
return <div style={{ display: 'none' }} dangerouslySetInnerHTML={{ __html: `<style> ${this.props.brew.style} </style>` }} />;
|
return <div style={{ display: 'none' }} dangerouslySetInnerHTML={{ __html: `<style> ${this.state.brew.style} </style>` }} />;
|
||||||
},
|
},
|
||||||
|
|
||||||
renderPages : function(){
|
renderPages : function(){
|
||||||
if(this.state.brewRenderer == 'legacy') {
|
if(this.state.brew.renderer == 'legacy') {
|
||||||
return _.map(this.state.brewText.split('\\page'), (pageText, index)=>{
|
return _.map(this.state.brew.text.split('\\page'), (pageText, index)=>{
|
||||||
return <div
|
return <div
|
||||||
className='phb page'
|
className='phb page'
|
||||||
id={`p${index + 1}`}
|
id={`p${index + 1}`}
|
||||||
@@ -57,7 +68,7 @@ const PrintPage = createClass({
|
|||||||
key={index} />;
|
key={index} />;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return _.map(this.state.brewText.split(/^\\page$/gm), (pageText, index)=>{
|
return _.map(this.state.brew.text.split(/^\\page$/gm), (pageText, index)=>{
|
||||||
pageText += `\n\n \n\\column\n `; //Artificial column break at page end to emulate column-fill:auto (until `wide` is used, when column-fill:balance will reappear)
|
pageText += `\n\n \n\\column\n `; //Artificial column break at page end to emulate column-fill:auto (until `wide` is used, when column-fill:balance will reappear)
|
||||||
return (
|
return (
|
||||||
<div className='page' id={`p${index + 1}`} key={index} >
|
<div className='page' id={`p${index + 1}`} key={index} >
|
||||||
@@ -72,7 +83,7 @@ const PrintPage = createClass({
|
|||||||
render : function(){
|
render : function(){
|
||||||
return <div>
|
return <div>
|
||||||
<Meta name='robots' content='noindex, nofollow' />
|
<Meta name='robots' content='noindex, nofollow' />
|
||||||
<link href={`${this.state.brewRenderer == 'legacy' ? '/themes/5ePhbLegacy.style.css' : '/themes/5ePhb.style.css'}`} rel='stylesheet'/>
|
<link href={`${this.state.brew.renderer == 'legacy' ? '/themes/5ePhbLegacy.style.css' : '/themes/5ePhb.style.css'}`} rel='stylesheet'/>
|
||||||
{/* Apply CSS from Style tab */}
|
{/* Apply CSS from Style tab */}
|
||||||
{this.renderStyle()}
|
{this.renderStyle()}
|
||||||
<div className='pages' ref='pages'>
|
<div className='pages' ref='pages'>
|
||||||
|
|||||||
Reference in New Issue
Block a user