Skip to content

Commit 9810a0c

Browse files
committed
refactor(mobile): simplify scratch option selection
1 parent 86d6898 commit 9810a0c

1 file changed

Lines changed: 7 additions & 28 deletions

File tree

‎apps/mobile/src/features/threads/new-task-project-selection.ts‎

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,52 +38,31 @@ export function filterProjectScopes(
3838
);
3939
}
4040

41-
export interface NewTaskScratchOption {
42-
readonly environmentId: EnvironmentId;
43-
/** False while the environment is still connecting; the row shows but cannot start yet. */
44-
readonly ready: boolean;
45-
}
46-
47-
/**
48-
* Project rows and the server config both restore from cache before the
49-
* connection is up, so the "No project" row is decided from the config alone.
50-
* Gating it on the connection phase too made it pop in once connected and
51-
* shift the rows below it. The phase only decides whether it is enabled. The
52-
* two cache reads are separate, so a config that was never cached can still
53-
* arrive after the rows; that case is not covered here.
54-
*/
41+
// Cached configuration reserves the row; connection readiness only gates activation.
5542
export function resolveNewTaskScratchOption(input: {
5643
readonly environments: ReadonlyArray<{
5744
readonly environmentId: EnvironmentId;
5845
readonly connectionState: EnvironmentConnectionPhase;
5946
}>;
6047
readonly serverConfigs: ReadonlyMap<EnvironmentId, Pick<ServerConfig, "scratchWorkspaceRoot">>;
6148
readonly selectedEnvironmentId: EnvironmentId | null;
62-
}): NewTaskScratchOption | null {
49+
}) {
6350
const offering = input.environments.filter(
6451
(environment) =>
6552
(input.serverConfigs.get(environment.environmentId)?.scratchWorkspaceRoot ?? null) !== null,
6653
);
67-
if (offering.length === 0) return null;
6854
const ready = offering.filter(
6955
(environment) =>
7056
availableScratchWorkspaceRoot(
7157
environment.connectionState,
7258
input.serverConfigs.get(environment.environmentId),
7359
) !== null,
7460
);
75-
const preferred = (candidates: typeof offering) =>
76-
candidates.find((environment) => environment.environmentId === input.selectedEnvironmentId) ??
77-
candidates[0] ??
78-
null;
79-
const readyEnvironment = preferred(ready);
80-
if (readyEnvironment !== null) {
81-
return { environmentId: readyEnvironment.environmentId, ready: true };
82-
}
83-
const pendingEnvironment = preferred(offering);
84-
return pendingEnvironment === null
85-
? null
86-
: { environmentId: pendingEnvironment.environmentId, ready: false };
61+
const candidates = ready.length > 0 ? ready : offering;
62+
const environment =
63+
candidates.find((candidate) => candidate.environmentId === input.selectedEnvironmentId) ??
64+
candidates[0];
65+
return environment ? { environmentId: environment.environmentId, ready: ready.length > 0 } : null;
8766
}
8867

8968
function getOnlySelectableProject(

0 commit comments

Comments
 (0)