Skip to content

Commit 90b0f02

Browse files
fix(mobile): new-task links and waitlist links respect the editor and cloud config
- A new-task link no longer drops an editor's unsaved changes before its removal guard runs; the draft clears only once the user discards it. - settings/waitlist joins the cloud-only deep links, since it renders the same SettingsAuth screen. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c4d1d19 commit 90b0f02

6 files changed

Lines changed: 66 additions & 28 deletions

File tree

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ import {
7878
} from "./scheduledTaskDraft";
7979
import { settingsTargetsForProject } from "./settings-environment-filter.logic";
8080
import { useScheduledTaskEditor } from "./scheduled-task-editor";
81-
import { scheduledTaskEditorSessionAtom } from "./scheduled-task-editor-state";
81+
import {
82+
discardScheduledTaskEditor,
83+
scheduledTaskEditorSessionAtom,
84+
} from "./scheduled-task-editor-state";
8285
import { appAtomRegistry } from "../../state/atom-registry";
8386
import {
8487
formatNextScheduledTaskRun,
@@ -460,15 +463,8 @@ export function SettingsScheduledTaskEditRouteScreen() {
460463
}
461464

462465
function SettingsScheduledTaskEditorScreen({ title }: { readonly title: string }) {
463-
const {
464-
editor,
465-
voiceOwnerKey,
466-
readEditor,
467-
setEditor,
468-
startEditor,
469-
hasChanges,
470-
draftForEnvironment,
471-
} = useScheduledTaskEditor();
466+
const { editor, voiceOwnerKey, readEditor, setEditor, hasChanges, draftForEnvironment } =
467+
useScheduledTaskEditor();
472468
const { availableTargets } = useSettingsEnvironmentFilter();
473469
const navigation = useNavigation();
474470
const insets = useSafeAreaInsets();
@@ -530,7 +526,7 @@ function SettingsScheduledTaskEditorScreen({ title }: { readonly title: string }
530526
style: "destructive",
531527
onPress: () => {
532528
if (voiceInput.isBusy) voiceInput.cancel();
533-
startEditor(null);
529+
discardScheduledTaskEditor();
534530
navigation.dispatch(data.action);
535531
},
536532
},

‎apps/mobile/src/features/settings/scheduled-task-editor-state.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { afterEach, describe, expect, it } from "vite-plus/test";
44
import { appAtomRegistry } from "../../state/atom-registry";
55
import { createDraft } from "./scheduledTaskDraft";
66
import {
7+
discardScheduledTaskEditor,
78
readScheduledTaskEditor,
89
scheduledTaskEditorSessionAtom,
910
startScheduledTaskEditor,
@@ -81,6 +82,24 @@ describe("new scheduled task link", () => {
8182
expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)).toBeNull();
8283
});
8384

85+
it("keeps unsaved changes until the editor's removal guard discards them", () => {
86+
startScheduledTaskEditor(editing);
87+
const edited = { ...editing, draft: { ...editing.draft, prompt: "unsaved" } };
88+
updateScheduledTaskEditor(edited, null);
89+
90+
takeScheduledTaskNewLink(newTaskLink);
91+
expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)?.current).toBe(edited);
92+
93+
discardScheduledTaskEditor();
94+
expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)).toBeNull();
95+
});
96+
97+
it("closes a discarded editor as empty when no new-task link is waiting", () => {
98+
startScheduledTaskEditor(editing);
99+
discardScheduledTaskEditor();
100+
expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)?.current).toBeNull();
101+
});
102+
84103
it("keeps the editor for links to other screens", () => {
85104
startScheduledTaskEditor(editing);
86105
takeScheduledTaskNewLink({ routes: [{ name: "SettingsSheet" }] });

‎apps/mobile/src/features/settings/scheduled-task-editor-state.ts‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Atom } from "effect/reactivity";
55
import { findLinkedRoute } from "../../lib/appLinking";
66

77
import { appAtomRegistry } from "../../state/atom-registry";
8-
import type { ScheduledTaskDraft } from "./scheduledTaskDraft";
8+
import { hasScheduledTaskDraftChanges, type ScheduledTaskDraft } from "./scheduledTaskDraft";
99

1010
export type ScheduledTaskEditor = {
1111
readonly environmentId: EnvironmentId;
@@ -23,8 +23,22 @@ export const scheduledTaskEditorSessionAtom = Atom.make<ScheduledTaskEditorSessi
2323
null,
2424
).pipe(Atom.keepAlive);
2525
let nextEditorId = 0;
26+
let newTaskLinkAwaitsDiscard = false;
27+
28+
export function scheduledTaskEditorHasChanges(
29+
initial: ScheduledTaskEditor | null,
30+
current: ScheduledTaskEditor | null,
31+
): boolean {
32+
return Boolean(
33+
initial &&
34+
current &&
35+
(initial.environmentId !== current.environmentId ||
36+
hasScheduledTaskDraftChanges(initial.draft, current.draft)),
37+
);
38+
}
2639

2740
export function startScheduledTaskEditor(next: ScheduledTaskEditor | null): void {
41+
newTaskLinkAwaitsDiscard = false;
2842
appAtomRegistry.set(scheduledTaskEditorSessionAtom, {
2943
id: ++nextEditorId,
3044
initial: next,
@@ -58,15 +72,30 @@ export function readScheduledTaskEditor(
5872
}
5973

6074
/**
61-
* A link to the new-task screen starts a fresh editor, like the in-app "New
62-
* task" action. Without this a warm app would reopen the last edited task's
63-
* draft under the "New" title and save over that task.
75+
* A new-task link starts a fresh editor, or a warm app reopens the last task's draft under
76+
* "New" and saves over it. Links parse before the open editor's removal guard runs, so
77+
* unsaved changes stay until the user discards them there.
6478
*/
6579
export function takeScheduledTaskNewLink(
6680
state: PartialState<NavigationState> | undefined,
6781
): PartialState<NavigationState> | undefined {
6882
if (findLinkedRoute(state, ["SettingsScheduledTaskNew"])) {
69-
appAtomRegistry.set(scheduledTaskEditorSessionAtom, null);
83+
const session = appAtomRegistry.get(scheduledTaskEditorSessionAtom);
84+
if (session && scheduledTaskEditorHasChanges(session.initial, session.current)) {
85+
newTaskLinkAwaitsDiscard = true;
86+
} else {
87+
appAtomRegistry.set(scheduledTaskEditorSessionAtom, null);
88+
}
7089
}
7190
return state;
7291
}
92+
93+
/** Drops unsaved changes; a new-task link that waited on them then opens a fresh editor. */
94+
export function discardScheduledTaskEditor(): void {
95+
if (newTaskLinkAwaitsDiscard) {
96+
newTaskLinkAwaitsDiscard = false;
97+
appAtomRegistry.set(scheduledTaskEditorSessionAtom, null);
98+
return;
99+
}
100+
startScheduledTaskEditor(null);
101+
}

‎apps/mobile/src/features/settings/scheduled-task-editor.tsx‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ import type { EnvironmentId } from "@t3tools/contracts";
33
import { useMemo, useCallback, type Dispatch, type SetStateAction } from "react";
44

55
import { useProjects, useServerConfigs } from "../../state/entities";
6-
import {
7-
createDraft,
8-
scheduledTaskDefaultModel,
9-
hasScheduledTaskDraftChanges,
10-
} from "./scheduledTaskDraft";
6+
import { createDraft, scheduledTaskDefaultModel } from "./scheduledTaskDraft";
117
import { useSettingsEnvironmentFilter } from "./settings-environment-filter";
128
import { settingsTargetsForProject } from "./settings-environment-filter.logic";
139

1410
import {
11+
scheduledTaskEditorHasChanges,
1512
scheduledTaskEditorSessionAtom,
1613
startScheduledTaskEditor,
1714
updateScheduledTaskEditor,
@@ -64,12 +61,7 @@ export function useScheduledTaskEditor() {
6461
const voiceOwnerKey = `scheduled-task:${session?.id ?? 0}`;
6562
const editor = session ? session.current : defaultEditor;
6663
const initial = session ? session.initial : defaultEditor;
67-
const hasChanges = Boolean(
68-
initial &&
69-
editor &&
70-
(initial.environmentId !== editor.environmentId ||
71-
hasScheduledTaskDraftChanges(initial.draft, editor.draft)),
72-
);
64+
const hasChanges = scheduledTaskEditorHasChanges(initial, editor);
7365
const setEditor = useCallback<Dispatch<SetStateAction<ScheduledTaskEditor | null>>>(
7466
(update) => {
7567
updateScheduledTaskEditor(update, defaultEditor);

‎apps/mobile/src/lib/appLinking.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe("cloud-only deep links", () => {
3030
it.each([
3131
"t3code://connect-onboarding",
3232
"t3code-dev://connect-onboarding/?source=x",
33+
"t3code://settings/waitlist",
3334
"t3code://settings/auth",
3435
"exp://192.168.1.2:8081/--/settings/auth",
3536
])("ignores %s without cloud config", (url) => {

‎apps/mobile/src/lib/appLinking.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export function shouldHandleAppLink(url: string, cloudConfigured: boolean): bool
1919
* Screens that only exist with T3 Connect configured. A build without it has
2020
* no entry points to them, so a link must not open one empty.
2121
*/
22-
const CLOUD_ONLY_LINK_PATH = /(?:^[a-z][\w+.-]*:\/*|\/)(?:connect-onboarding|settings\/auth)\/*$/i;
22+
const CLOUD_ONLY_LINK_PATH =
23+
/(?:^[a-z][\w+.-]*:\/*|\/)(?:connect-onboarding|settings\/(?:auth|waitlist))\/*$/i;
2324

2425
/** Keep the published draft URLs while using the root thread screen. */
2526
export function restoreDraftLinkState(

0 commit comments

Comments
 (0)