From 5442adb5174cee717b9a301d0cce8be8f3338388 Mon Sep 17 00:00:00 2001
From: Adam <2363879+adamdotdevin@users.noreply.github.com>
Date: Tue, 9 Dec 2025 11:08:55 -0600
Subject: wip(desktop): progress

---
 packages/desktop/src/context/layout.tsx | 34 +++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

(limited to 'packages/desktop/src/context/layout.tsx')

diff --git a/packages/desktop/src/context/layout.tsx b/packages/desktop/src/context/layout.tsx
index 1b43cf511..5ef41c1f4 100644
--- a/packages/desktop/src/context/layout.tsx
+++ b/packages/desktop/src/context/layout.tsx
@@ -1,14 +1,18 @@
 import { createStore } from "solid-js/store"
-import { createMemo } from "solid-js"
+import { createMemo, onMount } from "solid-js"
 import { createSimpleContext } from "@opencode-ai/ui/context"
 import { makePersisted } from "@solid-primitives/storage"
+import { useGlobalSync } from "./global-sync"
+import { useGlobalSDK } from "./global-sdk"
 
 export const { use: useLayout, provider: LayoutProvider } = createSimpleContext({
   name: "Layout",
   init: () => {
+    const globalSdk = useGlobalSDK()
+    const globalSync = useGlobalSync()
     const [store, setStore] = makePersisted(
       createStore({
-        projects: [] as { directory: string; expanded: boolean; lastSession?: string }[],
+        projects: [] as { directory: string; expanded: boolean }[],
         sidebar: {
           opened: false,
           width: 280,
@@ -26,11 +30,31 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
       },
     )
 
+    async function loadProjectSessions(directory: string) {
+      const [, setStore] = globalSync.child(directory)
+      globalSdk.client.session.list({ directory }).then((x) => {
+        const sessions = (x.data ?? [])
+          .slice()
+          .sort((a, b) => a.id.localeCompare(b.id))
+          .slice(0, 5)
+        setStore("session", sessions)
+      })
+    }
+
+    onMount(() => {
+      Promise.all(
+        store.projects.map(({ directory }) => {
+          return loadProjectSessions(directory)
+        }),
+      )
+    })
+
     return {
       projects: {
         list: createMemo(() => store.projects),
         open(directory: string) {
           if (store.projects.find((x) => x.directory === directory)) return
+          loadProjectSessions(directory)
           setStore("projects", (x) => [...x, { directory, expanded: true }])
         },
         close(directory: string) {
@@ -42,12 +66,6 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
         collapse(directory: string) {
           setStore("projects", (x) => x.map((x) => (x.directory === directory ? { ...x, expanded: false } : x)))
         },
-        lastSession(directory: string) {
-          return store.projects.find((x) => x.directory === directory)?.lastSession
-        },
-        setLastSession(directory: string, session: string | undefined) {
-          setStore("projects", (x) => x.map((x) => (x.directory === directory ? { ...x, lastSession: session } : x)))
-        },
       },
       sidebar: {
         opened: createMemo(() => store.sidebar.opened),
-- 
cgit v1.2.3

