From aad4ad8eef69072fc485e81ecbbdaeaa9986bbd3 Mon Sep 17 00:00:00 2001 From: blurymind Date: Tue, 20 Aug 2024 17:46:54 +0100 Subject: [PATCH] persist plugin editor state more via url parameters --- src/public/plugins/index.js | 10 ++++++++++ src/public/plugins/plugin-editor.js | 13 ++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/public/plugins/index.js b/src/public/plugins/index.js index b1377306..d0f86021 100644 --- a/src/public/plugins/index.js +++ b/src/public/plugins/index.js @@ -267,6 +267,15 @@ export var Plugins = function (app) { const gistPluginsFileUrl = urlParams.get('pluginFile'); const pluginModeUrl = urlParams.get('mode'); + const updateUrlParams = (key, value) => { + const url = new URL(window.location.href); + if (value) { + url.searchParams.set(key, value); + } else { + url.searchParams.delete(key); + } + window.history.replaceState(null, null, url); // or pushState + } this.rawUrls = {}; const getGistPluginFiles = () => { return new Promise((resolve) => { @@ -417,6 +426,7 @@ const getFunctionBody = (func = ()=>{}) => { saveGistPlugin, isGistTokenInvalid, urlParams, + updateUrlParams, gistPluginsFileUrl, pluginModeUrl, getPluginsList, diff --git a/src/public/plugins/plugin-editor.js b/src/public/plugins/plugin-editor.js index 6e87277e..5b52dd8c 100644 --- a/src/public/plugins/plugin-editor.js +++ b/src/public/plugins/plugin-editor.js @@ -120,6 +120,7 @@ export var PluginEditor = function ({ gistPluginsFileUrl, pluginModeUrl, urlParams, + updateUrlParams, getPluginsList, deleteGistPlugin, deleteVolatilePlugin, @@ -215,6 +216,9 @@ export var PluginEditor = function ({ mode === 'test' ? 'block' : 'none'; document.getElementById('plugin-output-downloader').style.display = 'none'; + updateUrlParams('mode', mode); + + console.log({urlParams}) this.onSetEditingFile(); }; // ace-editor @@ -242,6 +246,7 @@ export var PluginEditor = function ({ let fileContents = this.volatilePlugins[this.editingFile].content; this.editor.setValue(fileContents); this.editor.clearSelection(); + updateUrlParams('pluginFile', this.editingFile); if (this.mode === 'commit') { fileContents = this.editor.getValue(); @@ -291,6 +296,7 @@ export var PluginEditor = function ({ }); }; + const HEIGHT = '80vh'; const { value: formValues } = await Swal.fire({ showCloseButton: false, showCancelButton: false, @@ -329,11 +335,11 @@ export var PluginEditor = function ({ html: `
-
+
-
+