Skip to content

Commit e6bbe15

Browse files
refactor(mobile): share connection form fields
1 parent 53510d4 commit e6bbe15

3 files changed

Lines changed: 63 additions & 56 deletions

File tree

‎apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx‎

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useCallback, useState } from "react";
99
import { Platform, Alert, Pressable, View } from "react-native";
1010
import Animated, { FadeIn, FadeOut, LinearTransition } from "react-native-reanimated";
1111

12-
import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
12+
import { AppText as Text } from "../../components/AppText";
1313
import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
1414
import { MaterialButton } from "../../components/MaterialButton";
1515
import { MaterialIconButton } from "../../components/MaterialIconButton";
@@ -18,6 +18,7 @@ import { cn } from "../../lib/cn";
1818
import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
1919
import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types";
2020
import { serverEnvironment } from "../../state/server";
21+
import { ConnectionFormField } from "./ConnectionFormField";
2122
import { ConnectionStatusDot } from "./ConnectionStatusDot";
2223

2324
function connectionStatusLabel(environment: ConnectedEnvironmentSummary): string | null {
@@ -164,34 +165,24 @@ export function ConnectionEnvironmentRow(props: {
164165
</Text>
165166
) : (
166167
<>
167-
<View className="gap-1.5">
168-
<Text className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">
169-
Label
170-
</Text>
171-
<TextInput
172-
autoCapitalize="words"
173-
autoCorrect={false}
174-
placeholder="My MacBook"
175-
value={label}
176-
onChangeText={setLabel}
177-
className="rounded-[14px] border border-input-border bg-input px-4 py-3 text-base text-foreground"
178-
/>
179-
</View>
168+
<ConnectionFormField
169+
label="Label"
170+
autoCapitalize="words"
171+
autoCorrect={false}
172+
placeholder="My MacBook"
173+
value={label}
174+
onChangeText={setLabel}
175+
/>
180176

181-
<View className="gap-1.5">
182-
<Text className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">
183-
URL
184-
</Text>
185-
<TextInput
186-
autoCapitalize="none"
187-
autoCorrect={false}
188-
keyboardType="url"
189-
placeholder="192.168.1.100:8080"
190-
value={url}
191-
onChangeText={setUrl}
192-
className="rounded-[14px] border border-input-border bg-input px-4 py-3 text-base text-foreground"
193-
/>
194-
</View>
177+
<ConnectionFormField
178+
label="URL"
179+
autoCapitalize="none"
180+
autoCorrect={false}
181+
keyboardType="url"
182+
placeholder="192.168.1.100:8080"
183+
value={url}
184+
onChangeText={setUrl}
185+
/>
195186
</>
196187
)}
197188

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { View } from "react-native";
2+
3+
import { AppText, AppTextInput, type AppTextInputProps } from "../../components/AppText";
4+
import { cn } from "../../lib/cn";
5+
6+
type ConnectionFormFieldProps = Omit<AppTextInputProps, "className"> & {
7+
readonly label: string;
8+
readonly className?: string;
9+
};
10+
11+
/** Labeled connection input with a native wrapper retained inside form sheets. */
12+
export function ConnectionFormField({ label, className, ...inputProps }: ConnectionFormFieldProps) {
13+
return (
14+
<View collapsable={false} className={cn("gap-1.5", className)}>
15+
<AppText className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">
16+
{label}
17+
</AppText>
18+
<AppTextInput
19+
accessibilityLabel={label}
20+
{...inputProps}
21+
className="rounded-[14px] px-4 py-3.5"
22+
/>
23+
</View>
24+
);
25+
}

‎apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx‎

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import { Alert, Linking, Platform, View } from "react-native";
1313
import { useSafeAreaInsets } from "react-native-safe-area-context";
1414
import { useUniwindTheme } from "../../lib/useUniwindTheme";
1515
import { SettingsScreen } from "../settings/components/SettingsScreen";
16-
import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
16+
import { AppText as Text } from "../../components/AppText";
1717
import { ErrorBanner } from "../../components/ErrorBanner";
18+
import { ConnectionFormField } from "./ConnectionFormField";
1819
import { ConnectionSheetButton } from "./ConnectionSheetButton";
1920
import { buildPairingUrl, extractPairingUrlFromQrPayload, parsePairingUrl } from "./pairing";
2021
import { useRemoteConnections } from "../../state/use-remote-environment-registry";
@@ -262,34 +263,24 @@ export function ConnectionsNewRouteScreen({
262263
)
263264
) : (
264265
<View collapsable={false} className="gap-4 rounded-[24px] bg-card p-4">
265-
<View collapsable={false} className="gap-1.5">
266-
<Text className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">
267-
Host
268-
</Text>
269-
<TextInput
270-
autoCapitalize="none"
271-
autoCorrect={false}
272-
keyboardType="url"
273-
placeholder="192.168.1.100:8080"
274-
value={hostInput}
275-
onChangeText={handleHostChange}
276-
className="rounded-[14px] border border-input-border bg-input px-4 py-3.5 text-base text-foreground"
277-
/>
278-
</View>
266+
<ConnectionFormField
267+
label="Host"
268+
autoCapitalize="none"
269+
autoCorrect={false}
270+
keyboardType="url"
271+
placeholder="192.168.1.100:8080"
272+
value={hostInput}
273+
onChangeText={handleHostChange}
274+
/>
279275

280-
<View collapsable={false} className="gap-1.5">
281-
<Text className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">
282-
Pairing code
283-
</Text>
284-
<TextInput
285-
autoCapitalize="none"
286-
autoCorrect={false}
287-
placeholder="abc-123-xyz"
288-
value={codeInput}
289-
onChangeText={handleCodeChange}
290-
className="rounded-[14px] border border-input-border bg-input px-4 py-3.5 text-base text-foreground"
291-
/>
292-
</View>
276+
<ConnectionFormField
277+
label="Pairing code"
278+
autoCapitalize="none"
279+
autoCorrect={false}
280+
placeholder="abc-123-xyz"
281+
value={codeInput}
282+
onChangeText={handleCodeChange}
283+
/>
293284

294285
{pairingConnectionError ? <ErrorBanner message={pairingConnectionError} /> : null}
295286

0 commit comments

Comments
 (0)