0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 14:12:40 +00:00

Merge branch 'master' into api-tests

This commit is contained in:
Charlie Humphreys
2023-01-05 23:02:43 -06:00
5 changed files with 30 additions and 27 deletions

View File

@@ -67,7 +67,8 @@ const NewPage = createClass({
}
localStorage.setItem(BREWKEY, brew.text);
localStorage.setItem(STYLEKEY, brew.style);
if(brew.style)
localStorage.setItem(STYLEKEY, brew.style);
localStorage.setItem(METAKEY, JSON.stringify({ 'renderer': brew.renderer, 'theme': brew.theme }));
},
componentWillUnmount : function() {

View File

@@ -29,9 +29,10 @@ const PrintPage = createClass({
getInitialState : function() {
return {
brew : {
text : this.props.brew.text || '',
style : this.props.brew.style || undefined,
renderer : this.props.brew.renderer || 'legacy'
text : this.props.brew.text || '',
style : this.props.brew.style || undefined,
renderer : this.props.brew.renderer || 'legacy',
theme : this.props.brew.theme || '5ePHB'
}
};
},
@@ -48,7 +49,7 @@ const PrintPage = createClass({
text : brewStorage,
style : styleStorage,
renderer : metaStorage?.renderer || 'legacy',
theme : metaStorage?.theme || '5ePHB'
theme : metaStorage?.theme || '5ePHB'
}
};
});

View File

@@ -407,7 +407,7 @@ if(isLocalEnvironment){
//Render the page
const templateFn = require('./../client/template.js');
app.use(asyncHandler(async (req, res, next)=>{
const brew = _.defaults(req.brew, DEFAULT_BREW);
// Create configuration object
const configuration = {
local : isLocalEnvironment,
@@ -417,7 +417,7 @@ app.use(asyncHandler(async (req, res, next)=>{
const props = {
version : require('./../package.json').version,
url : req.originalUrl,
brew : brew,
brew : req.brew,
brews : req.brews,
googleBrews : req.googleBrews,
account : req.account,

View File

@@ -1,30 +1,36 @@
const _ = require('lodash');
// Default brew properties in most cases
// Default properties for newly-created brews
const DEFAULT_BREW = {
title : '',
text : '',
editId : null,
shareId : null,
title : 'Untitled Brew',
style : undefined,
description : '',
editId : undefined,
shareId : undefined,
createdAt : undefined,
updatedAt : undefined,
renderer : 'V3',
theme : '5ePHB',
authors : [],
tags : [],
systems : [],
thumbnail : '',
published : false,
pageCount : 1,
theme : '5ePHB'
gDrive : false,
trashed : false
};
// Default brew properties for loading
const DEFAULT_BREW_LOAD = {};
_.defaults(DEFAULT_BREW_LOAD,
// Default values for older brews with missing properties
// e.g., missing "renderer" is assumed to be "legacy"
const DEFAULT_BREW_LOAD = _.defaults(
{
renderer : 'legacy',
published : true
renderer : 'legacy',
},
DEFAULT_BREW);
module.exports = {
DEFAULT_BREW,
DEFAULT_BREW_LOAD
};
};

View File

@@ -76,17 +76,12 @@ If you believe you should have access to this brew, ask the file owner to invite
throw 'Brew not found in Homebrewery database or Google Drive';
}
if(typeof stub?.tags === 'string') {
stub.tags = [];
}
// Clean up brew: fill in missing fields with defaults / fix old invalid values
stub.tags = stub.tags || undefined; // Clear empty strings
stub.renderer = stub.renderer || undefined; // Clear empty strings
stub = _.defaults(stub, DEFAULT_BREW_LOAD); // Fill in blank fields
// Use _.assignWith instead of _.defaults - does this need to be replicated at all other uses of _.defaults???
_.assignWith(stub, DEFAULT_BREW_LOAD, (objValue, srcValue)=>{
if(typeof objValue === 'boolean') return objValue;
return objValue || srcValue;
});
req.brew = stub;
next();
};
},