diff --git a/apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx b/apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx index a8cc689b7a5cf..d322963820c84 100644 --- a/apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx +++ b/apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx @@ -8,17 +8,23 @@ import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell"; import { shouldCheckoutNewTaskBranch } from "./new-task-context-presentation"; import type { VcsRef } from "@t3tools/client-runtime/state/vcs"; import { + AuthOrchestrationOperateScope, AuthSourceControlWriteScope, + repositoryGroupingDisplayNameOf, resolveEnvironmentMachineKind, type EnvironmentId, } from "@t3tools/contracts"; +import { + canCreateProjectInEnvironment, + getCloneDirectoryName, +} from "@t3tools/client-runtime/operations/projects"; import { LegendList } from "@legendapp/list/react-native"; import { isAtomCommandInterrupted, squashAtomCommandFailure, } from "@t3tools/client-runtime/state/runtime"; import * as Haptics from "expo-haptics"; -import { useNavigation } from "@react-navigation/native"; +import { StackActions, useNavigation } from "@react-navigation/native"; import { T, useGT, useMessages, Var } from "gt-react-native"; import { m } from "../../i18n/messages"; import { useRef, useState, type ReactNode } from "react"; @@ -33,7 +39,8 @@ import { AppText as Text } from "../../components/ui/AppText"; import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol"; import { ThemedSwitch } from "../../components/ui/ThemedSwitch"; import { cn } from "../../lib/cn"; -import { useEnvironmentScope } from "../../state/session"; +import { useEnvironmentScope, useEnvironmentsWithScope } from "../../state/session"; +import { useServerConfigs } from "../../state/entities"; import { useAtomCommand } from "../../state/use-atom-command"; import { vcsEnvironment } from "../../state/vcs"; import { useRefreshBranchesOnFocus } from "./use-refresh-branches-on-focus"; @@ -46,7 +53,10 @@ import { useDebouncedValue, usePaginatedBranches } from "../../state/queries"; import { setPendingConnectionError } from "../../state/use-remote-environment-registry"; import { useEnvironmentPresentation } from "../../state/presentation"; -import { useRemoteConnections } from "../../state/use-remote-environment-registry"; +import { + useRemoteConnectionStatus, + useRemoteConnections, +} from "../../state/use-remote-environment-registry"; import { ConnectionStatusDot } from "../connection/ConnectionStatusDot"; import { ConnectionDiagnosisDetails, @@ -188,11 +198,82 @@ function PickerSurface(props: { readonly children: ReactNode }) { ); } +function AddToMachineRow(props: { + readonly environmentId: EnvironmentId; + readonly title: string; + readonly isLast: boolean; + readonly onPress: () => void; +}) { + const gt = useGT(); + const { presentation } = useEnvironmentPresentation(props.environmentId); + return ( + + + + {props.title} + + + + ); +} + +/** Connected machines without the selected repository that can clone it. */ +function useAddProjectTargets() { + const flow = useNewTaskFlow(); + const { connectedEnvironments } = useRemoteConnectionStatus(); + const serverConfigs = useServerConfigs(); + // The clone destination needs both: writing source control and creating the project. + const canClone = useEnvironmentsWithScope(connectedEnvironments, AuthSourceControlWriteScope); + const canOperate = useEnvironmentsWithScope(connectedEnvironments, AuthOrchestrationOperateScope); + if (flow.isScratchDraft || !flow.selectedProject?.repositoryIdentity?.locator.remoteUrl) { + return []; + } + const hasProject = new Set(flow.environments.map((environment) => environment.environmentId)); + return connectedEnvironments + .filter( + (environment) => + !hasProject.has(environment.environmentId) && + canClone.has(environment.environmentId) && + canOperate.has(environment.environmentId) && + canCreateProjectInEnvironment(environment.connectionState) && + serverConfigs.has(environment.environmentId), + ) + .sort((a, b) => a.environmentLabel.localeCompare(b.environmentLabel)); +} + export function NewTaskEnvironmentPickerRouteScreen() { const gt = useGT(); const flow = useNewTaskFlow(); const navigation = useNavigation(); const insets = useSafeAreaInsets(); + const addTargets = useAddProjectTargets(); + const addToMachine = (environmentId: EnvironmentId) => { + const identity = flow.selectedProject?.repositoryIdentity; + const remoteUrl = identity?.origin?.remoteUrl ?? identity?.locator.remoteUrl; + if (!identity || !remoteUrl) return; + navigation.dispatch( + StackActions.push("AddProjectDestination", { + environmentId, + remoteUrl, + repositoryTitle: + repositoryGroupingDisplayNameOf(identity) ?? flow.selectedProject?.title ?? remoteUrl, + repositoryName: getCloneDirectoryName(remoteUrl), + ...(flow.prompt.trim() ? { prompt: flow.prompt } : {}), + }), + ); + }; return ( navigation.goBack()} /> @@ -224,6 +305,30 @@ export function NewTaskEnvironmentPickerRouteScreen() { /> ))} + {addTargets.length > 0 ? ( + + + {gt("Add to another machine")} + + + {addTargets.map((environment, index) => ( + addToMachine(environment.environmentId)} + /> + ))} + + + ) : null} diff --git a/apps/mobile/src/i18n/translations/de.json b/apps/mobile/src/i18n/translations/de.json index 1116dd8895c6e..1425b63a2fd23 100644 --- a/apps/mobile/src/i18n/translations/de.json +++ b/apps/mobile/src/i18n/translations/de.json @@ -4363,6 +4363,8 @@ "60f1e4428eca5eac": "Verbindungsdetails für {title} ausblenden", "400667ed9c6be7f1": "Verbindungsdetails für {title} anzeigen", "70a6342814614ba1": "Jetzt neu verbinden", + "097cb1e3a26a6336": "Projekt zu {title} hinzufügen", + "656e5640ed1b3e70": "Zu einem anderen Rechner hinzufügen", "24ab73837f60e592": "Branch konnte nicht gewechselt werden", "ae508eab4195971a": "Der Branch konnte nicht ausgecheckt werden.", "b5be5c92de4bd8bf": "Wähle die Repositorys, an denen dieser Thread arbeitet.", diff --git a/apps/mobile/src/i18n/translations/en.json b/apps/mobile/src/i18n/translations/en.json index d9c7d08df765b..4e1500583bcf3 100644 --- a/apps/mobile/src/i18n/translations/en.json +++ b/apps/mobile/src/i18n/translations/en.json @@ -4365,6 +4365,8 @@ "60f1e4428eca5eac": "Hide connection details for {title}", "400667ed9c6be7f1": "Show connection details for {title}", "70a6342814614ba1": "Reconnect now", + "097cb1e3a26a6336": "Add project to {title}", + "656e5640ed1b3e70": "Add to another machine", "24ab73837f60e592": "Could not switch branch", "ae508eab4195971a": "The branch could not be checked out.", "b5be5c92de4bd8bf": "Choose the repositories this thread works on.", diff --git a/apps/mobile/src/i18n/translations/es.json b/apps/mobile/src/i18n/translations/es.json index 8ceac2b26a722..73c3a5671ac2d 100644 --- a/apps/mobile/src/i18n/translations/es.json +++ b/apps/mobile/src/i18n/translations/es.json @@ -4356,6 +4356,8 @@ "60f1e4428eca5eac": "Ocultar los detalles de conexión de {title}", "400667ed9c6be7f1": "Mostrar los detalles de conexión de {title}", "70a6342814614ba1": "Reconectar ahora", + "097cb1e3a26a6336": "Añadir proyecto a {title}", + "656e5640ed1b3e70": "Añadir a otra máquina", "24ab73837f60e592": "No se pudo cambiar de rama", "ae508eab4195971a": "No se pudo hacer checkout de la rama.", "b5be5c92de4bd8bf": "Elige los repositorios en los que trabaja este hilo.", diff --git a/apps/mobile/src/i18n/translations/fr.json b/apps/mobile/src/i18n/translations/fr.json index a6904b69d7f73..3e32199da31f6 100644 --- a/apps/mobile/src/i18n/translations/fr.json +++ b/apps/mobile/src/i18n/translations/fr.json @@ -4357,6 +4357,8 @@ "60f1e4428eca5eac": "Masquer les détails de connexion de {title}", "400667ed9c6be7f1": "Afficher les détails de connexion de {title}", "70a6342814614ba1": "Se reconnecter maintenant", + "097cb1e3a26a6336": "Ajouter le projet à {title}", + "656e5640ed1b3e70": "Ajouter à une autre machine", "24ab73837f60e592": "Impossible de changer de branche", "ae508eab4195971a": "Le checkout de la branche a échoué.", "b5be5c92de4bd8bf": "Choisissez les dépôts sur lesquels ce fil travaille.", diff --git a/apps/mobile/src/i18n/translations/ja.json b/apps/mobile/src/i18n/translations/ja.json index 3ce3515fae73b..533536c6fac32 100644 --- a/apps/mobile/src/i18n/translations/ja.json +++ b/apps/mobile/src/i18n/translations/ja.json @@ -4349,6 +4349,8 @@ "60f1e4428eca5eac": "{title} の接続の詳細を非表示", "400667ed9c6be7f1": "{title} の接続の詳細を表示", "70a6342814614ba1": "今すぐ再接続", + "097cb1e3a26a6336": "{title} にプロジェクトを追加", + "656e5640ed1b3e70": "別のマシンに追加", "24ab73837f60e592": "ブランチを切り替えられませんでした", "ae508eab4195971a": "ブランチをチェックアウトできませんでした。", "b5be5c92de4bd8bf": "このスレッドが作業するリポジトリを選択してください。", diff --git a/apps/mobile/src/i18n/translations/ko.json b/apps/mobile/src/i18n/translations/ko.json index 484ab67231b2e..7b843334ca7db 100644 --- a/apps/mobile/src/i18n/translations/ko.json +++ b/apps/mobile/src/i18n/translations/ko.json @@ -4353,6 +4353,8 @@ "60f1e4428eca5eac": "{title} 연결 세부 정보 숨기기", "400667ed9c6be7f1": "{title} 연결 세부 정보 표시", "70a6342814614ba1": "지금 다시 연결", + "097cb1e3a26a6336": "{title}에 프로젝트 추가", + "656e5640ed1b3e70": "다른 머신에 추가", "24ab73837f60e592": "브랜치를 전환할 수 없습니다", "ae508eab4195971a": "브랜치를 체크아웃할 수 없습니다.", "b5be5c92de4bd8bf": "이 스레드가 작업할 저장소를 선택하세요.", diff --git a/apps/mobile/src/i18n/translations/pt-BR.json b/apps/mobile/src/i18n/translations/pt-BR.json index 4959be9c365b1..5a2344d4c494d 100644 --- a/apps/mobile/src/i18n/translations/pt-BR.json +++ b/apps/mobile/src/i18n/translations/pt-BR.json @@ -4357,6 +4357,8 @@ "60f1e4428eca5eac": "Ocultar detalhes da conexão de {title}", "400667ed9c6be7f1": "Mostrar detalhes da conexão de {title}", "70a6342814614ba1": "Reconectar agora", + "097cb1e3a26a6336": "Adicionar projeto a {title}", + "656e5640ed1b3e70": "Adicionar a outra máquina", "24ab73837f60e592": "Não foi possível trocar de branch", "ae508eab4195971a": "Não foi possível fazer checkout do branch.", "b5be5c92de4bd8bf": "Escolha os repositórios em que esta thread trabalha.", diff --git a/apps/mobile/src/i18n/translations/ru.json b/apps/mobile/src/i18n/translations/ru.json index 7987d3d16485a..041a6edec8911 100644 --- a/apps/mobile/src/i18n/translations/ru.json +++ b/apps/mobile/src/i18n/translations/ru.json @@ -4411,6 +4411,8 @@ "60f1e4428eca5eac": "Скрыть сведения о подключении для {title}", "400667ed9c6be7f1": "Показать сведения о подключении для {title}", "70a6342814614ba1": "Переподключиться сейчас", + "097cb1e3a26a6336": "Добавить проект на {title}", + "656e5640ed1b3e70": "Добавить на другую машину", "24ab73837f60e592": "Не удалось переключить ветку", "ae508eab4195971a": "Не удалось переключиться на ветку.", "b5be5c92de4bd8bf": "Выберите репозитории, с которыми работает этот тред.", diff --git a/apps/mobile/src/i18n/translations/sv.json b/apps/mobile/src/i18n/translations/sv.json index 38f2f3c80172c..97199aa57f145 100644 --- a/apps/mobile/src/i18n/translations/sv.json +++ b/apps/mobile/src/i18n/translations/sv.json @@ -4363,6 +4363,8 @@ "60f1e4428eca5eac": "Dölj anslutningsdetaljer för {title}", "400667ed9c6be7f1": "Visa anslutningsdetaljer för {title}", "70a6342814614ba1": "Återanslut nu", + "097cb1e3a26a6336": "Lägg till projekt på {title}", + "656e5640ed1b3e70": "Lägg till på en annan dator", "24ab73837f60e592": "Kunde inte byta gren", "ae508eab4195971a": "Grenen kunde inte checkas ut.", "b5be5c92de4bd8bf": "Välj vilka repon den här tråden arbetar i.", diff --git a/apps/mobile/src/i18n/translations/zh.json b/apps/mobile/src/i18n/translations/zh.json index e673d0e56ba1b..de27bc6ec7187 100644 --- a/apps/mobile/src/i18n/translations/zh.json +++ b/apps/mobile/src/i18n/translations/zh.json @@ -4358,6 +4358,8 @@ "60f1e4428eca5eac": "隐藏 {title} 的连接详情", "400667ed9c6be7f1": "显示 {title} 的连接详情", "70a6342814614ba1": "立即重新连接", + "097cb1e3a26a6336": "将项目添加到 {title}", + "656e5640ed1b3e70": "添加到另一台机器", "24ab73837f60e592": "无法切换分支", "ae508eab4195971a": "无法检出该分支。", "b5be5c92de4bd8bf": "选择此会话要处理的仓库。",