Skip to content

Commit

Permalink
persist plugin editor state more via url parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
blurymind committed Aug 20, 2024
1 parent 4eed16d commit aad4ad8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/public/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -417,6 +426,7 @@ const getFunctionBody = (func = ()=>{}) => {
saveGistPlugin,
isGistTokenInvalid,
urlParams,
updateUrlParams,
gistPluginsFileUrl,
pluginModeUrl,
getPluginsList,
Expand Down
13 changes: 10 additions & 3 deletions src/public/plugins/plugin-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export var PluginEditor = function ({
gistPluginsFileUrl,
pluginModeUrl,
urlParams,
updateUrlParams,
getPluginsList,
deleteGistPlugin,
deleteVolatilePlugin,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -291,6 +296,7 @@ export var PluginEditor = function ({
});
};

const HEIGHT = '80vh';
const { value: formValues } = await Swal.fire({
showCloseButton: false,
showCancelButton: false,
Expand Down Expand Up @@ -329,11 +335,11 @@ export var PluginEditor = function ({
html: `
<div style="overflow:hidden;">
<div id="js-editor-wrapper">
<div id="js-editor" style="height: 70vh; width: 100%;"></div>
<div id="js-editor" style="height: ${HEIGHT}; width: 100%;"></div>
</div>
<div style="position: relative;">
<div id="diff-editor" class="diff-editor" style="height: 70vh; width: 100%;"></div>
<div id="diff-editor" class="diff-editor" style="height: ${HEIGHT}; width: 100%;"></div>
<button id="plugin-differ-commit" style="position: absolute;
right: 17px;
bottom: 17px;
Expand All @@ -360,7 +366,7 @@ export var PluginEditor = function ({
>
Download
</button>
<iframe id="plugin-output-previewer" style="height: 70vh; width: 100%; border: none;">
<iframe id="plugin-output-previewer" style="height: ${HEIGHT}; width: 100%; border: none;">
</div>
</div>
Expand All @@ -384,6 +390,7 @@ export var PluginEditor = function ({

},
onAfterClose: () => {
updateUrlParams('pluginFile', '');
// removeStyleSheet('public/plugins/ace-diff/ace-diff-dark.min.css');
// removeStyleSheet('public/plugins/ace-diff/ace-diff.min.css');
},
Expand Down

0 comments on commit aad4ad8

Please sign in to comment.