Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 108 additions & 3 deletions apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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,
Expand Down Expand Up @@ -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 (
<Pressable
accessibilityRole="button"
accessibilityLabel={gt("Add project to {title}", { title: props.title })}
onPress={props.onPress}
className={cn(
"min-h-14 flex-row items-center gap-3 bg-grouped-card px-4 py-3 active:bg-subtle",
!props.isLast && "border-b border-border-subtle",
)}
>
<EnvironmentMachineSymbol
kind={resolveEnvironmentMachineKind(presentation?.serverConfig ?? null)}
size={20}
tintColorClassName="accent-icon-muted"
/>
<Text className="min-w-0 flex-1 text-base font-t3-medium text-foreground" numberOfLines={1}>
{props.title}
</Text>
<SymbolView name="plus" size={15} tintColorClassName="accent-icon-muted" />
</Pressable>
);
}

/** 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),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
)
.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 (
<View className="flex-1 bg-sheet" collapsable={false}>
<AppBar title={gt("Environment")} hideBottomBorder onBack={() => navigation.goBack()} />
Expand Down Expand Up @@ -224,6 +305,30 @@ export function NewTaskEnvironmentPickerRouteScreen() {
/>
))}
</PickerSurface>
{addTargets.length > 0 ? (
<View className="mt-6 gap-2">
<Text
className={
Platform.OS === "android"
? "px-4 text-sm font-t3-medium text-primary-text"
: "px-1 text-2xs font-t3-bold tracking-[0.7px] uppercase text-foreground-muted"
}
>
{gt("Add to another machine")}
</Text>
<PickerSurface>
{addTargets.map((environment, index) => (
<AddToMachineRow
key={String(environment.environmentId)}
environmentId={environment.environmentId}
title={environment.environmentLabel}
isLast={index === addTargets.length - 1}
onPress={() => addToMachine(environment.environmentId)}
/>
))}
</PickerSurface>
</View>
) : null}
</ScrollView>
</ScreenContent>
</View>
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -4349,6 +4349,8 @@
"60f1e4428eca5eac": "{title} の接続の詳細を非表示",
"400667ed9c6be7f1": "{title} の接続の詳細を表示",
"70a6342814614ba1": "今すぐ再接続",
"097cb1e3a26a6336": "{title} にプロジェクトを追加",
"656e5640ed1b3e70": "別のマシンに追加",
"24ab73837f60e592": "ブランチを切り替えられませんでした",
"ae508eab4195971a": "ブランチをチェックアウトできませんでした。",
"b5be5c92de4bd8bf": "このスレッドが作業するリポジトリを選択してください。",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -4353,6 +4353,8 @@
"60f1e4428eca5eac": "{title} 연결 세부 정보 숨기기",
"400667ed9c6be7f1": "{title} 연결 세부 정보 표시",
"70a6342814614ba1": "지금 다시 연결",
"097cb1e3a26a6336": "{title}에 프로젝트 추가",
"656e5640ed1b3e70": "다른 머신에 추가",
"24ab73837f60e592": "브랜치를 전환할 수 없습니다",
"ae508eab4195971a": "브랜치를 체크아웃할 수 없습니다.",
"b5be5c92de4bd8bf": "이 스레드가 작업할 저장소를 선택하세요.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -4411,6 +4411,8 @@
"60f1e4428eca5eac": "Скрыть сведения о подключении для {title}",
"400667ed9c6be7f1": "Показать сведения о подключении для {title}",
"70a6342814614ba1": "Переподключиться сейчас",
"097cb1e3a26a6336": "Добавить проект на {title}",
"656e5640ed1b3e70": "Добавить на другую машину",
"24ab73837f60e592": "Не удалось переключить ветку",
"ae508eab4195971a": "Не удалось переключиться на ветку.",
"b5be5c92de4bd8bf": "Выберите репозитории, с которыми работает этот тред.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -4358,6 +4358,8 @@
"60f1e4428eca5eac": "隐藏 {title} 的连接详情",
"400667ed9c6be7f1": "显示 {title} 的连接详情",
"70a6342814614ba1": "立即重新连接",
"097cb1e3a26a6336": "将项目添加到 {title}",
"656e5640ed1b3e70": "添加到另一台机器",
"24ab73837f60e592": "无法切换分支",
"ae508eab4195971a": "无法检出该分支。",
"b5be5c92de4bd8bf": "选择此会话要处理的仓库。",
Expand Down
Loading