@@ -73,6 +73,7 @@ export type ConnectionReduxState = {
7373 connectionState : ConnectionState
7474 lastUpdate : number
7575 useDb : string | null
76+ lastUseDb : string | null
7677}
7778type ConnectionState =
7879 | typeof DISCONNECTED_STATE
@@ -103,7 +104,8 @@ const initialState: ConnectionReduxState = {
103104 activeConnection : null ,
104105 connectionState : DISCONNECTED_STATE ,
105106 lastUpdate : 0 ,
106- useDb : null
107+ useDb : null ,
108+ lastUseDb : null
107109}
108110/**
109111 * Selectors
@@ -119,6 +121,10 @@ export function getConnection(
119121 )
120122}
121123
124+ export function getLastUseDb ( state : GlobalState ) : string | null {
125+ return ( state [ NAME ] || { } ) . lastUseDb
126+ }
127+
122128export function getUseDb ( state : GlobalState ) : string | null {
123129 return ( state [ NAME ] || { } ) . useDb
124130}
@@ -286,7 +292,12 @@ export default function(state = initialState, action: any) {
286292 case UPDATE_AUTH_ENABLED :
287293 return updateAuthEnabledHelper ( state , action . authEnabled )
288294 case USE_DB :
289- return { ...state , useDb : action . useDb }
295+ const { useDb } = action
296+ let lastUseDb = useDb
297+ if ( useDb === null ) {
298+ lastUseDb = state . useDb || state . lastUseDb
299+ }
300+ return { ...state , lastUseDb, useDb }
290301 case USER_CLEAR :
291302 return initialState
292303 default :
@@ -356,6 +367,8 @@ export const setAuthEnabled = (authEnabled: any) => {
356367
357368export const useDb = ( db : any = null ) => ( { type : USE_DB , useDb : db } )
358369
370+ export const resetUseDb = ( ) => ( { type : USE_DB , useDb : null } )
371+
359372// Epics
360373export const useDbEpic = ( action$ : any ) => {
361374 return action$
@@ -449,7 +462,7 @@ function shouldTryAutoconnecting(conn: Connection | null): boolean {
449462export const startupConnectEpic = ( action$ : any , store : any ) => {
450463 return action$
451464 . ofType ( discovery . DONE )
452- . do ( ( ) => store . dispatch ( useDb ( null ) ) )
465+ . do ( ( ) => store . dispatch ( resetUseDb ( ) ) )
453466 . mergeMap ( async ( { discovered } : DiscoverDataAction ) => {
454467 const connectionTimeout = getConnectionTimeout ( store . getState ( ) )
455468 const savedConnection = getConnection (
@@ -559,7 +572,7 @@ export const disconnectEpic = (action$: any, store: any) => {
559572 . ofType ( DISCONNECT )
560573 . merge ( action$ . ofType ( USER_CLEAR ) )
561574 . do ( ( ) => bolt . closeConnection ( ) )
562- . do ( ( ) => store . dispatch ( useDb ( null ) ) )
575+ . do ( ( ) => store . dispatch ( resetUseDb ( ) ) )
563576 . do ( ( action : any ) =>
564577 store . dispatch ( updateConnection ( { id : action . id , password : '' } ) )
565578 )
@@ -569,7 +582,7 @@ export const silentDisconnectEpic = (action$: any, store: any) => {
569582 return action$
570583 . ofType ( SILENT_DISCONNECT )
571584 . do ( ( ) => bolt . closeConnection ( ) )
572- . do ( ( ) => store . dispatch ( useDb ( null ) ) )
585+ . do ( ( ) => store . dispatch ( resetUseDb ( ) ) )
573586 . do ( ( ) => store . dispatch ( { type : CLEAR_META } ) )
574587 . mapTo ( setActiveConnection ( null , true ) )
575588}
0 commit comments