From 0596b02f198ebe43703c3702f45eb2f1acdda431 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Tue, 20 Jan 2026 05:06:05 -0600 Subject: [PATCH] chore: cleanup --- packages/app/src/pages/layout.tsx | 153 ++++++++++++++++++++---------- packages/desktop/src/index.tsx | 23 ++++- 2 files changed, 122 insertions(+), 54 deletions(-) diff --git a/packages/app/src/pages/layout.tsx b/packages/app/src/pages/layout.tsx index dc716c030..b46758049 100644 --- a/packages/app/src/pages/layout.tsx +++ b/packages/app/src/pages/layout.tsx @@ -76,6 +76,7 @@ export default function Layout(props: ParentProps) { activeWorkspace: undefined as string | undefined, workspaceOrder: {} as Record, workspaceName: {} as Record, + workspaceBranchName: {} as Record>, workspaceExpanded: {} as Record, }), ) @@ -198,7 +199,10 @@ export default function Layout(props: ParentProps) { value={editorValue()} class={props.class} onInput={(event) => setEditor("value", event.currentTarget.value)} - onKeyDown={(event) => editorKeyDown(event, props.onSave)} + onKeyDown={(event) => { + event.stopPropagation() + editorKeyDown(event, props.onSave) + }} onBlur={() => closeEditor()} onPointerDown={stopPropagation} onClick={stopPropagation} @@ -458,9 +462,27 @@ export default function Layout(props: ParentProps) { ), ) - const workspaceName = (directory: string) => store.workspaceName[directory] - const workspaceLabel = (directory: string, branch?: string) => - workspaceName(directory) ?? branch ?? getFilename(directory) + const workspaceKey = (directory: string) => directory.replace(/[\\/]+$/, "") + + const workspaceName = (directory: string, projectId?: string, branch?: string) => { + const key = workspaceKey(directory) + const direct = store.workspaceName[key] ?? store.workspaceName[directory] + if (direct) return direct + if (!projectId) return + if (!branch) return + return store.workspaceBranchName[projectId]?.[branch] + } + + const setWorkspaceName = (directory: string, next: string, projectId?: string, branch?: string) => { + const key = workspaceKey(directory) + setStore("workspaceName", (prev) => ({ ...(prev ?? {}), [key]: next })) + if (!projectId) return + if (!branch) return + setStore("workspaceBranchName", projectId, (prev) => ({ ...(prev ?? {}), [branch]: next })) + } + + const workspaceLabel = (directory: string, branch?: string, projectId?: string) => + workspaceName(directory, projectId, branch) ?? branch ?? getFilename(directory) const isWorkspaceEditing = () => editor.active.startsWith("workspace:") @@ -885,10 +907,10 @@ export default function Layout(props: ParentProps) { }) } - const renameWorkspace = (directory: string, next: string) => { - const current = workspaceName(directory) ?? getFilename(directory) + const renameWorkspace = (directory: string, next: string, projectId?: string, branch?: string) => { + const current = workspaceName(directory, projectId, branch) ?? branch ?? getFilename(directory) if (current === next) return - setStore("workspaceName", directory, next) + setWorkspaceName(directory, next, projectId, branch) } function closeProject(directory: string) { @@ -1491,7 +1513,7 @@ export default function Layout(props: ParentProps) { const [workspaceStore] = globalSync.child(directory) const kind = directory === project.worktree ? "local" : "sandbox" - const name = workspaceLabel(directory, workspaceStore.vcs?.branch) + const name = workspaceLabel(directory, workspaceStore.vcs?.branch, project.id) return `${kind} : ${name}` }) @@ -1508,6 +1530,7 @@ export default function Layout(props: ParentProps) { const sortable = createSortable(props.directory) const [workspaceStore, setWorkspaceStore] = globalSync.child(props.directory) const [menuOpen, setMenuOpen] = createSignal(false) + const [pendingRename, setPendingRename] = createSignal(false) const slug = createMemo(() => base64Encode(props.directory)) const sessions = createMemo(() => workspaceStore.session @@ -1517,8 +1540,9 @@ export default function Layout(props: ParentProps) { ) const local = createMemo(() => props.directory === props.project.worktree) const workspaceValue = createMemo(() => { - const name = workspaceStore.vcs?.branch ?? getFilename(props.directory) - return workspaceName(props.directory) ?? name + const branch = workspaceStore.vcs?.branch + const name = branch ?? getFilename(props.directory) + return workspaceName(props.directory, props.project.id, branch) ?? name }) const open = createMemo(() => store.workspaceExpanded[props.directory] ?? true) const loading = createMemo(() => open() && workspaceStore.status !== "complete" && sessions().length === 0) @@ -1537,6 +1561,44 @@ export default function Layout(props: ParentProps) { if (editorOpen(`workspace:${props.directory}`)) closeEditor() } + const header = () => ( +
+
+ +
+ {local() ? "local" : "sandbox"} : + + {workspaceStore.vcs?.branch ?? getFilename(props.directory)} + + } + > + { + const trimmed = next.trim() + if (!trimmed) return + renameWorkspace(props.directory, trimmed, props.project.id, workspaceStore.vcs?.branch) + setEditor("value", workspaceValue()) + }} + class="text-14-medium text-text-base min-w-0 truncate" + displayClass="text-14-medium text-text-base min-w-0 truncate" + editing={workspaceEditActive()} + stopPropagation={false} + openOnDblClick={false} + /> + + +
+ ) + return ( // @ts-ignore
@@ -1544,43 +1606,18 @@ export default function Layout(props: ParentProps) {
- -
-
- -
- {local() ? "local" : "sandbox"} : - - {workspaceStore.vcs?.branch ?? getFilename(props.directory)} - - } - > - { - const trimmed = next.trim() - if (!trimmed) return - renameWorkspace(props.directory, trimmed) - setEditor("value", workspaceValue()) - }} - class="text-14-medium text-text-base min-w-0 truncate" - displayClass="text-14-medium text-text-base min-w-0 truncate" - editing={workspaceEditActive()} - stopPropagation={false} - openOnDblClick={false} - /> - - + + {header()} + + } + > +
+ {header()}
- +
- + { + if (!pendingRename()) return + event.preventDefault() + setPendingRename(false) + openEditor(`workspace:${props.directory}`, workspaceValue()) + }} + > navigate(`/${slug()}/session`)}> New session + { + setPendingRename(true) + setMenuOpen(false) + }} + > + Rename + dialog.show(() => )} > - Reset workspace + Reset dialog.show(() => )} > - Delete workspace + Delete @@ -1681,7 +1734,7 @@ export default function Layout(props: ParentProps) { const label = (directory: string) => { const [data] = globalSync.child(directory) const kind = directory === props.project.worktree ? "local" : "sandbox" - const name = workspaceLabel(directory, data.vcs?.branch) + const name = workspaceLabel(directory, data.vcs?.branch, props.project.id) return `${kind} : ${name}` } diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/index.tsx index d6ee121af..3b3002967 100644 --- a/packages/desktop/src/index.tsx +++ b/packages/desktop/src/index.tsx @@ -89,11 +89,26 @@ const createPlatform = (password: Accessor): Platform => ({ length(): Promise } - const WRITE_DEBOUNCE_MS = 250 + const WRITE_DEBOUNCE_MS = 250 - const storeCache = new Map>() - const apiCache = new Map Promise }>() - const memoryCache = new Map() + const storeCache = new Map>() + const apiCache = new Map Promise }>() + const memoryCache = new Map() + + const flushAll = async () => { + const apis = Array.from(apiCache.values()) + await Promise.all(apis.map((api) => api.flush().catch(() => undefined))) + } + + if ("addEventListener" in globalThis) { + const handleVisibility = () => { + if (document.visibilityState !== "hidden") return + void flushAll() + } + + window.addEventListener("pagehide", () => void flushAll()) + document.addEventListener("visibilitychange", handleVisibility) + } const createMemoryStore = () => { const data = new Map()