1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-27 08:40:10 +02:00

add error modal when js preview not working

This commit is contained in:
Kushagra Gour
2022-09-08 09:41:26 +05:30
parent 2f40d21bae
commit 03489400e4
2 changed files with 95 additions and 42 deletions

View File

@@ -14,6 +14,7 @@ import { trackEvent } from '../analytics';
import { Console } from './Console'; import { Console } from './Console';
import CssSettingsModal from './CssSettingsModal'; import CssSettingsModal from './CssSettingsModal';
import { PreviewDimension } from './PreviewDimension.jsx'; import { PreviewDimension } from './PreviewDimension.jsx';
import Modal from './Modal.jsx';
const minCodeWrapSize = 33; const minCodeWrapSize = 33;
/* global htmlCodeEl /* global htmlCodeEl
@@ -25,6 +26,7 @@ export default class ContentWrap extends Component {
this.state = { this.state = {
isConsoleOpen: false, isConsoleOpen: false,
isCssSettingsModalOpen: false, isCssSettingsModalOpen: false,
isPreviewNotWorkingModalVisible: false,
logs: [] logs: []
}; };
@@ -43,19 +45,21 @@ export default class ContentWrap extends Component {
// `clearConsole` is on window because it gets called from inside iframe also. // `clearConsole` is on window because it gets called from inside iframe also.
window.clearConsole = this.clearConsole.bind(this); window.clearConsole = this.clearConsole.bind(this);
this.consoleHeaderDblClickHandler = this.consoleHeaderDblClickHandler.bind( this.consoleHeaderDblClickHandler =
this this.consoleHeaderDblClickHandler.bind(this);
); this.clearConsoleBtnClickHandler =
this.clearConsoleBtnClickHandler = this.clearConsoleBtnClickHandler.bind( this.clearConsoleBtnClickHandler.bind(this);
this
);
this.toggleConsole = this.toggleConsole.bind(this); this.toggleConsole = this.toggleConsole.bind(this);
this.evalConsoleExpr = this.evalConsoleExpr.bind(this); this.evalConsoleExpr = this.evalConsoleExpr.bind(this);
this.dismissPreviewNotWorkingModal =
this.dismissPreviewNotWorkingModal.bind(this);
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
return ( return (
this.state.isConsoleOpen !== nextState.isConsoleOpen || this.state.isConsoleOpen !== nextState.isConsoleOpen ||
this.state.isCssSettingsModalOpen !== nextState.isCssSettingsModalOpen || this.state.isCssSettingsModalOpen !== nextState.isCssSettingsModalOpen ||
this.state.isPreviewNotWorkingModalVisible !==
nextState.isPreviewNotWorkingModalVisible ||
this.state.logs !== nextState.logs || this.state.logs !== nextState.logs ||
this.state.codeSplitSizes !== nextState.codeSplitSizes || this.state.codeSplitSizes !== nextState.codeSplitSizes ||
this.state.mainSplitSizes !== nextState.mainSplitSizes || this.state.mainSplitSizes !== nextState.mainSplitSizes ||
@@ -127,8 +131,12 @@ export default class ContentWrap extends Component {
} }
createPreviewFile(html, css, js) { createPreviewFile(html, css, js) {
const versionMatch = navigator.userAgent.match(/Chrome\/(\d+)/);
const shouldInlineJs = const shouldInlineJs =
!window.webkitRequestFileSystem || !window.IS_EXTENSION; !window.webkitRequestFileSystem ||
!window.IS_EXTENSION ||
(versionMatch && +versionMatch[1] >= 104);
var contents = getCompleteHtml( var contents = getCompleteHtml(
html, html,
css, css,
@@ -278,6 +286,19 @@ export default class ContentWrap extends Component {
this.showErrors(resultItem.errors.lang, resultItem.errors.data); this.showErrors(resultItem.errors.lang, resultItem.errors.data);
} }
}); });
const versionMatch = navigator.userAgent.match(/Chrome\/(\d+)/);
if (
result[2].code &&
versionMatch &&
+versionMatch[1] >= 104 &&
window.IS_EXTENSION &&
!window.sessionStorage.getItem('previewErrorMessageDismissed')
) {
this.setState({
isPreviewNotWorkingModalVisible: true
});
}
}); });
} }
@@ -320,7 +341,8 @@ export default class ContentWrap extends Component {
window.editorThemeLinkTag.href = `lib/codemirror/theme/${prefs.editorTheme}.css`; window.editorThemeLinkTag.href = `lib/codemirror/theme/${prefs.editorTheme}.css`;
} }
window.fontStyleTag.textContent = window.fontStyleTemplate.textContent.replace( window.fontStyleTag.textContent =
window.fontStyleTemplate.textContent.replace(
/fontname/g, /fontname/g,
(prefs.editorFont === 'other' (prefs.editorFont === 'other'
? prefs.editorCustomFont ? prefs.editorCustomFont
@@ -481,7 +503,8 @@ export default class ContentWrap extends Component {
codeModeChangeHandler(e) { codeModeChangeHandler(e) {
var mode = e.target.value; var mode = e.target.value;
var type = e.target.dataset.type; var type = e.target.dataset.type;
var currentMode = this.props.currentItem[ var currentMode =
this.props.currentItem[
type === 'html' ? 'htmlMode' : type === 'css' ? 'cssMode' : 'jsMode' type === 'html' ? 'htmlMode' : type === 'css' ? 'cssMode' : 'jsMode'
]; ];
if (currentMode !== mode) { if (currentMode !== mode) {
@@ -604,6 +627,13 @@ export default class ContentWrap extends Component {
this.props.onPrettifyBtnClick(codeType); this.props.onPrettifyBtnClick(codeType);
} }
dismissPreviewNotWorkingModal() {
this.setState({
isPreviewNotWorkingModalVisible: false
});
window.sessionStorage.setItem('previewErrorMessageDismissed', true);
}
render() { render() {
// log('contentwrap update'); // log('contentwrap update');
@@ -892,6 +922,34 @@ export default class ContentWrap extends Component {
settings={this.props.currentItem.cssSettings} settings={this.props.currentItem.cssSettings}
editorTheme={this.props.prefs.editorTheme} editorTheme={this.props.prefs.editorTheme}
/> />
<Modal
show={this.state.isPreviewNotWorkingModalVisible}
closeHandler={this.dismissPreviewNotWorkingModal}
>
<h1>🔴 JavaScript preview not working!</h1>
<p>
Latest version of Chrome has changed a few things because of which
JavaScript preview has stopped working.
</p>
<p>
If you want to work with just HTML & CSS, you can still continue
here. Otherwise, it is recommended to switch to the Web Maker web
app which is much more powerful and works offline too -{' '}
<a href="https://webmaker.app/app" target="_blank">
Go to web app
</a>
</p>
<div class="flex flex-h-end">
<button
class="btn btn--primary"
onClick={this.dismissPreviewNotWorkingModal}
>
Dismiss
</button>
</div>
</Modal>
</div> </div>
</SplitPane> </SplitPane>
); );

View File

@@ -102,12 +102,7 @@ export function log() {
if (window.DEBUG) { if (window.DEBUG) {
const err = new Error(); const err = new Error();
console.log( console.log(
parseInt( parseInt(Date.now().toString().substr(4), 10),
Date.now()
.toString()
.substr(4),
10
),
...arguments, ...arguments,
err.stack.split('\n')[2].replace(/\(.*\)/, '') err.stack.split('\n')[2].replace(/\(.*\)/, '')
); );
@@ -399,7 +394,7 @@ export function getCompleteHtml(html, css, js, item, isForExport) {
} }
if (typeof js === 'string') { if (typeof js === 'string') {
contents += '<script>\n' + js + '\n//# sourceURL=userscript.js'; contents += js ? '<script>\n' + js + '\n//# sourceURL=userscript.js' : '';
} else { } else {
var origin = chrome.i18n.getMessage() var origin = chrome.i18n.getMessage()
? `chrome-extension://${chrome.i18n.getMessage('@@extension_id')}` ? `chrome-extension://${chrome.i18n.getMessage('@@extension_id')}`