From d68cb6b1b8877f614a87ae88760f36127de3d5ee Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Sat, 6 Dec 2025 22:16:08 +0000 Subject: [PATCH] Add delete controls to resume sessions --- .../src/components/instance-welcome-view.tsx | 168 +++++++++++++----- 1 file changed, 125 insertions(+), 43 deletions(-) diff --git a/packages/ui/src/components/instance-welcome-view.tsx b/packages/ui/src/components/instance-welcome-view.tsx index 39faa6f1..922e2ce4 100644 --- a/packages/ui/src/components/instance-welcome-view.tsx +++ b/packages/ui/src/components/instance-welcome-view.tsx @@ -1,8 +1,9 @@ import { Component, createSignal, Show, For, createEffect, onMount, onCleanup, createMemo } from "solid-js" +import { Trash2 } from "lucide-solid" + import type { Instance } from "../types/instance" -import { getParentSessions, createSession, setActiveParentSession } from "../stores/sessions" +import { getParentSessions, createSession, setActiveParentSession, deleteSession, loading } from "../stores/sessions" import InstanceInfo from "./instance-info" -import KeyboardHint from "./keyboard-hint" import Kbd from "./kbd" import { keyboardRegistry, type KeyboardShortcut } from "../lib/keyboard-registry" import { isMac } from "../lib/keyboard-utils" @@ -22,6 +23,10 @@ const InstanceWelcomeView: Component = (props) => { const [showInstanceInfoOverlay, setShowInstanceInfoOverlay] = createSignal(false) const parentSessions = () => getParentSessions(props.instance.id) + const isSessionDeleting = (sessionId: string) => { + const deleting = loading().deletingSession.get(props.instance.id) + return deleting ? deleting.has(sessionId) : false + } const newSessionShortcut = createMemo(() => { const registered = keyboardRegistry.get("session-new") if (registered) return registered @@ -119,21 +124,48 @@ const InstanceWelcomeView: Component = (props) => { scrollToIndex(newIndex) } else if (e.key === "Enter") { e.preventDefault() - handleEnterKey() + void handleEnterKey() + } else if (e.key === "Delete" || e.key === "Backspace") { + e.preventDefault() + void handleDeleteKey() } } async function handleEnterKey() { const sessions = parentSessions() const index = selectedIndex() - + if (index < sessions.length) { await handleSessionSelect(sessions[index].id) } } - - onMount(() => { + + async function handleDeleteKey() { + const sessions = parentSessions() + const index = selectedIndex() + + if (index >= sessions.length) { + return + } + + await handleSessionDelete(sessions[index].id) + + const updatedSessions = parentSessions() + if (updatedSessions.length === 0) { + setFocusMode("new-session") + setSelectedIndex(0) + return + } + + const nextIndex = Math.min(index, updatedSessions.length - 1) + setSelectedIndex(nextIndex) + setFocusMode("sessions") + scrollToIndex(nextIndex) + } + + onMount(() => { window.addEventListener("keydown", handleKeyDown) + onCleanup(() => { window.removeEventListener("keydown", handleKeyDown) }) @@ -184,10 +216,21 @@ const InstanceWelcomeView: Component = (props) => { setActiveParentSession(props.instance.id, sessionId) } + async function handleSessionDelete(sessionId: string) { + if (isSessionDeleting(sessionId)) return + + try { + await deleteSession(props.instance.id, sessionId) + } catch (error) { + log.error("Failed to delete session:", error) + } + } + async function handleNewSession() { if (isCreating()) return setIsCreating(true) + try { const session = await createSession(props.instance.id) setActiveParentSession(props.instance.id, session.id) @@ -248,48 +291,82 @@ const InstanceWelcomeView: Component = (props) => {
- {(session, index) => ( -
- + +
+ +
-
- {session.agent} - - {formatRelativeTime(session.time.updated)} -
-
- -
- - - )} + + ) + }} @@ -363,6 +440,7 @@ const InstanceWelcomeView: Component = (props) => { ) } + + export default InstanceWelcomeView -export default InstanceWelcomeView