0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-09 09:22:38 +00:00

Get renderer information from localStorage when printing from /new

Default to `legacy`.
This commit is contained in:
Sean Robertson
2021-10-01 13:31:09 +13:00
parent 2401993018
commit 41c1b04f0e

View File

@@ -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 METAKEY = 'homebrewery-new-meta';
const PrintPage = createClass({ const PrintPage = createClass({
getDefaultProps : function() { getDefaultProps : function() {
return { return {
@@ -21,14 +23,19 @@ const PrintPage = createClass({
getInitialState : function() { getInitialState : function() {
return { return {
brewText : this.props.brew.text brewText : this.props.brew.text,
brewRenderer : this.props.brew.renderer
}; };
}, },
componentDidMount : function() { componentDidMount : function() {
if(this.props.query.local){ if(this.props.query.local){
const localText = localStorage.getItem(prevProps.query.local);
const localRenderer = JSON.stringify(localStorage.getItem(METAKEY)).renderer || 'legacy';
this.setState((prevState, prevProps)=>({ this.setState((prevState, prevProps)=>({
brewText : localStorage.getItem(prevProps.query.local) brewText : localText,
brewRenderer : localRenderer
}
})); }));
} }
@@ -41,7 +48,7 @@ const PrintPage = createClass({
}, },
renderPages : function(){ renderPages : function(){
if(this.props.brew.renderer == 'legacy') { if(this.state.brewRenderer == 'legacy') {
return _.map(this.state.brewText.split('\\page'), (pageText, index)=>{ return _.map(this.state.brewText.split('\\page'), (pageText, index)=>{
return <div return <div
className='phb page' className='phb page'
@@ -65,7 +72,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.props.brew.renderer == 'legacy' ? '/themes/5ePhbLegacy.style.css' : '/themes/5ePhb.style.css'}`} rel='stylesheet'/> <link href={`${this.state.brewRenderer == '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'>