Skip to content

Commit bc57a9f

Browse files
fix(mobile): pass the cloning flag and wait for the project before opening its draft
The flag was dropped in the rebase; without it Start was enabled before the clone stream reported. The draft also waits briefly for the project.created event so it opens on the new project instead of its picker. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 3722273 commit bc57a9f

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import * as Order from "effect/Order";
4949
import { AsyncResult } from "effect/unstable/reactivity";
5050
import { cn } from "../../lib/cn";
5151

52-
import { useProjects, useServerConfigs } from "../../state/entities";
52+
import { useProjects, useServerConfigs, waitForProject } from "../../state/entities";
5353
import { filesystemEnvironment } from "../../state/filesystem";
5454
import { projectEnvironment } from "../../state/projects";
5555
import { useEnvironmentQuery } from "../../state/query";
@@ -972,10 +972,15 @@ export function AddProjectDestinationScreen(props: {
972972
if (AsyncResult.isFailure(startResult)) {
973973
setError(errorMessage(Cause.squash(startResult.cause)));
974974
} else {
975+
// The create event usually lands before the RPC returns; give the
976+
// shell stream a moment so the draft opens on the new project rather
977+
// than falling back to its picker.
978+
await waitForProject({ environmentId: environment.environmentId, projectId }, 3_000);
975979
openNewTaskDraft(navigation, {
976980
environmentId: environment.environmentId,
977981
projectId,
978982
title,
983+
cloning: "1",
979984
});
980985
}
981986
setIsSubmitting(false);

‎apps/mobile/src/state/entities.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { useAtomValue } from "@effect/atom-react";
2+
3+
import { appAtomRegistry } from "./atom-registry";
24
import type {
35
EnvironmentProject,
46
EnvironmentThreadShell,
@@ -25,6 +27,31 @@ const EMPTY_SERVER_CONFIG_ATOM = Atom.make<ServerConfig | null>(null).pipe(
2527
Atom.withLabel("mobile-server-config:empty"),
2628
);
2729

30+
/** Resolves when the project event reaches the live client store. */
31+
export function waitForProject(
32+
ref: ScopedProjectRef,
33+
timeoutMs = 10_000,
34+
): Promise<EnvironmentProject | null> {
35+
const atom = environmentProjects.projectAtom(ref);
36+
const current = appAtomRegistry.get(atom);
37+
if (current !== null) return Promise.resolve(current);
38+
return new Promise((resolve) => {
39+
let unsubscribe: (() => void) | null = null;
40+
const timeout = setTimeout(() => {
41+
unsubscribe?.();
42+
resolve(null);
43+
}, timeoutMs);
44+
const finish = (project: EnvironmentProject | null) => {
45+
if (project === null) return;
46+
clearTimeout(timeout);
47+
unsubscribe?.();
48+
resolve(project);
49+
};
50+
unsubscribe = appAtomRegistry.subscribe(atom, finish);
51+
finish(appAtomRegistry.get(atom));
52+
});
53+
}
54+
2855
export function useProjects(): ReadonlyArray<EnvironmentProject> {
2956
return useAtomValue(environmentProjects.projectsAtom);
3057
}

0 commit comments

Comments
 (0)