From 8c0b315eeb02e23f41d5d9e9a306e61fc9272f73 Mon Sep 17 00:00:00 2001 From: Kushagra Gour <chinchang457@gmail.com> Date: Mon, 4 Sep 2023 08:59:47 +0530 Subject: [PATCH] add query param code read mode --- src/components/app.jsx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/components/app.jsx b/src/components/app.jsx index 42c3207..d17aefd 100644 --- a/src/components/app.jsx +++ b/src/components/app.jsx @@ -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 {