0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-28 11:22:39 +00:00

Load theme bundles on /share page

This commit is contained in:
Trevor Buckner
2024-07-23 16:26:33 -04:00
parent 6ae249a527
commit 0b01f27d11

View File

@@ -18,18 +18,38 @@ const SharePage = createClass({
displayName : 'SharePage',
getDefaultProps : function() {
return {
brew : DEFAULT_BREW_LOAD
brew : DEFAULT_BREW_LOAD,
themeBundle : {}
};
},
getInitialState : function() {
return {
themeBundle : this.props.themeBundle
};
},
componentDidMount : function() {
document.addEventListener('keydown', this.handleControlKeys);
this.fetchThemeBundle(this.props.brew.renderer, this.props.brew.theme);
},
componentWillUnmount : function() {
document.removeEventListener('keydown', this.handleControlKeys);
},
// 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
}));
});
},
handleControlKeys : function(e){
if(!(e.ctrlKey || e.metaKey)) return;
const P_KEY = 80;
@@ -99,7 +119,7 @@ const SharePage = createClass({
style={this.props.brew.style}
renderer={this.props.brew.renderer}
theme={this.props.brew.theme}
userThemes={this.props.userThemes}
themeBundle={this.state.themeBundle}
allowPrint={true}
/>
</div>