feat(app): detect prior server activity for layout transition

This commit is contained in:
usrnk1 2026-07-13 14:36:34 +02:00
commit 545b86587d
2 changed files with 28 additions and 0 deletions

View file

@ -3,6 +3,7 @@ import { createRoot, createSignal } from "solid-js"
import { createStore } from "solid-js/store"
import {
createServerProjects,
hasPersistedServerData,
migrateCanonicalLocalServerState,
nextServerAfterRemoval,
resolveServerList,
@ -61,6 +62,23 @@ describe("resolveServerList", () => {
})
})
describe("hasPersistedServerData", () => {
const empty = () => ({ list: [], projects: {}, lastProject: {}, recentlyClosed: {} })
test("ignores a blank persisted server store", () => {
expect(hasPersistedServerData(empty())).toBe(false)
})
test("recognizes configured servers and remembered project activity", () => {
expect(hasPersistedServerData({ ...empty(), list: ["https://example.com"] })).toBe(true)
expect(hasPersistedServerData({ ...empty(), projects: { local: [{ worktree: "/code", expanded: true }] } })).toBe(
true,
)
expect(hasPersistedServerData({ ...empty(), lastProject: { local: "/code" } })).toBe(true)
expect(hasPersistedServerData({ ...empty(), recentlyClosed: { local: ["/code"] } })).toBe(true)
})
})
test("treats WSL sidecars as remote server connections", () => {
expect(
ServerConnection.local({

View file

@ -12,6 +12,7 @@ type ServerProjectState = {
lastProject: Record<string, string>
recentlyClosed: Record<string, string[]>
}
type PersistedServerState = ServerProjectState & { list: StoredServer[] }
const HEALTH_POLL_INTERVAL_MS = 10_000
// The store retains more history than is displayed. Consumers filter recently closed entries
// against the live project list (dropping deleted projects) and then cap the visible count via
@ -178,6 +179,13 @@ export function resolveServerList(input: {
return [...deduped.values()]
}
export function hasPersistedServerData(store: PersistedServerState) {
if (store.list.length > 0) return true
if (Object.values(store.projects).some((projects) => projects.length > 0)) return true
if (Object.values(store.lastProject).some(Boolean)) return true
return Object.values(store.recentlyClosed).some((projects) => projects.length > 0)
}
export namespace ServerConnection {
type Base = { displayName?: string; label?: string }
@ -331,10 +339,12 @@ export const { use: useServer, provider: ServerProvider } = createSimpleContext(
() => allServers().find((s) => ServerConnection.key(s) === state.active) ?? allServers()[0],
)
const isLocal = createMemo(() => ServerConnection.local(current()))
const hasPersistedData = createMemo(() => hasPersistedServerData(store))
return {
ready: isReady,
isLocal,
hasPersistedData,
get key() {
return state.active
},