@@ -17,14 +17,24 @@ import { useServerSync } from "@/context/server-sync"
1717import { useLanguage } from "@/context/language"
1818import { useProviders } from "@/hooks/use-providers"
1919
20- export function DialogConnectProvider ( props : { provider : string ; directory ?: Accessor < string | undefined > } ) {
20+ export function DialogConnectProvider ( props : {
21+ provider : string
22+ directory ?: Accessor < string | undefined >
23+ onBack ?: ( ) => void
24+ content ?: boolean
25+ bind ?: ( value : { back : ( ) => void } ) => void
26+ } ) {
2127 const dialog = useDialog ( )
2228 const serverSync = useServerSync ( )
2329 const serverSDK = useServerSDK ( )
2430 const language = useLanguage ( )
2531 const providers = useProviders ( props . directory )
2632
2733 const all = ( ) => {
34+ if ( props . onBack ) {
35+ props . onBack ( )
36+ return
37+ }
2838 void import ( "./dialog-select-provider" ) . then ( ( x ) => {
2939 dialog . show ( ( ) => < x . DialogSelectProvider directory = { props . directory } /> )
3040 } )
@@ -598,6 +608,74 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc
598608 )
599609 }
600610
611+ const content = (
612+ < div class = "flex flex-col gap-6 px-2.5 pb-3" >
613+ < div class = "px-2.5 flex gap-4 items-center" >
614+ < ProviderIcon id = { props . provider } class = "size-5 shrink-0 icon-strong-base" />
615+ < div class = "text-16-medium text-text-strong" >
616+ < Switch >
617+ < Match when = { props . provider === "anthropic" && method ( ) ?. label ?. toLowerCase ( ) . includes ( "max" ) } >
618+ { language . t ( "provider.connect.title.anthropicProMax" ) }
619+ </ Match >
620+ < Match when = { true } > { language . t ( "provider.connect.title" , { provider : provider ( ) . name } ) } </ Match >
621+ </ Switch >
622+ </ div >
623+ </ div >
624+ < div class = "px-2.5 pb-10 flex flex-col gap-6" >
625+ < div onKeyDown = { handleKey } tabIndex = { 0 } autofocus = { store . methodIndex === undefined ? true : undefined } >
626+ < Switch >
627+ < Match when = { loading ( ) } >
628+ < div class = "text-14-regular text-text-base" >
629+ < div class = "flex items-center gap-x-2" >
630+ < Spinner />
631+ < span > { language . t ( "provider.connect.status.inProgress" ) } </ span >
632+ </ div >
633+ </ div >
634+ </ Match >
635+ < Match when = { store . methodIndex === undefined } >
636+ < MethodSelection />
637+ </ Match >
638+ < Match when = { store . state === "pending" } >
639+ < div class = "text-14-regular text-text-base" >
640+ < div class = "flex items-center gap-x-2" >
641+ < Spinner />
642+ < span > { language . t ( "provider.connect.status.inProgress" ) } </ span >
643+ </ div >
644+ </ div >
645+ </ Match >
646+ < Match when = { store . state === "prompt" } >
647+ < AuthPromptsView />
648+ </ Match >
649+ < Match when = { store . state === "error" } >
650+ < div class = "text-14-regular text-text-base" >
651+ < div class = "flex items-center gap-x-2" >
652+ < Icon name = "circle-ban-sign" class = "text-icon-critical-base" />
653+ < span > { language . t ( "provider.connect.status.failed" , { error : store . error ?? "" } ) } </ span >
654+ </ div >
655+ </ div >
656+ </ Match >
657+ < Match when = { method ( ) ?. type === "api" } >
658+ < ApiAuthView />
659+ </ Match >
660+ < Match when = { method ( ) ?. type === "oauth" } >
661+ < Switch >
662+ < Match when = { store . authorization ?. method === "code" } >
663+ < OAuthCodeView />
664+ </ Match >
665+ < Match when = { store . authorization ?. method === "auto" } >
666+ < OAuthAutoView />
667+ </ Match >
668+ </ Switch >
669+ </ Match >
670+ </ Switch >
671+ </ div >
672+ </ div >
673+ </ div >
674+ )
675+
676+ props . bind ?.( { back : goBack } )
677+ if ( props . content ) return content
678+
601679 return (
602680 < Dialog
603681 title = {
@@ -610,68 +688,7 @@ export function DialogConnectProvider(props: { provider: string; directory?: Acc
610688 />
611689 }
612690 >
613- < div class = "flex flex-col gap-6 px-2.5 pb-3" >
614- < div class = "px-2.5 flex gap-4 items-center" >
615- < ProviderIcon id = { props . provider } class = "size-5 shrink-0 icon-strong-base" />
616- < div class = "text-16-medium text-text-strong" >
617- < Switch >
618- < Match when = { props . provider === "anthropic" && method ( ) ?. label ?. toLowerCase ( ) . includes ( "max" ) } >
619- { language . t ( "provider.connect.title.anthropicProMax" ) }
620- </ Match >
621- < Match when = { true } > { language . t ( "provider.connect.title" , { provider : provider ( ) . name } ) } </ Match >
622- </ Switch >
623- </ div >
624- </ div >
625- < div class = "px-2.5 pb-10 flex flex-col gap-6" >
626- < div onKeyDown = { handleKey } tabIndex = { 0 } autofocus = { store . methodIndex === undefined ? true : undefined } >
627- < Switch >
628- < Match when = { loading ( ) } >
629- < div class = "text-14-regular text-text-base" >
630- < div class = "flex items-center gap-x-2" >
631- < Spinner />
632- < span > { language . t ( "provider.connect.status.inProgress" ) } </ span >
633- </ div >
634- </ div >
635- </ Match >
636- < Match when = { store . methodIndex === undefined } >
637- < MethodSelection />
638- </ Match >
639- < Match when = { store . state === "pending" } >
640- < div class = "text-14-regular text-text-base" >
641- < div class = "flex items-center gap-x-2" >
642- < Spinner />
643- < span > { language . t ( "provider.connect.status.inProgress" ) } </ span >
644- </ div >
645- </ div >
646- </ Match >
647- < Match when = { store . state === "prompt" } >
648- < AuthPromptsView />
649- </ Match >
650- < Match when = { store . state === "error" } >
651- < div class = "text-14-regular text-text-base" >
652- < div class = "flex items-center gap-x-2" >
653- < Icon name = "circle-ban-sign" class = "text-icon-critical-base" />
654- < span > { language . t ( "provider.connect.status.failed" , { error : store . error ?? "" } ) } </ span >
655- </ div >
656- </ div >
657- </ Match >
658- < Match when = { method ( ) ?. type === "api" } >
659- < ApiAuthView />
660- </ Match >
661- < Match when = { method ( ) ?. type === "oauth" } >
662- < Switch >
663- < Match when = { store . authorization ?. method === "code" } >
664- < OAuthCodeView />
665- </ Match >
666- < Match when = { store . authorization ?. method === "auto" } >
667- < OAuthAutoView />
668- </ Match >
669- </ Switch >
670- </ Match >
671- </ Switch >
672- </ div >
673- </ div >
674- </ div >
691+ { content }
675692 </ Dialog >
676693 )
677694}
0 commit comments