@@ -11,6 +11,11 @@ const openBrowser = (url: string) => Effect.promise(() => open(url).catch(() =>
1111
1212const println = ( msg : string ) => Effect . sync ( ( ) => UI . println ( msg ) )
1313
14+ const isActiveOrgChoice = (
15+ active : Option . Option < { id : AccountID ; active_org_id : OrgID | null } > ,
16+ choice : { accountID : AccountID ; orgID : OrgID } ,
17+ ) => Option . isSome ( active ) && active . value . id === choice . accountID && active . value . active_org_id === choice . orgID
18+
1419const loginEffect = Effect . fn ( "login" ) ( function * ( url : string ) {
1520 const service = yield * AccountService
1621
@@ -99,11 +104,10 @@ const switchEffect = Effect.fn("switch")(function* () {
99104 if ( groups . length === 0 ) return yield * println ( "Not logged in" )
100105
101106 const active = yield * service . active ( )
102- const activeOrgID = Option . flatMap ( active , ( a ) => Option . fromNullishOr ( a . active_org_id ) )
103107
104108 const opts = groups . flatMap ( ( group ) =>
105109 group . orgs . map ( ( org ) => {
106- const isActive = Option . isSome ( activeOrgID ) && activeOrgID . value === org . id
110+ const isActive = isActiveOrgChoice ( active , { accountID : group . account . id , orgID : org . id } )
107111 return {
108112 value : { orgID : org . id , accountID : group . account . id , label : org . name } ,
109113 label : isActive
@@ -132,11 +136,10 @@ const orgsEffect = Effect.fn("orgs")(function* () {
132136 if ( ! groups . some ( ( group ) => group . orgs . length > 0 ) ) return yield * println ( "No orgs found" )
133137
134138 const active = yield * service . active ( )
135- const activeOrgID = Option . flatMap ( active , ( a ) => Option . fromNullishOr ( a . active_org_id ) )
136139
137140 for ( const group of groups ) {
138141 for ( const org of group . orgs ) {
139- const isActive = Option . isSome ( activeOrgID ) && activeOrgID . value === org . id
142+ const isActive = isActiveOrgChoice ( active , { accountID : group . account . id , orgID : org . id } )
140143 const dot = isActive ? UI . Style . TEXT_SUCCESS + "●" + UI . Style . TEXT_NORMAL : " "
141144 const name = isActive ? UI . Style . TEXT_HIGHLIGHT_BOLD + org . name + UI . Style . TEXT_NORMAL : org . name
142145 const email = UI . Style . TEXT_DIM + group . account . email + UI . Style . TEXT_NORMAL
0 commit comments