|
|
@@ -1,4 +1,4 @@
|
|
|
-import { createMemo, createResource, createSignal, onMount } from "solid-js"
|
|
|
+import { createMemo, createResource, createSignal } from "solid-js"
|
|
|
import type { SessionInfo } from "@opencode-ai/client"
|
|
|
import { useTerminalDimensions } from "@opentui/solid"
|
|
|
import { dialogWidth, useDialog } from "../ui/dialog"
|
|
|
@@ -20,10 +20,22 @@ import { Spinner } from "./spinner"
|
|
|
import { projectName } from "../util/project"
|
|
|
|
|
|
const RECENT_LIMIT = 8
|
|
|
+export const DialogOpenKey = Symbol("DialogOpen")
|
|
|
|
|
|
type OpenTarget = { type: "session"; sessionID: string } | { type: "project"; directory: string }
|
|
|
|
|
|
-export function DialogOpen() {
|
|
|
+export async function loadDialogOpen(data: ReturnType<typeof useData>, client: ReturnType<typeof useClient>) {
|
|
|
+ const [, sessions] = await Promise.all([
|
|
|
+ data.project.sync().catch(() => {}),
|
|
|
+ client.api.session
|
|
|
+ .list({ limit: 50, order: "desc", parentID: null })
|
|
|
+ .then((response) => response.data)
|
|
|
+ .catch(() => [] as SessionInfo[]),
|
|
|
+ ])
|
|
|
+ return sessions
|
|
|
+}
|
|
|
+
|
|
|
+export function DialogOpen(props: { sessions: SessionInfo[] }) {
|
|
|
const dialog = useDialog()
|
|
|
const route = useRoute()
|
|
|
const data = useData()
|
|
|
@@ -39,18 +51,6 @@ export function DialogOpen() {
|
|
|
const [filter, setFilter] = createSignal("")
|
|
|
const [selectionMoved, setSelectionMoved] = createSignal(false)
|
|
|
|
|
|
- void data.project.sync().catch(() => {})
|
|
|
-
|
|
|
- // One background fetch fills in recent sessions from other projects; the menu renders
|
|
|
- // immediately from the local store and never blocks on the network.
|
|
|
- const [fetched] = createResource(
|
|
|
- () =>
|
|
|
- client.api.session
|
|
|
- .list({ limit: 50, order: "desc", parentID: null })
|
|
|
- .then((response) => response.data)
|
|
|
- .catch(() => [] as SessionInfo[]),
|
|
|
- { initialValue: [] },
|
|
|
- )
|
|
|
const [matched] = createResource(
|
|
|
() => {
|
|
|
const value = filter().trim()
|
|
|
@@ -72,7 +72,7 @@ export function DialogOpen() {
|
|
|
const sessions = createMemo(() => {
|
|
|
const seen = new Set<string>()
|
|
|
const match = matched()
|
|
|
- return [...data.session.list(), ...fetched(), ...(match ? [match] : [])]
|
|
|
+ return [...data.session.list(), ...props.sessions, ...(match ? [match] : [])]
|
|
|
.filter((session) => {
|
|
|
if (session.parentID || seen.has(session.id)) return false
|
|
|
seen.add(session.id)
|
|
|
@@ -142,8 +142,6 @@ export function DialogOpen() {
|
|
|
return [...sessionOptions, ...projectOptions]
|
|
|
})
|
|
|
|
|
|
- onMount(() => dialog.setSize("large"))
|
|
|
-
|
|
|
return (
|
|
|
<DialogSelect
|
|
|
title="Open"
|