Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -629,17 +629,19 @@ function AdaptiveWorkspaceLayoutContent(
.filter((environment) => environment.connectionState === "connected")
.map((environment) => environment.environmentId),
);
const currentProject = environmentId && projectId ? { environmentId, projectId } : undefined;
handleSelectThreadRoute(
newTaskDestination({
projects,
requestId: uuidv4(),
useLastProject: saved?.useLastProjectForNewThreads,
currentProject: environmentId && projectId ? { environmentId, projectId } : undefined,
currentProject,
filteredProject: filteredScope
? newTaskFilteredProject(
filteredScope,
listEnvironmentId,
connectedEnvironmentIds,
currentProject,
saved?.lastThreadProject,
)
: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe("newTaskFilteredProject", () => {
makeScope([mac, server]),
null,
new Set([mac.environmentId, server.environmentId]),
undefined,
{ environmentId: "mac", projectId: "t3code" },
),
).toEqual({ environmentId: "server", projectId: "t3code" });
Expand All @@ -98,7 +99,7 @@ describe("newTaskFilteredProject", () => {
const server = makeProject("t3code", "server");
const connected = new Set([mac.environmentId, server.environmentId]);
const filtered = (last?: { readonly environmentId: string; readonly projectId: string }) =>
newTaskFilteredProject(makeScope([mac, server]), null, connected, last);
newTaskFilteredProject(makeScope([mac, server]), null, connected, undefined, last);
expect(filtered({ environmentId: "server", projectId: "t3code" })).toEqual({
environmentId: "server",
projectId: "t3code",
Expand All @@ -108,6 +109,20 @@ describe("newTaskFilteredProject", () => {
projectId: "t3code",
});
});

it("starts in the current thread's copy of the filtered project", () => {
const mac = makeProject("t3code", "mac");
const server = makeProject("t3code", "server");
const connected = new Set([mac.environmentId, server.environmentId]);
const remembered = { environmentId: "mac", projectId: "t3code" };
const filtered = (current: { readonly environmentId: string; readonly projectId: string }) =>
newTaskFilteredProject(makeScope([mac, server]), null, connected, current, remembered);
expect(filtered({ environmentId: "server", projectId: "t3code" })).toEqual({
environmentId: "server",
projectId: "t3code",
});
expect(filtered({ environmentId: "server", projectId: "other" })).toEqual(remembered);
});
});

describe("resolveEnvironmentProjectMatch", () => {
Expand Down Expand Up @@ -252,15 +267,26 @@ describe("newTaskDestination", () => {
});
}

it("starts in the current thread's project ahead of the filtered and remembered ones", () => {
const projects = [makeProject("remembered"), makeProject("current", "other-environment")];
it("starts in the thread list's filtered project ahead of a current thread outside it", () => {
const projects = [makeProject("filtered"), makeProject("current", "other-environment")];
const last = { environmentId: "environment", projectId: "remembered" };
expect(
destination({
useLastProject: true,
projects,
projects: [...projects, makeProject("remembered")],
current: projects[1],
filtered: projects[0],
last: { environmentId: "environment", projectId: "remembered" },
last,
}),
).toEqual({
draft: { requestId: "request", environmentId: "environment", projectId: "filtered" },
});
expect(
destination({
useLastProject: true,
projects: [...projects, makeProject("remembered")],
current: projects[1],
last,
}),
).toEqual({
draft: { requestId: "request", environmentId: "other-environment", projectId: "current" },
Expand Down
23 changes: 15 additions & 8 deletions apps/mobile/src/features/threads/new-task-project-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,27 @@ export function resolveDraftProjectSelection(

type ProjectRef = { readonly environmentId: string; readonly projectId: string };

/** The live copy of the thread list's filtered project a new thread starts in: the remembered one if it is a copy. */
const isProjectRef = (project: EnvironmentProject, ref: ProjectRef | undefined) =>
project.environmentId === ref?.environmentId && project.id === ref.projectId;

/**
* The copy of the thread list's filtered project a new thread starts in: the current thread's
* if it is a copy, else the remembered live one, else a live one on a connected machine.
*/
export function newTaskFilteredProject(
scope: HomeProjectScope,
preferredEnvironmentId: EnvironmentId | null,
connectedEnvironmentIds: ReadonlySet<EnvironmentId>,
currentProject: ProjectRef | undefined,
lastProject: ProjectRef | undefined,
): ProjectRef | undefined {
if (scope.projects.some((project) => isProjectRef(project, currentProject))) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
return currentProject;
}
const live = scope.projects.filter((project) => project.archivedAt == null);
if (live.length === 0) return undefined;
const project =
live.find(
(candidate) =>
candidate.environmentId === lastProject?.environmentId &&
candidate.id === lastProject.projectId,
) ??
live.find((candidate) => isProjectRef(candidate, lastProject)) ??
getProjectScopeSelectionTarget(
{ ...scope, projects: live },
preferredEnvironmentId,
Expand All @@ -212,13 +218,14 @@ export function newTaskDestination(options: {
options.projects.find(
(project) => project.environmentId === ref.environmentId && project.id === ref.projectId,
);
// The list filter is the user's explicit choice, so a current thread outside it doesn't win.
// A remembered project that was archived since opens the picker; the current one still wins.
const last = find(options.lastProject);
const project =
options.useLastProject === false
? undefined
: (find(options.currentProject) ??
find(options.filteredProject) ??
: (find(options.filteredProject) ??
find(options.currentProject) ??
(last?.archivedAt == null ? last : undefined));
return project
? {
Expand Down
4 changes: 2 additions & 2 deletions docs/user/thread-sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ your model and mode selections, unless the destination project has its own model
Its branch and workspace mode come from your configured defaults. To continue in
an existing worktree, use **New thread in this worktree** from the branch toolbar.

On mobile, **New thread** starts in the current thread's project, or else in the
project the thread list is filtered to, or else in the last project you opened
On mobile, **New thread** starts in the project the thread list is filtered to,
or else in the current thread's project, or else in the last project you opened
or chose on that device. If none is available, the project picker opens. Turn
off **Settings → General → Use last project** to choose a project every time.
When you pick a project that is on more than one machine, the thread starts on
Expand Down
Loading