Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #5

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions javascript/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const StateController = (function () {

function load(config) {

loadUI();
restoreTabs(config);

for (const [settingId, element] of Object.entries(ELEMENTS)) {
Expand Down Expand Up @@ -97,6 +98,37 @@ const StateController = (function () {
return tabs;
}

function loadUI() {

let toolbar = document.createElement("div");
toolbar.style.minWidth = 0;
toolbar.className = "gr-box relative w-full border-solid border border-gray-200 gr-padded";

let resetBtn = document.createElement("button");
resetBtn.innerHTML = "🔁";
resetBtn.className = "gr-button gr-button-lg gr-button-tool";
resetBtn.style.border = "none";
resetBtn.title = "Reset State";
resetBtn.addEventListener('click', function () {
let confirmed = confirm('Reset all state values?');
if (confirmed) {
let keys = Object.keys(localStorage);
for (let i = 0; i < keys.length; i++) {
if (keys[i].startsWith('state-')) {
localStorage.removeItem(keys[i]);
}
}
alert('All state values deleted!');
}
});

toolbar.appendChild(resetBtn);

let quickSettings = gradioApp().getElementById("quicksettings");
quickSettings.appendChild(toolbar);
}


function restoreTabs(config) {

if (! config.hasSetting('tabs')) {
Expand Down