0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-03 17:02:40 +00:00
This commit is contained in:
Trevor Buckner
2024-07-22 02:46:26 -04:00
parent c0123b96eb
commit 6ae249a527
5 changed files with 20 additions and 21 deletions

View File

@@ -111,7 +111,7 @@ const MetadataEditor = createClass({
handleTheme : function(theme){ handleTheme : function(theme){
this.props.metadata.renderer = theme.renderer; this.props.metadata.renderer = theme.renderer;
this.props.metadata.theme = theme.path; this.props.metadata.theme = theme.path;
this.props.onChange(this.props.metadata, "theme"); this.props.onChange(this.props.metadata, 'theme');
}, },
handleLanguage : function(languageCode){ handleLanguage : function(languageCode){
@@ -212,7 +212,7 @@ const MetadataEditor = createClass({
}; };
const currentThemePath = this.props.metadata?.theme && Themes[_.upperFirst(this.props.metadata.renderer)]?.hasOwnProperty(this.props.metadata?.theme) ? this.props.metadata.renderer : 'Brew'; const currentThemePath = this.props.metadata?.theme && Themes[_.upperFirst(this.props.metadata.renderer)]?.hasOwnProperty(this.props.metadata?.theme) ? this.props.metadata.renderer : 'Brew';
const currentTheme = mergedThemes[`${_.upperFirst(currentThemePath)}`]?.hasOwnProperty(this.props.metadata.theme) ? mergedThemes[`${_.upperFirst(currentThemePath)}`][this.props.metadata.theme] : { name: `!!! THEME MISSING !!! ID=${this.props.metadata.theme.slice(1)}`}; const currentTheme = mergedThemes[`${_.upperFirst(currentThemePath)}`]?.hasOwnProperty(this.props.metadata.theme) ? mergedThemes[`${_.upperFirst(currentThemePath)}`][this.props.metadata.theme] : { name: `!!! THEME MISSING !!! ID=${this.props.metadata.theme.slice(1)}` };
let dropdown; let dropdown;
if(this.props.metadata.renderer == 'legacy') { if(this.props.metadata.renderer == 'legacy') {

View File

@@ -51,7 +51,7 @@ const Snippetbar = createClass({
}, },
componentDidMount : async function() { componentDidMount : async function() {
let snippets = this.compileSnippets(); const snippets = this.compileSnippets();
this.setState({ this.setState({
snippets : snippets snippets : snippets
}); });
@@ -59,7 +59,7 @@ const Snippetbar = createClass({
componentDidUpdate : async function(prevProps) { componentDidUpdate : async function(prevProps) {
if(prevProps.renderer != this.props.renderer || prevProps.theme != this.props.theme || prevProps.snippetBundle != this.props.snippetBundle) { if(prevProps.renderer != this.props.renderer || prevProps.theme != this.props.theme || prevProps.snippetBundle != this.props.snippetBundle) {
let snippets = this.compileSnippets(); const snippets = this.compileSnippets();
this.setState({ this.setState({
snippets : snippets snippets : snippets
}); });
@@ -78,12 +78,12 @@ const Snippetbar = createClass({
let compiledSnippets = []; let compiledSnippets = [];
let oldSnippets = _.keyBy(compiledSnippets, 'groupName'); let oldSnippets = _.keyBy(compiledSnippets, 'groupName');
for (let snippets of this.props.snippetBundle) { for (let snippets of this.props.snippetBundle) {
if (typeof(snippets) == "string") // load staticThemes as needed; they were sent as just a file name if(typeof(snippets) == 'string') // load staticThemes as needed; they were sent as just a file name
snippets = ThemeSnippets[snippets]; snippets = ThemeSnippets[snippets];
let newSnippets = _.keyBy(_.cloneDeep(snippets), 'groupName'); const newSnippets = _.keyBy(_.cloneDeep(snippets), 'groupName');
compiledSnippets = _.values(_.mergeWith(oldSnippets, newSnippets, this.mergeCustomizer)); compiledSnippets = _.values(_.mergeWith(oldSnippets, newSnippets, this.mergeCustomizer));
oldSnippets = _.keyBy(compiledSnippets, 'groupName'); oldSnippets = _.keyBy(compiledSnippets, 'groupName');

View File

@@ -134,9 +134,9 @@ const EditPage = createClass({
}, },
handleMetaChange : function(metadata, field=undefined){ handleMetaChange : function(metadata, field=undefined){
if(field == "theme") // Fetch theme bundle only if theme was changed if(field == 'theme') // Fetch theme bundle only if theme was changed
this.fetchThemeBundle(metadata.renderer, metadata.theme); this.fetchThemeBundle(metadata.renderer, metadata.theme);
this.setState((prevState)=>({ this.setState((prevState)=>({
brew : { brew : {
...prevState.brew, ...prevState.brew,
@@ -153,13 +153,13 @@ const EditPage = createClass({
// Loads the theme bundle and parses it out. Called when the iFrame is first mounted, and when a new theme is selected // Loads the theme bundle and parses it out. Called when the iFrame is first mounted, and when a new theme is selected
fetchThemeBundle : function(renderer, theme) { fetchThemeBundle : function(renderer, theme) {
fetch(`${window.location.protocol}//${window.location.host}/theme/${renderer}/${theme}`).then((response)=>response.json()).then((themeBundle)=>{ fetch(`${window.location.protocol}//${window.location.host}/theme/${renderer}/${theme}`).then((response)=>response.json()).then((themeBundle)=>{
themeBundle.joinedStyles = themeBundle.styles.map(style => `<style>${style}</style>`).join('\n\n'); //DOMPurify.sanitize(joinedStyles, purifyConfig); themeBundle.joinedStyles = themeBundle.styles.map((style)=>`<style>${style}</style>`).join('\n\n'); //DOMPurify.sanitize(joinedStyles, purifyConfig);
this.setState((prevState)=>({ // MOVE TO MOUNT STEP OF SHARE / NEW / EDIT this.setState((prevState)=>({ // MOVE TO MOUNT STEP OF SHARE / NEW / EDIT
...prevState, ...prevState,
themeBundle : themeBundle themeBundle : themeBundle
})); }));
}); });
}, },
trySave : function(immediate=false){ trySave : function(immediate=false){

View File

@@ -61,7 +61,7 @@ const api = {
const userThemes = {}; const userThemes = {};
const brews = await HomebrewModel.getByUser(username, true, fields, { tags: { $in: ['meta:theme', 'meta:Theme'] }}); const brews = await HomebrewModel.getByUser(username, true, fields, { tags: { $in: ['meta:theme', 'meta:Theme'] } });
if(brews) { if(brews) {
for (const brew of brews) { for (const brew of brews) {
@@ -269,7 +269,6 @@ const api = {
const completeSnippets = []; const completeSnippets = [];
while (req.params.id) { while (req.params.id) {
console.log(`loading theme ID ${req.params.id}`)
//=== User Themes ===// //=== User Themes ===//
if(!isStaticTheme(req.params.renderer, req.params.id)) { if(!isStaticTheme(req.params.renderer, req.params.id)) {
await api.getBrew('share')(req, res, ()=>{}); await api.getBrew('share')(req, res, ()=>{});
@@ -282,7 +281,7 @@ const api = {
req.params.id = currentTheme.theme; req.params.id = currentTheme.theme;
req.params.renderer = currentTheme.renderer; req.params.renderer = currentTheme.renderer;
} }
//=== Static Themes ===// //=== Static Themes ===//
else { else {
const localSnippets = `${req.params.renderer}_${req.params.id}`; // Just log the name for loading on client const localSnippets = `${req.params.renderer}_${req.params.id}`; // Just log the name for loading on client

View File

@@ -288,14 +288,14 @@ describe('Tests for api', ()=>{
textBin : undefined, textBin : undefined,
version : undefined, version : undefined,
userThemes : { userThemes : {
Brew: {} Brew : {}
}, },
createdAt : undefined, createdAt : undefined,
gDrive : false, gDrive : false,
style : undefined, style : undefined,
trashed : false, trashed : false,
updatedAt : undefined, updatedAt : undefined,
views : 0 views : 0
}); });
expect(next).toHaveBeenCalled(); expect(next).toHaveBeenCalled();
expect(api.getId).toHaveBeenCalledWith(req); expect(api.getId).toHaveBeenCalledWith(req);