Fix: Tab-Auswahl bleibt nach Reload erhalten (localStorage)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4aed4e70ab
commit
c9378f4cdb
8 changed files with 4854 additions and 2 deletions
|
|
@ -25,7 +25,12 @@ export function registerTab(pluginName: string, component: React.FC<{ data: any
|
|||
export default function App() {
|
||||
const [connected, setConnected] = useState(false);
|
||||
const [plugins, setPlugins] = useState<PluginInfo[]>([]);
|
||||
const [activeTab, setActiveTab] = useState<string>('');
|
||||
const [activeTab, setActiveTabRaw] = useState<string>(() => localStorage.getItem('hub_activeTab') ?? '');
|
||||
|
||||
const setActiveTab = (tab: string) => {
|
||||
setActiveTabRaw(tab);
|
||||
localStorage.setItem('hub_activeTab', tab);
|
||||
};
|
||||
const [pluginData, setPluginData] = useState<Record<string, any>>({});
|
||||
const eventSourceRef = useRef<EventSource | null>(null);
|
||||
|
||||
|
|
@ -35,7 +40,9 @@ export default function App() {
|
|||
.then(r => r.json())
|
||||
.then((list: PluginInfo[]) => {
|
||||
setPlugins(list);
|
||||
if (list.length > 0 && !activeTab) setActiveTab(list[0].name);
|
||||
const saved = localStorage.getItem('hub_activeTab');
|
||||
const valid = list.some(p => p.name === saved);
|
||||
if (list.length > 0 && !valid) setActiveTab(list[0].name);
|
||||
})
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue