fix: persist active tab via localStorage + fix implicit event bug in switchTab
- Add data-tab attributes to tab buttons for reliable identification - Replace implicit window.event usage with querySelector by data-tab - Save active tab to localStorage on switch, restore on page load
This commit is contained in:
@@ -660,15 +660,15 @@
|
||||
<!-- Tab Navigation -->
|
||||
<div class="tab-container">
|
||||
<div class="tab-buttons">
|
||||
<button class="tab-button active" onclick="switchTab('tab1')">Server Management</button>
|
||||
<button class="tab-button" onclick="switchTab('tab2')">Actions</button>
|
||||
<button class="tab-button" onclick="switchTab('tab3')">Status</button>
|
||||
<button class="tab-button" onclick="switchTab('tab4')">⚙️ LLM Settings</button>
|
||||
<button class="tab-button" onclick="switchTab('tab5')">🎨 Image Generation</button>
|
||||
<button class="tab-button" onclick="switchTab('tab6')">📊 Autonomous Stats</button>
|
||||
<button class="tab-button" onclick="switchTab('tab7')">💬 Chat with LLM</button>
|
||||
<button class="tab-button" onclick="switchTab('tab8')">📞 Voice Call</button>
|
||||
<button class="tab-button" onclick="switchTab('tab9')">🧠 Memories</button>
|
||||
<button class="tab-button active" data-tab="tab1" onclick="switchTab('tab1')">Server Management</button>
|
||||
<button class="tab-button" data-tab="tab2" onclick="switchTab('tab2')">Actions</button>
|
||||
<button class="tab-button" data-tab="tab3" onclick="switchTab('tab3')">Status</button>
|
||||
<button class="tab-button" data-tab="tab4" onclick="switchTab('tab4')">⚙️ LLM Settings</button>
|
||||
<button class="tab-button" data-tab="tab5" onclick="switchTab('tab5')">🎨 Image Generation</button>
|
||||
<button class="tab-button" data-tab="tab6" onclick="switchTab('tab6')">📊 Autonomous Stats</button>
|
||||
<button class="tab-button" data-tab="tab7" onclick="switchTab('tab7')">💬 Chat with LLM</button>
|
||||
<button class="tab-button" data-tab="tab8" onclick="switchTab('tab8')">📞 Voice Call</button>
|
||||
<button class="tab-button" data-tab="tab9" onclick="switchTab('tab9')">🧠 Memories</button>
|
||||
<button class="tab-button" onclick="window.location.href='/static/system.html'">🎛️ System Settings</button>
|
||||
</div>
|
||||
|
||||
@@ -1830,8 +1830,12 @@ function switchTab(tabId) {
|
||||
// Show the selected tab content
|
||||
document.getElementById(tabId).classList.add('active');
|
||||
|
||||
// Add active class to the clicked tab button
|
||||
event.target.classList.add('active');
|
||||
// Add active class to the matching tab button via data-tab attribute
|
||||
const activeBtn = document.querySelector(`.tab-button[data-tab="${tabId}"]`);
|
||||
if (activeBtn) activeBtn.classList.add('active');
|
||||
|
||||
// Persist active tab to localStorage
|
||||
localStorage.setItem('miku-active-tab', tabId);
|
||||
|
||||
console.log(`🔄 Switched to ${tabId}`);
|
||||
if (tabId === 'tab1') {
|
||||
@@ -1846,6 +1850,12 @@ function switchTab(tabId) {
|
||||
|
||||
// Initialize
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Restore persisted tab from localStorage
|
||||
const savedTab = localStorage.getItem('miku-active-tab');
|
||||
if (savedTab && document.getElementById(savedTab)) {
|
||||
switchTab(savedTab);
|
||||
}
|
||||
|
||||
loadStatus();
|
||||
loadServers();
|
||||
loadLastPrompt();
|
||||
|
||||
Reference in New Issue
Block a user