@@ -6,7 +6,9 @@ import classnames from 'classnames';
66import Setting from '@/blocks/Setting' ;
77import Iconfont from '@/components/Iconfont' ;
88import BrandLogo from '@/components/BrandLogo' ;
9- import { MainState } from '@/models/mainPage' ;
9+ import { IMainPageType } from '@/models/mainPage' ;
10+ import { IWorkspaceModelType } from '@/models/workspace' ;
11+ import { IConnectionModelType } from '@/models/connection' ;
1012import { findObjListValue } from '@/utils'
1113
1214import DataSource from './connection' ;
@@ -45,42 +47,57 @@ const navConfig: INavItem[] = [
4547const initPageIndex = navConfig . findIndex ( t => `/${ t . key } ` === window . location . pathname ) ;
4648
4749interface IProps {
48- mainModel : MainState ;
50+ mainModel : IMainPageType [ 'state' ] ;
51+ workspaceModel : IWorkspaceModelType [ 'state' ] ;
52+ connectionModel : IConnectionModelType [ 'state' ] ;
4953 dispatch : any ;
5054}
5155
5256function MainPage ( props : IProps ) {
53- const { mainModel, dispatch } = props ;
57+ const { mainModel, workspaceModel , connectionModel , dispatch } = props ;
5458 const { curPage } = mainModel ;
59+ const { curConnection } = connectionModel ;
5560 const [ activeNav , setActiveNav ] = useState < INavItem > ( navConfig [ initPageIndex > 0 ? initPageIndex : 0 ] ) ;
5661
5762 useEffect ( ( ) => {
63+ // activeNav 发生变化,同步到全局状态管理
5864 dispatch ( {
5965 type : 'mainPage/updateCurPage' ,
6066 payload : activeNav . key
6167 } )
68+ // activeNav 发生变化 如果没有选中连接并且不在connections 那么需要跳转到 连接页面
69+ // if (!curConnection?.id && activeNav.key !== 'connections') {
70+ // setActiveNav(navConfig[2]);
71+ // }
72+ // activeNav 变化 同步地址栏变化
73+ // change url,but no page refresh
74+ window . history . pushState ( { } , "" , activeNav . key ) ;
6275 } , [ activeNav ] )
6376
6477 useEffect ( ( ) => {
65- if ( curPage !== activeNav . key ) {
66- const activeNav = navConfig [ findObjListValue ( navConfig , 'key' , curPage ) ]
67- setActiveNav ( activeNav )
78+ // 全局状态curPage发生变化,activeNav 需要同步变化
79+ if ( curPage && curPage !== activeNav . key ) {
80+ const newActiveNav = navConfig [ findObjListValue ( navConfig , 'key' , curPage ) ]
81+ setActiveNav ( newActiveNav )
6882 }
6983 } , [ curPage ] )
7084
85+ useEffect ( ( ) => {
86+ if ( curConnection ?. id ) {
87+ dispatch ( {
88+ type : 'workspace/fetchdatabaseAndSchema' ,
89+ } )
90+ }
91+ } , [ curConnection ] )
92+
7193 function switchingNav ( item : INavItem ) {
72- // change url,but no page refresh
73- window . history . pushState ( { } , "" , item . key ) ;
7494 if ( item . openBrowser ) {
7595 window . open ( item . openBrowser ) ;
7696 } else {
7797 setActiveNav ( item ) ;
7898 }
7999 }
80100
81- useEffect ( ( ) => {
82-
83- } , [ ] )
84101
85102 return (
86103 < div className = { styles . page } >
@@ -123,6 +140,8 @@ function MainPage(props: IProps) {
123140 ) ;
124141}
125142
126- export default connect ( ( { mainPage } : { mainPage : MainState } ) => ( {
143+ export default connect ( ( { mainPage, workspace , connection } : { mainPage : IMainPageType , workspace : IWorkspaceModelType , connection : IConnectionModelType } ) => ( {
127144 mainModel : mainPage ,
145+ workspaceModel : workspace ,
146+ connectionModel : connection ,
128147} ) ) ( MainPage ) ;
0 commit comments