Skip to content

Commit bd79daa

Browse files
committed
fix(mobile): enable last-project reuse by default
1 parent d14d490 commit bd79daa

5 files changed

Lines changed: 59 additions & 40 deletions

File tree

‎apps/mobile/src/features/settings/SettingsThreadsRouteScreen.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function NewThreadSettingsSection() {
6969
subtitle="Start in the last project you used on this device."
7070
value={
7171
AsyncResult.isSuccess(preferences) &&
72-
preferences.value.useLastProjectForNewThreads === true
72+
preferences.value.useLastProjectForNewThreads !== false
7373
}
7474
disabled={!ready}
7575
onValueChange={(value) => savePreferences({ useLastProjectForNewThreads: value })}

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

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -101,38 +101,55 @@ describe("resolveDraftProjectSelection", () => {
101101
describe("newTaskDestination", () => {
102102
const request = { draft: { requestId: "request" } };
103103

104-
it.each([undefined, false])("opens the picker when the preference is %s", (useLastProject) => {
104+
it("opens the picker when the preference is disabled", () => {
105105
const projects = [makeProject("first"), makeProject("current", "other-environment")];
106106
expect(
107-
newTaskDestination(useLastProject, projects, projects[1], "request", {
107+
newTaskDestination(false, projects, projects[1], "request", {
108108
environmentId: "environment",
109109
projectId: "first",
110110
}),
111111
).toEqual(request);
112112
});
113113

114-
it("uses the current thread or draft project when enabled", () => {
115-
const projects = [makeProject("first"), makeProject("current", "other-environment")];
114+
it.each([undefined, true])(
115+
"uses the current project when the preference is %s",
116+
(useLastProject) => {
117+
const projects = [makeProject("first"), makeProject("current", "other-environment")];
118+
expect(
119+
newTaskDestination(useLastProject, projects, projects[1], "request", {
120+
environmentId: "environment",
121+
projectId: "first",
122+
}),
123+
).toEqual({
124+
draft: { requestId: "request", environmentId: "other-environment", projectId: "current" },
125+
});
126+
},
127+
);
128+
129+
it.each([undefined, true])(
130+
"remembers the last project from Home when the preference is %s",
131+
(useLastProject) => {
132+
const projects = [makeProject("same-id"), makeProject("same-id", "other-environment")];
133+
expect(
134+
newTaskDestination(useLastProject, projects, undefined, "request", {
135+
environmentId: "other-environment",
136+
projectId: "same-id",
137+
}),
138+
).toEqual({
139+
draft: { requestId: "request", environmentId: "other-environment", projectId: "same-id" },
140+
});
141+
},
142+
);
143+
144+
it("opens the picker by default when no last project exists", () => {
116145
expect(
117-
newTaskDestination(true, projects, projects[1], "request", {
118-
environmentId: "environment",
119-
projectId: "first",
120-
}),
121-
).toEqual({
122-
draft: { requestId: "request", environmentId: "other-environment", projectId: "current" },
123-
});
124-
});
125-
126-
it("remembers the last project from Home without relying on project order", () => {
127-
const projects = [makeProject("same-id"), makeProject("same-id", "other-environment")];
128-
expect(
129-
newTaskDestination(true, projects, undefined, "request", {
130-
environmentId: "other-environment",
131-
projectId: "same-id",
132-
}),
133-
).toEqual({
134-
draft: { requestId: "request", environmentId: "other-environment", projectId: "same-id" },
135-
});
146+
newTaskDestination(
147+
undefined,
148+
[makeProject("first"), makeProject("second")],
149+
undefined,
150+
"request",
151+
),
152+
).toEqual(request);
136153
});
137154

138155
it("uses the remembered project when the current project is stale", () => {

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,19 @@ export function newTaskDestination(
9898
requestId: string,
9999
lastProject?: { readonly environmentId: string; readonly projectId: string },
100100
) {
101-
const project = useLastProject
102-
? (projects.find(
103-
(candidate) =>
104-
candidate.environmentId === currentProject?.environmentId &&
105-
candidate.id === currentProject.id,
106-
) ??
107-
projects.find(
108-
(candidate) =>
109-
candidate.environmentId === lastProject?.environmentId &&
110-
candidate.id === lastProject.projectId,
111-
))
112-
: undefined;
101+
const project =
102+
useLastProject !== false
103+
? (projects.find(
104+
(candidate) =>
105+
candidate.environmentId === currentProject?.environmentId &&
106+
candidate.id === currentProject.id,
107+
) ??
108+
projects.find(
109+
(candidate) =>
110+
candidate.environmentId === lastProject?.environmentId &&
111+
candidate.id === lastProject.projectId,
112+
))
113+
: undefined;
113114
return project
114115
? {
115116
draft: {

‎apps/mobile/src/persistence/mobile-preferences.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const makeStore = Effect.fn("test.makePreferencesStore")(function* (initial: unk
3737
});
3838

3939
describe("new-thread project preferences", () => {
40-
it.effect("leaves the preference off for existing installations", () =>
40+
it.effect("keeps missing new-thread preferences unset for existing installations", () =>
4141
Effect.gen(function* () {
4242
const openStore = yield* makeStore({ workingShelfEnabled: true });
4343
const store = yield* openStore;

‎docs/user/thread-sidebar.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ and mode selections, unless the destination project has its own model default.
1010
Its branch and workspace mode come from your configured defaults. To continue in
1111
an existing worktree, use **New thread in this worktree** from the branch toolbar.
1212

13-
On mobile, new threads open the project picker. Turn on **Settings → Thread behavior →
14-
Use last project** to reuse the last project you opened or chose on that device,
15-
including after restarting the app. Project-specific actions always use the project you chose.
13+
On mobile, new threads reuse the last project you opened or chose on that device,
14+
including after restarting the app. Turn off **Settings → Thread behavior → Use last project**
15+
to choose a project each time. If no previous project is available, the project picker opens.
16+
Project-specific actions always use the project you chose.
1617

1718
When you change a new thread's project, T3 Code stays in the current environment
1819
if that project exists there. Otherwise it selects an environment that has it.

0 commit comments

Comments
 (0)