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
| 1 | import { useFocusEffect } from "@react-navigation/native"; |
| 2 | import { isScratchProject } from "@t3tools/client-runtime/state/projects"; |
| 3 | import { runAtomCommand } from "@t3tools/client-runtime/state/runtime"; |
| 4 | import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell"; |
| 5 | import { AsyncResult } from "effect/reactivity"; |
| 6 | import { useCallback } from "react"; |
| 7 | |
| 8 | import { appAtomRegistry } from "../../state/atom-registry"; |
| 9 | import { useEnvironmentServerConfig } from "../../state/entities"; |
| 10 | import { mobilePreferencesAtom, saveMobilePreferences } from "../../state/preferences"; |
| 11 | |
| 12 | export function useRememberThreadProject(project: EnvironmentProject | null) { |
| 13 | const serverConfig = useEnvironmentServerConfig(project?.environmentId ?? null); |
| 14 | const environmentId = project?.environmentId; |
| 15 | const projectId = project?.id; |
| 16 | const remember = |
| 17 | project !== null && |
| 18 | serverConfig !== null && |
| 19 | !isScratchProject(project, serverConfig.scratchWorkspaceRoot); |
| 20 | |
| 21 | useFocusEffect( |
| 22 | useCallback(() => { |
| 23 | if (!remember || !environmentId || !projectId) return; |
| 24 | const preferences = appAtomRegistry.get(mobilePreferencesAtom); |
| 25 | if (!AsyncResult.isSuccess(preferences)) return; |
| 26 | const last = preferences.value.lastThreadProject; |
| 27 | if (last?.environmentId === environmentId && last.projectId === projectId) return; |
| 28 | void runAtomCommand(appAtomRegistry, saveMobilePreferences, { |
| 29 | lastThreadProject: { environmentId, projectId }, |
| 30 | }); |
| 31 | }, [environmentId, projectId, remember]), |
| 32 | ); |
| 33 | } |