The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useFocusEffect, useNavigation } from "@react-navigation/native"; |
| 2 | import { useCallback } from "react"; |
| 3 | |
| 4 | import { useProjects } from "../../state/entities"; |
| 5 | import { useConnectionsReady, useWorkspaceEnvironments } from "../../state/workspace"; |
| 6 | import { |
| 7 | pullRequestFallbackEnvironment, |
| 8 | type PullRequestEnvironmentTarget, |
| 9 | } from "./pullRequestEnvironmentFallback"; |
| 10 | |
| 11 | export function usePullRequestEnvironmentFallback(params: PullRequestEnvironmentTarget) { |
| 12 | const navigation = useNavigation(); |
| 13 | const projects = useProjects(); |
| 14 | const isReady = useConnectionsReady(); |
| 15 | const environments = useWorkspaceEnvironments(); |
| 16 | const fallback = isReady ? pullRequestFallbackEnvironment(params, projects, environments) : null; |
| 17 | // Only while focused: a screen kept as a placeholder throws on any navigation action. |
| 18 | useFocusEffect( |
| 19 | useCallback(() => { |
| 20 | if (fallback) navigation.setParams(fallback); |
| 21 | }, [fallback, navigation]), |
| 22 | ); |
| 23 | } |