@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 46 lines 1.57 KB
Raw
1 import { rootNavigationRef, whenRootNavigationReady } from "../../lib/rootNavigation";
2 import { isConnectOnboardingOptedOut } from "./connectOnboardingOptOut";
3
4 // Sign-in happens in its own modal; give its session-state transition a beat to
5 // settle before presenting another formSheet on top.
6 const PRESENT_ONBOARDING_DELAY_MS = 600;
7
8 interface PendingRequest {
9 readonly accountId: string;
10 readonly timer: ReturnType<typeof setTimeout>;
11 }
12
13 // Retain the account id so sign-out cannot present onboarding for the wrong account.
14 let pending: PendingRequest | null = null;
15
16 export function requestConnectOnboarding(accountId: string): void {
17 clearConnectOnboardingRequest();
18 const request: PendingRequest = {
19 accountId,
20 timer: setTimeout(() => {
21 void (async () => {
22 const optedOut = await isConnectOnboardingOptedOut(accountId).catch(() => false);
23 // A sign-out or a newer sign-in may have replaced this request while
24 // the opt-out read was in flight.
25 if (pending !== request) return;
26 if (optedOut) {
27 pending = null;
28 return;
29 }
30 // Stays pending until navigation is ready, so a sign-out meanwhile still cancels it.
31 whenRootNavigationReady(() => {
32 if (pending !== request) return;
33 pending = null;
34 rootNavigationRef.navigate("ConnectOnboarding");
35 });
36 })();
37 }, PRESENT_ONBOARDING_DELAY_MS),
38 };
39 pending = request;
40 }
41
42 export function clearConnectOnboardingRequest(): void {
43 if (pending === null) return;
44 clearTimeout(pending.timer);
45 pending = null;
46 }