|
|
@ -18,7 +18,6 @@ const darkTheme = createMuiTheme({ |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
export interface MainWindowState { |
|
|
|
export interface MainWindowState { |
|
|
|
tabLabels: string[], |
|
|
|
|
|
|
|
tabStates: any[], |
|
|
|
tabStates: any[], |
|
|
|
tabReducers: Reducer<any, any>[], |
|
|
|
tabReducers: Reducer<any, any>[], |
|
|
|
tabTypes: WindowType[], |
|
|
|
tabTypes: WindowType[], |
|
|
@ -41,7 +40,6 @@ export function MainWindowReducer(state: MainWindowState, action: any) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
...state, |
|
|
|
...state, |
|
|
|
tabStates: state.tabStates.filter((i: any, idx: number) => idx != action.idx), |
|
|
|
tabStates: state.tabStates.filter((i: any, idx: number) => idx != action.idx), |
|
|
|
tabLabels: state.tabLabels.filter((i: any, idx: number) => idx != action.idx), |
|
|
|
|
|
|
|
tabReducers: state.tabReducers.filter((i: any, idx: number) => idx != action.idx), |
|
|
|
tabReducers: state.tabReducers.filter((i: any, idx: number) => idx != action.idx), |
|
|
|
tabTypes: state.tabTypes.filter((i: any, idx: number) => idx != action.idx), |
|
|
|
tabTypes: state.tabTypes.filter((i: any, idx: number) => idx != action.idx), |
|
|
|
activeTab: state.activeTab >= (newSize - 1) ? (newSize - 1) : state.activeTab, |
|
|
|
activeTab: state.activeTab >= (newSize - 1) ? (newSize - 1) : state.activeTab, |
|
|
@ -51,7 +49,6 @@ export function MainWindowReducer(state: MainWindowState, action: any) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
...state, |
|
|
|
...state, |
|
|
|
tabStates: [...state.tabStates, action.tabState], |
|
|
|
tabStates: [...state.tabStates, action.tabState], |
|
|
|
tabLabels: [...state.tabLabels, action.tabLabel], |
|
|
|
|
|
|
|
tabReducers: [...state.tabReducers, action.tabReducer], |
|
|
|
tabReducers: [...state.tabReducers, action.tabReducer], |
|
|
|
tabTypes: [...state.tabTypes, action.tabType], |
|
|
|
tabTypes: [...state.tabTypes, action.tabType], |
|
|
|
} |
|
|
|
} |
|
|
@ -71,15 +68,10 @@ export function MainWindowReducer(state: MainWindowState, action: any) { |
|
|
|
|
|
|
|
|
|
|
|
export default function MainWindow(props: any) { |
|
|
|
export default function MainWindow(props: any) { |
|
|
|
const [state, dispatch] = useReducer(MainWindowReducer, { |
|
|
|
const [state, dispatch] = useReducer(MainWindowReducer, { |
|
|
|
tabLabels: ["Query"], |
|
|
|
|
|
|
|
tabStates: [ |
|
|
|
tabStates: [ |
|
|
|
{ |
|
|
|
newWindowState[WindowType.Query]() |
|
|
|
editingQuery: false, |
|
|
|
|
|
|
|
query: null, |
|
|
|
|
|
|
|
resultsForQuery: null, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
], |
|
|
|
tabReducers: [QueryWindowReducer], |
|
|
|
tabReducers: [newWindowReducer[WindowType.Query]], |
|
|
|
tabTypes: [WindowType.Query], |
|
|
|
tabTypes: [WindowType.Query], |
|
|
|
activeTab: 0 |
|
|
|
activeTab: 0 |
|
|
|
}) |
|
|
|
}) |
|
|
@ -92,7 +84,6 @@ export default function MainWindow(props: any) { |
|
|
|
idx: i |
|
|
|
idx: i |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
console.log("state", state); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (state.tabTypes[i]) { |
|
|
|
switch (state.tabTypes[i]) { |
|
|
|
case WindowType.Query: |
|
|
|
case WindowType.Query: |
|
|
@ -112,10 +103,12 @@ export default function MainWindow(props: any) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("State:", state) |
|
|
|
|
|
|
|
|
|
|
|
return <ThemeProvider theme={darkTheme}> |
|
|
|
return <ThemeProvider theme={darkTheme}> |
|
|
|
<CssBaseline /> |
|
|
|
<CssBaseline /> |
|
|
|
<AppBar |
|
|
|
<AppBar |
|
|
|
tabLabels={state.tabLabels} |
|
|
|
tabLabels={state.tabStates.map((s: any) => s.tabLabel)} |
|
|
|
selectedTab={state.activeTab} |
|
|
|
selectedTab={state.activeTab} |
|
|
|
setSelectedTab={(t: number) => dispatch({ type: MainWindowStateActions.SetActiveTab, value: t })} |
|
|
|
setSelectedTab={(t: number) => dispatch({ type: MainWindowStateActions.SetActiveTab, value: t })} |
|
|
|
onCloseTab={(t: number) => dispatch({ type: MainWindowStateActions.CloseTab, idx: t })} |
|
|
|
onCloseTab={(t: number) => dispatch({ type: MainWindowStateActions.CloseTab, idx: t })} |
|
|
@ -123,7 +116,6 @@ export default function MainWindow(props: any) { |
|
|
|
dispatch({ |
|
|
|
dispatch({ |
|
|
|
type: MainWindowStateActions.AddTab, |
|
|
|
type: MainWindowStateActions.AddTab, |
|
|
|
tabState: newWindowState[w.windowType](), |
|
|
|
tabState: newWindowState[w.windowType](), |
|
|
|
tabLabel: w.title, |
|
|
|
|
|
|
|
tabReducer: newWindowReducer[w.windowType], |
|
|
|
tabReducer: newWindowReducer[w.windowType], |
|
|
|
tabType: w.windowType, |
|
|
|
tabType: w.windowType, |
|
|
|
}) |
|
|
|
}) |
|
|
|