From 64dfaeb8d55bcf972982fa9e429214cb0cbf1d34 Mon Sep 17 00:00:00 2001 From: "ilian.iliev" Date: Mon, 20 Mar 2023 09:50:42 +0200 Subject: [PATCH] Fixed bug with tabs --- javascript/state.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/javascript/state.js b/javascript/state.js index 6c89911..c382f1b 100644 --- a/javascript/state.js +++ b/javascript/state.js @@ -83,20 +83,27 @@ const StateController = (function () { } } + function storeTab() { + localStorage.setItem(LS_PREFIX + 'tab', this.textContent); + bindTabEvents(); + } + + function bindTabEvents() { + const tabs = gradioApp().querySelectorAll('#tabs > div:first-child button'); + tabs.forEach(tab => { // dirty hack here + tab.removeEventListener('click', storeTab); + tab.addEventListener('click', storeTab); + }); + return tabs; + } + function restoreTabs(config) { if (! config.hasSetting('tabs')) { return; } - const tabs = gradioApp().querySelectorAll('#tabs > div:first-child button'); - - tabs.forEach(tab => { - tab.addEventListener('click', function () { - localStorage.setItem(LS_PREFIX + 'tab', this.textContent); - }); - }); - + const tabs = bindTabEvents(); const value = localStorage.getItem(LS_PREFIX + 'tab'); if (value) {