3
3
import { VSCodePanelTab , VSCodePanelView , VSCodePanels } from '@vscode/webview-ui-toolkit/react' ;
4
4
import './App.css' ;
5
5
import { StatGroupSelectionBox } from './controls/StatGroupSelectionBox' ;
6
- import { useCallback , useState } from 'react' ;
6
+ import { useCallback , useEffect , useState } from 'react' ;
7
7
import { StatisticType , YAxisType , createStatResolver } from './StatisticResolver' ;
8
8
import MinecraftStatisticLineChart from './controls/MinecraftStatisticLineChart' ;
9
9
import MinecraftStatisticStackedLineChart from './controls/MinecraftStatisticStackedLineChart' ;
@@ -12,6 +12,16 @@ import { MultipleStatisticProvider, SimpleStatisticProvider, StatisticUpdatedMes
12
12
13
13
import * as statPrefabs from './StatisticPrefabs' ;
14
14
15
+ const vscode = acquireVsCodeApi ( ) ;
16
+
17
+ interface TabState {
18
+ tabId : string ;
19
+ }
20
+
21
+ interface VSCodePanelsChangeEvent extends Event {
22
+ target : EventTarget & { activeid : string } ;
23
+ }
24
+
15
25
// Filter out events with a value of zero that haven't been previously subscribed to
16
26
function constructSubscribedSignalFilter ( ) {
17
27
const nonFilteredValues : string [ ] = [ ] ;
@@ -31,22 +41,48 @@ function constructSubscribedSignalFilter() {
31
41
function App ( ) {
32
42
// State
33
43
const [ selectedPlugin , setSelectedPlugin ] = useState < string > ( 'no_plugin_selected' ) ;
44
+ const [ selectedClient , setSelectedClient ] = useState < string > ( 'no_client_selected' ) ;
45
+ const [ currentTab , setCurrentTab ] = useState < string > ( ) ;
46
+
47
+ // Load initial state from vscode
48
+ useEffect ( ( ) => {
49
+ const tabState = vscode . getState ( ) as TabState ;
50
+ if ( tabState && tabState . tabId ) {
51
+ setCurrentTab ( tabState . tabId ) ;
52
+ }
53
+ } , [ ] ) ;
54
+
55
+ // Save current tab state whenever it changes
56
+ useEffect ( ( ) => {
57
+ if ( currentTab ) {
58
+ const tabState : TabState = { tabId : currentTab } ;
59
+ vscode . setState ( tabState ) ;
60
+ }
61
+ } , [ currentTab ] ) ;
34
62
35
63
const handlePluginSelection = useCallback ( ( pluginSelectionId : string ) => {
36
64
console . log ( `Selected Plugin: ${ pluginSelectionId } ` ) ;
37
65
setSelectedPlugin ( ( ) => pluginSelectionId ) ;
38
66
} , [ ] ) ;
39
67
40
- const [ selectedClient , setSelectedClient ] = useState < string > ( 'no_client_selected' ) ;
41
-
42
68
const handleClientSelection = useCallback ( ( clientSelectionId : string ) => {
43
69
console . log ( `Selected Client: ${ clientSelectionId } ` ) ;
44
70
setSelectedClient ( ( ) => clientSelectionId ) ;
45
71
} , [ ] ) ;
46
72
73
+ const handlePanelChange = useCallback ( ( event : VSCodePanelsChangeEvent ) : void => {
74
+ const newTabId = event . target . activeid ;
75
+ if ( newTabId ) {
76
+ setCurrentTab ( newTabId ) ;
77
+ }
78
+ } , [ ] ) ;
79
+
47
80
return (
48
81
< main >
49
- < VSCodePanels >
82
+ < VSCodePanels
83
+ activeid = { currentTab }
84
+ onChange = { event => handlePanelChange ( event as VSCodePanelsChangeEvent ) }
85
+ >
50
86
< VSCodePanelTab id = "tab-1" > World</ VSCodePanelTab >
51
87
< VSCodePanelTab id = "tab-2" > Memory</ VSCodePanelTab >
52
88
< VSCodePanelTab id = "tab-3" > Server Timing</ VSCodePanelTab >
0 commit comments