Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useDialog } from "@tui/ui/dialog"
import { DialogSelect } from "@tui/ui/dialog-select"
import { DialogSelect, type DialogSelectRef } from "@tui/ui/dialog-select"
import { useRoute } from "@tui/context/route"
import { useSync } from "@tui/context/sync"
import { createMemo, createResource, createSignal, onMount } from "solid-js"
Expand Down Expand Up @@ -31,6 +31,8 @@ export function DialogSessionList() {
const toast = useToast()
const [toDelete, setToDelete] = createSignal<string>()
const [search, setSearch] = createDebouncedSignal("", 150)
const [selectRef, setSelectRef] = createSignal<DialogSelectRef<string>>()


const [searchResults, { refetch }] = createResource(search, async (query) => {
if (!query) return undefined
Expand Down Expand Up @@ -176,6 +178,7 @@ export function DialogSessionList() {

return (
<DialogSelect
ref={setSelectRef}
title="Sessions"
options={options()}
skipFilter={true}
Expand All @@ -197,8 +200,10 @@ export function DialogSessionList() {
title: "delete",
onTrigger: async (option) => {
if (toDelete() === option.value) {
const ref = selectRef()
const currentIndex = ref?.filtered.findIndex((opt) => opt.value === option.value) ?? -1
const session = sessions().find((item) => item.id === option.value)
const status = session?.workspaceID ? project.workspace.status(session.workspaceID) : undefined
const wsStatus = session?.workspaceID ? project.workspace.status(session.workspaceID) : undefined

try {
const result = await sdk.client.session.delete({
Expand Down Expand Up @@ -230,11 +235,20 @@ export function DialogSessionList() {
setToDelete(undefined)
return
}
if (status && status !== "connected") {
if (wsStatus && wsStatus !== "connected") {
await sync.session.refresh()
}
if (search()) await refetch()
setToDelete(undefined)

if (ref && currentIndex >= 0) {
setTimeout(() => {
const newIndex = Math.min(currentIndex, ref.filtered.length - 1)
if (newIndex >= 0) {
ref.moveTo(newIndex, true)
}
}, 50)
}
return
}
setToDelete(option.value)
Expand Down
2 changes: 2 additions & 0 deletions packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface DialogSelectOption<T = any> {
export type DialogSelectRef<T> = {
filter: string
filtered: DialogSelectOption<T>[]
moveTo: (index: number, center?: boolean) => void
}

export function DialogSelect<T>(props: DialogSelectProps<T>) {
Expand Down Expand Up @@ -232,6 +233,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
get filtered() {
return filtered()
},
moveTo,
}
props.ref?.(ref)

Expand Down