11import { base64Encode } from "@opencode-ai/util/encode"
2- import { Button } from "@opencode-ai/ui/button"
3- import { Dialog } from "@opencode-ai/ui/dialog"
4- import { createMemo , Show , type JSX } from "solid-js"
5- import type { Session } from "@opencode-ai/sdk/v2/client"
62import type { LocalProject } from "@/context/layout"
7- import { displayName } from "./helpers"
8-
9- type T = ( key : string , vars ?: Record < string , string | number > ) => string
103
114type Nav = {
125 directory : string
@@ -18,29 +11,6 @@ type Nav = {
1811 open : ( directory : string ) => Promise < void > | void
1912}
2013
21- type Ask = {
22- project : LocalProject
23- t : T
24- show : ( cb : ( ) => JSX . Element ) => void
25- dismiss : ( ) => void
26- onClose : ( directory : string ) => void
27- list : ( input : { directory : string } ) => Promise < { data ?: Session [ ] | null } >
28- }
29-
30- type DialogProps = {
31- count : number
32- project : LocalProject
33- t : T
34- onCancel : ( ) => void
35- onClose : ( ) => void
36- }
37-
38- export function projectCloseBody ( count : number , t : T ) {
39- if ( count === 0 ) return t ( "dialog.project.close.note" )
40- if ( count === 1 ) return `${ t ( "dialog.project.close.sessions.one" ) } ${ t ( "dialog.project.close.note" ) } `
41- return `${ t ( "dialog.project.close.sessions.many" , { count } ) } ${ t ( "dialog.project.close.note" ) } `
42- }
43-
4414export function closeProject ( input : Nav ) {
4515 const go = input . go ?? input . navigate
4616 const index = input . list . findIndex ( ( x ) => x . worktree === input . directory )
@@ -65,56 +35,3 @@ export function closeProject(input: Nav) {
6535 void input . open ( next . worktree )
6636 } )
6737}
68-
69- async function count ( project : LocalProject , list : Ask [ "list" ] ) {
70- const dirs = [ project . worktree , ...( project . sandboxes ?? [ ] ) ]
71- const all = await Promise . all (
72- dirs . map ( ( directory ) =>
73- list ( { directory } )
74- . then ( ( x ) => x . data ?? [ ] )
75- . catch ( ( ) => [ ] ) ,
76- ) ,
77- )
78- return all . flat ( ) . filter ( ( session ) => session . time . archived === undefined ) . length
79- }
80-
81- export async function askProjectClose ( input : Ask ) {
82- const total = await count ( input . project , input . list )
83- input . show ( ( ) => (
84- < DialogCloseProject
85- count = { total }
86- project = { input . project }
87- t = { input . t }
88- onCancel = { input . dismiss }
89- onClose = { ( ) => {
90- input . dismiss ( )
91- input . onClose ( input . project . worktree )
92- } }
93- />
94- ) )
95- }
96-
97- export function DialogCloseProject ( props : DialogProps ) {
98- const name = createMemo ( ( ) => displayName ( props . project ) )
99-
100- return (
101- < Dialog title = { props . t ( "dialog.project.close.title" ) } fit >
102- < div class = "flex flex-col gap-4 pl-6 pr-2.5 pb-3" >
103- < div class = "flex flex-col gap-1" >
104- < span class = "text-14-regular text-text-strong" >
105- { props . t ( "dialog.project.close.confirm" , { name : name ( ) } ) }
106- </ span >
107- < span class = "text-12-regular text-text-weak" > { projectCloseBody ( props . count , props . t ) } </ span >
108- </ div >
109- < div class = "flex justify-end gap-2" >
110- < Button variant = "ghost" size = "large" onClick = { props . onCancel } >
111- { props . t ( "common.cancel" ) }
112- </ Button >
113- < Button variant = "primary" size = "large" onClick = { props . onClose } >
114- { props . t ( "common.close" ) }
115- </ Button >
116- </ div >
117- </ div >
118- </ Dialog >
119- )
120- }
0 commit comments