0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-13 17:22:49 +00:00

Move fetchThemeBundle into /shared/helpers

This might not be the best rework - I was unsure if the *this* that would be available when called would see the appropriate object so I assumed not and pass it as a parameter.
Works, but may be bad form.
This commit is contained in:
David Bolack
2024-07-23 22:17:52 -05:00
parent 8e7baca47d
commit d2afa7adea
5 changed files with 22 additions and 54 deletions

View File

@@ -13,6 +13,7 @@ const HelpNavItem = require('../../navbar/help.navitem.jsx');
const RecentNavItem = require('../../navbar/recent.navitem.jsx').both;
const AccountNavItem = require('../../navbar/account.navitem.jsx');
const ErrorNavItem = require('../../navbar/error-navitem.jsx');
const { fetchThemeBundle } = require('../../../../shared/helpers.js');
const SplitPane = require('naturalcrit/splitPane/splitPane.jsx');
@@ -42,18 +43,7 @@ const HomePage = createClass({
editor : React.createRef(null),
componentDidMount : function() {
this.fetchThemeBundle(this.props.brew.renderer, this.props.brew.theme);
},
// 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) {
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);
this.setState((prevState)=>({ // MOVE TO MOUNT STEP OF SHARE / NEW / EDIT
...prevState,
themeBundle : themeBundle
}));
});
fetchThemeBundle(this, this.props.brew.renderer, this.props.brew.theme);
},
handleSave : function(){