@@ -12,10 +12,11 @@ import {
1212import { runDockerComposeUpWithPortCheck } from "@effect-template/lib/usecases/projects-up"
1313import { Effect , Match , pipe } from "effect"
1414
15+ import { openAuthMenu } from "./menu-auth.js"
1516import { startCreateView } from "./menu-create.js"
1617import { loadSelectView } from "./menu-select-load.js"
17- import { resumeTui , suspendTui } from "./menu-shared.js"
18- import { type MenuEnv , type MenuRunner , type MenuState , type ViewState } from "./menu-types.js"
18+ import { pauseForEnter , resumeTui , suspendTui , writeToTerminal } from "./menu-shared.js"
19+ import { type MenuEnv , type MenuRunner , type MenuState , type MenuViewContext } from "./menu-types.js"
1920
2021// CHANGE: keep menu actions and input parsing in a dedicated module
2122// WHY: reduce cognitive complexity in the TUI entry
@@ -39,9 +40,7 @@ export type MenuContext = {
3940 readonly state : MenuState
4041 readonly runner : MenuRunner
4142 readonly exit : ( ) => void
42- readonly setView : ( view : ViewState ) => void
43- readonly setMessage : ( message : string | null ) => void
44- }
43+ } & MenuViewContext
4544
4645export type MenuSelectionContext = MenuContext & {
4746 readonly selected : number
@@ -50,6 +49,8 @@ export type MenuSelectionContext = MenuContext & {
5049
5150const actionLabel = ( action : MenuAction ) : string =>
5251 Match . value ( action ) . pipe (
52+ Match . when ( { _tag : "Auth" } , ( ) => "Auth profiles" ) ,
53+ Match . when ( { _tag : "ProjectAuth" } , ( ) => "Project auth" ) ,
5354 Match . when ( { _tag : "Up" } , ( ) => "docker compose up" ) ,
5455 Match . when ( { _tag : "Status" } , ( ) => "docker compose ps" ) ,
5556 Match . when ( { _tag : "Logs" } , ( ) => "docker compose logs" ) ,
@@ -69,7 +70,19 @@ const runWithSuspendedTui = (
6970 context . setMessage ( `${ label } ...` )
7071 suspendTui ( )
7172 } ) ,
72- Effect . zipRight ( effect ) ,
73+ Effect . zipRight (
74+ pipe (
75+ effect ,
76+ Effect . tapError ( ( error ) =>
77+ Effect . ignore (
78+ Effect . tryPromise ( async ( ) => {
79+ writeToTerminal ( `\n[docker-git] ${ renderError ( error ) } \n` )
80+ await pauseForEnter ( )
81+ } )
82+ )
83+ )
84+ )
85+ ) ,
7386 Effect . tap ( ( ) =>
7487 Effect . sync ( ( ) => {
7588 context . setMessage ( `${ label } finished.` )
@@ -140,6 +153,8 @@ const handleMenuAction = (
140153 Match . when ( { _tag : "Quit" } , ( ) => Effect . succeed ( quitOutcome ) ) ,
141154 Match . when ( { _tag : "Create" } , ( ) => Effect . succeed ( continueOutcome ( state ) ) ) ,
142155 Match . when ( { _tag : "Select" } , ( ) => Effect . succeed ( continueOutcome ( state ) ) ) ,
156+ Match . when ( { _tag : "Auth" } , ( ) => Effect . succeed ( continueOutcome ( state ) ) ) ,
157+ Match . when ( { _tag : "ProjectAuth" } , ( ) => Effect . succeed ( continueOutcome ( state ) ) ) ,
143158 Match . when ( { _tag : "Info" } , ( ) => Effect . succeed ( continueOutcome ( state ) ) ) ,
144159 Match . when ( { _tag : "Delete" } , ( ) => Effect . succeed ( continueOutcome ( state ) ) ) ,
145160 Match . when ( { _tag : "Up" } , ( ) =>
@@ -171,6 +186,22 @@ const runSelectAction = (context: MenuContext) => {
171186 context . runner . runEffect ( loadSelectView ( listProjectItems , "Connect" , context ) )
172187}
173188
189+ const runAuthProfilesAction = ( context : MenuContext ) => {
190+ context . setMessage ( null )
191+ openAuthMenu ( {
192+ state : context . state ,
193+ runner : context . runner ,
194+ setView : context . setView ,
195+ setMessage : context . setMessage ,
196+ setActiveDir : context . setActiveDir
197+ } )
198+ }
199+
200+ const runProjectAuthAction = ( context : MenuContext ) => {
201+ context . setMessage ( null )
202+ context . runner . runEffect ( loadSelectView ( listProjectItems , "Auth" , context ) )
203+ }
204+
174205const runDownAllAction = ( context : MenuContext ) => {
175206 context . setMessage ( null )
176207 runWithSuspendedTui ( downAllDockerGitProjects , context , "Stopping all docker-git containers" )
@@ -222,6 +253,12 @@ export const handleMenuActionSelection = (action: MenuAction, context: MenuConte
222253 Match . when ( { _tag : "Select" } , ( ) => {
223254 runSelectAction ( context )
224255 } ) ,
256+ Match . when ( { _tag : "Auth" } , ( ) => {
257+ runAuthProfilesAction ( context )
258+ } ) ,
259+ Match . when ( { _tag : "ProjectAuth" } , ( ) => {
260+ runProjectAuthAction ( context )
261+ } ) ,
225262 Match . when ( { _tag : "Info" } , ( ) => {
226263 runInfoAction ( context )
227264 } ) ,
0 commit comments