Skip to content

Commit 8945553

Browse files
committed
Improve connection tab laziness
1 parent fdad29e commit 8945553

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/pages/RemoteProduct.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
import { useCallback, useEffect, useRef, useState } from 'react';
14+
import { EcaRemoteApi } from '../bridge/api';
1415
import { probePort, testConnection } from '../bridge/connection';
1516
import type { WebBridge } from '../bridge/transport';
1617
import type { ChatEntry, WorkspaceFolder } from '../bridge/types';
@@ -51,13 +52,42 @@ export function RemoteProduct() {
5152
// --- Persistence ---
5253

5354
useEffect(() => {
54-
saveConnections(entries.map(({ id, host, password, protocol }) => ({ id, host, password, protocol })));
55+
saveConnections(entries.map(({ id, host, password, protocol, workspaceFolders }) => ({ id, host, password, protocol, workspaceFolders })));
5556
}, [entries]);
5657

5758
useEffect(() => {
5859
saveActiveId(activeId);
5960
}, [activeId]);
6061

62+
// --- Proactive workspace folder fetch ---
63+
// For entries that don't have workspace folders yet (e.g. freshly added or
64+
// loaded from storage before this feature existed), fire a lightweight
65+
// session request to populate them. Uses a ref to avoid re-fetching.
66+
67+
const fetchedWorkspaceIdsRef = useRef(new Set<string>());
68+
69+
useEffect(() => {
70+
for (const entry of entries) {
71+
if (entry.workspaceFolders || fetchedWorkspaceIdsRef.current.has(entry.id)) continue;
72+
fetchedWorkspaceIdsRef.current.add(entry.id);
73+
74+
const api = new EcaRemoteApi(entry.host, entry.password, entry.protocol);
75+
api.session()
76+
.then((session) => {
77+
if (session.workspaceFolders?.length) {
78+
setEntries((prev) =>
79+
prev.map((e) =>
80+
e.id === entry.id && !e.workspaceFolders
81+
? { ...e, workspaceFolders: session.workspaceFolders }
82+
: e,
83+
),
84+
);
85+
}
86+
})
87+
.catch(() => { /* server not reachable yet — will populate when session connects */ });
88+
}
89+
}, [entries]);
90+
6191
// --- Deep-link on mount ---
6292

6393
useEffect(() => {

src/storage/connections.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Includes one-time migration from the legacy single-connection format.
66
*/
77

8+
import type { WorkspaceFolder } from '../bridge/types';
89
import type { Protocol } from '../bridge/utils';
910

1011
// ---------------------------------------------------------------------------
@@ -16,6 +17,8 @@ export interface Connection {
1617
host: string;
1718
password: string;
1819
protocol?: Protocol;
20+
/** Cached workspace folders from the last successful session. */
21+
workspaceFolders?: (WorkspaceFolder | string)[];
1922
}
2023

2124
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)