Skip to content

Commit fe2297c

Browse files
fix(mobile): Add project keeps a typed path per host
The path state kept one path tagged with its host, so editing on host B lost host A's path. Each host now keeps its own; with no host selected the field shows the last path typed anywhere, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 21f708e commit fe2297c

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎apps/mobile/src/features/projects/AddProjectScreen.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,19 @@ describe("local folder path", () => {
758758
expect(screen.path).toBe("~/");
759759
});
760760

761+
it("keeps each host's typed path when switching between hosts", async () => {
762+
await using screen = mountLocalFolder();
763+
await screen.render("environment");
764+
await screen.type("/work/a");
765+
await screen.render("another-environment");
766+
await screen.type("~/b");
767+
768+
await screen.render("environment");
769+
expect(screen.path).toBe("/work/a");
770+
await screen.render("another-environment");
771+
expect(screen.path).toBe("~/b");
772+
});
773+
761774
it("keeps a typed path when the default host drops out and comes back", async () => {
762775
await using screen = mountLocalFolder();
763776
await screen.render();

‎apps/mobile/src/features/projects/AddProjectScreen.tsx‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,23 @@ function useBrowsePathInput(environment: EnvironmentOption | null, pinnedDirecto
296296
getAddProjectInitialQuery(environmentBaseDirectory),
297297
pinnedDirectoryName,
298298
);
299-
// Only the last typed or browsed path is kept, tagged with its host. Other hosts show their
300-
// own default; a host that drops out briefly (null) keeps showing the path, and returning to
301-
// the tagged host restores it unless the path was edited on another host meanwhile.
302-
const [pathState, setPathState] = useState({ environmentId, path: seedPath });
299+
// Each host keeps the path last typed or browsed for it, and shows its own default until then,
300+
// so switching hosts and back loses nothing. With no host selected (one dropping out briefly),
301+
// the field keeps the last path typed anywhere.
302+
const [paths, setPaths] = useState<{
303+
readonly byHost: ReadonlyMap<EnvironmentId, string>;
304+
readonly last: string;
305+
}>(() => ({ byHost: new Map(), last: seedPath }));
303306
const pathInput =
304-
environmentId === null || pathState.environmentId === environmentId ? pathState.path : seedPath;
305-
const commitPathInput = (path: string) => setPathState({ environmentId, path });
307+
environmentId === null ? paths.last : (paths.byHost.get(environmentId) ?? seedPath);
308+
const commitPathInput = (path: string) =>
309+
setPaths((current) => {
310+
const byHost = new Map(current.byHost);
311+
if (environmentId !== null) {
312+
byHost.set(environmentId, path);
313+
}
314+
return { byHost, last: path };
315+
});
306316
const environmentRuntime = useRemoteEnvironmentRuntime(environmentId);
307317
const loadBrowsePath = useAtomQueryRunner(filesystemEnvironment.browse, {
308318
reportFailure: false,

0 commit comments

Comments
 (0)