Browse Source

fix(app): reload instance after workspace reset

Adam 1 month ago
parent
commit
c2f9fd5fef
2 changed files with 40 additions and 20 deletions
  1. 10 1
      packages/app/src/components/prompt-input.tsx
  2. 30 19
      packages/app/src/pages/layout.tsx

+ 10 - 1
packages/app/src/components/prompt-input.tsx

@@ -1056,7 +1056,16 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
 
     let session = info()
     if (!session && isNewSession) {
-      session = await client.session.create().then((x) => x.data ?? undefined)
+      session = await client.session
+        .create()
+        .then((x) => x.data ?? undefined)
+        .catch((err) => {
+          showToast({
+            title: "Failed to create session",
+            description: errorMessage(err),
+          })
+          return undefined
+        })
       if (session) navigate(`/${base64Encode(sessionDirectory)}/session/${session.id}`)
     }
     if (!session) return

+ 30 - 19
packages/app/src/pages/layout.tsx

@@ -965,10 +965,23 @@ export default function Layout(props: ParentProps) {
     if (!current) return
     if (directory === current.worktree) return
 
-    const reset = globalSDK.client.worktree
+    const progress = showToast({
+      persistent: true,
+      title: "Resetting workspace",
+      description: "This may take a minute.",
+    })
+    const dismiss = () => toaster.dismiss(progress)
+
+    const sessions = await globalSDK.client.session
+      .list({ directory })
+      .then((x) => x.data ?? [])
+      .catch(() => [])
+
+    const result = await globalSDK.client.worktree
       .reset({ directory: current.worktree, worktreeResetInput: { directory } })
       .then((x) => x.data)
       .catch((err) => {
+        dismiss()
         showToast({
           title: "Failed to reset workspace",
           description: errorMessage(err),
@@ -976,21 +989,16 @@ export default function Layout(props: ParentProps) {
         return false
       })
 
-    const href = `/${base64Encode(directory)}/session`
-    navigate(href)
-    layout.mobileSidebar.hide()
-
-    void (async () => {
-      const sessions = await globalSDK.client.session
-        .list({ directory })
-        .then((x) => x.data ?? [])
-        .catch(() => [])
-
-      if (sessions.length === 0) return
+    if (!result) {
+      dismiss()
+      return
+    }
 
-      const archivedAt = Date.now()
-      await Promise.all(
-        sessions.map((session) =>
+    const archivedAt = Date.now()
+    await Promise.all(
+      sessions
+        .filter((session) => session.time.archived === undefined)
+        .map((session) =>
           globalSDK.client.session
             .update({
               sessionID: session.id,
@@ -999,11 +1007,14 @@ export default function Layout(props: ParentProps) {
             })
             .catch(() => undefined),
         ),
-      )
-    })()
+    )
 
-    const result = await reset
-    if (!result) return
+    await globalSDK.client.instance.dispose({ directory }).catch(() => undefined)
+    dismiss()
+
+    const href = `/${base64Encode(directory)}/session`
+    navigate(href)
+    layout.mobileSidebar.hide()
 
     showToast({
       title: "Workspace reset",