1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-04-21 03:01:52 +02:00

add query param code read mode

This commit is contained in:
Kushagra Gour 2023-09-04 08:59:47 +05:30
parent 4b2f5e03ee
commit 8c0b315eeb

View File

@ -82,6 +82,8 @@ const version = '5.0.3';
// Read forced settings as query parameters
window.forcedSettings = {};
window.codeHtml = '';
window.codeCss = '';
if (location.search) {
let match = location.search.replace(/^\?/, '').match(/settings=([^=]*)/);
if (match) {
@ -93,6 +95,14 @@ if (location.search) {
window.forcedSettings[pair[0]] = pair[1];
});
}
const params = new URLSearchParams(location.search);
window.codeHtml = params.get('html')
? decodeURIComponent(params.get('html'))
: '';
window.codeCss = params.get('css')
? decodeURIComponent(params.get('css'))
: '';
}
export default class App extends Component {
@ -121,7 +131,9 @@ export default class App extends Component {
prefs: {},
currentItem: {
title: '',
externalLibs: { js: '', css: '' }
externalLibs: { js: '', css: '' },
html: window.codeHtml,
css: window.codeCss
},
catalogs: {}
};
@ -219,11 +231,16 @@ export default class App extends Component {
}
}
);
// Get synced `preserveLastCode` setting to get back last code (or not).
db.getSettings(this.defaultSettings).then(result => {
if (result.preserveLastCode && lastCode) {
if (window.codeHtml || window.codeCss) {
log('Load item from query params', lastCode);
this.setCurrentItem(this.state.currentItem).then(() => {
this.refreshEditor();
});
} else if (result.preserveLastCode && lastCode) {
this.setState({ unsavedEditCount: 0 });
log('Load last unsaved item', lastCode);
this.setCurrentItem(lastCode).then(() => this.refreshEditor());
} else {