TypeScript
refactor(mobile): consolidate shared action buttons (#21940)
Julius Marminge5837a85e7477
diff --git a/apps/mobile/src/components/ui/Button.android.tsx b/apps/mobile/src/components/ui/Button.android.tsxindex af8ce1aba1a..ac917427d1c 100644--- a/apps/mobile/src/components/ui/Button.android.tsx+++ b/apps/mobile/src/components/ui/Button.android.tsx@@ -49,7 +49,7 @@ export function Button(props: ButtonProps) {<ViewaccessibleaccessibilityRole="button"- accessibilityLabel={props.label}+ accessibilityLabel={props.accessibilityLabel ?? props.label}accessibilityHint={props.accessibilityHint}accessibilityState={{disabled: Boolean(props.disabled || props.loading),diff --git a/apps/mobile/src/components/ui/Button.tsx b/apps/mobile/src/components/ui/Button.tsxindex 4536ad93c9f..05c6e008524 100644--- a/apps/mobile/src/components/ui/Button.tsx+++ b/apps/mobile/src/components/ui/Button.tsx@@ -6,6 +6,7 @@ import { cn } from "../../lib/cn";export interface ButtonProps {readonly label: string;+ readonly accessibilityLabel?: string;readonly icon?: AppSymbolName;readonly onPress: () => void;readonly disabled?: boolean;@@ -29,7 +30,7 @@ export function Button(props: ButtonProps) {return (<PressableaccessibilityRole="button"- accessibilityLabel={props.label}+ accessibilityLabel={props.accessibilityLabel ?? props.label}accessibilityHint={props.accessibilityHint}accessibilityState={{ disabled, busy: Boolean(props.loading) }}disabled={disabled}diff --git a/apps/mobile/src/features/projects/AddProjectScreen.tsx b/apps/mobile/src/features/projects/AddProjectScreen.tsxindex eb05271e89e..6aef5430654 100644--- a/apps/mobile/src/features/projects/AddProjectScreen.tsx+++ b/apps/mobile/src/features/projects/AddProjectScreen.tsx@@ -262,20 +262,7 @@ function PrimaryActionButton(props: {readonly loading?: boolean;readonly onPress: () => void;}) {- if (Platform.OS === "android") return <Button {...props} tone="primary" fullWidth />;- return (- <Pressable- disabled={props.disabled}- onPress={props.onPress}- className="h-12 items-center justify-center rounded-full bg-primary active:opacity-70 disabled:opacity-45"- >- {props.loading ? (- <AppActivityIndicator colorClassName={String("accent-primary-foreground")} />- ) : (- <Text className="text-base font-t3-bold text-primary-foreground">{props.label}</Text>- )}- </Pressable>- );+ return <Button {...props} tone="primary" fullWidth />;}function ProjectPathInput(props: {diff --git a/apps/mobile/src/features/threads/PendingApprovalCard.tsx b/apps/mobile/src/features/threads/PendingApprovalCard.tsxindex e4897761d4b..3037ee422bd 100644--- a/apps/mobile/src/features/threads/PendingApprovalCard.tsx+++ b/apps/mobile/src/features/threads/PendingApprovalCard.tsx@@ -1,4 +1,4 @@-import { RequestActionButton } from "./RequestActionButton";+import { Button } from "../../components/ui/Button";import type {ProviderApprovalDecision,ProviderApprovalOption,@@ -55,7 +55,7 @@ export function PendingApprovalCard(props: PendingApprovalCardProps) {) : null}<View className="flex-row flex-wrap gap-2.5">{options.map((option) => (- <RequestActionButton+ <Buttonkey={option.decision}label={option.label}tone={diff --git a/apps/mobile/src/features/threads/PendingUserInputCard.tsx b/apps/mobile/src/features/threads/PendingUserInputCard.tsxindex 0df28161bc0..c20ad4cc1af 100644--- a/apps/mobile/src/features/threads/PendingUserInputCard.tsx+++ b/apps/mobile/src/features/threads/PendingUserInputCard.tsx@@ -1,4 +1,4 @@-import { RequestActionButton } from "./RequestActionButton";+import { Button } from "../../components/ui/Button";import { QuestionAttachments } from "./QuestionAttachments";import type { RuntimeRequestId } from "@t3tools/contracts";import type { ThreadUserInputQuestion } from "@t3tools/client-runtime/state/thread-requests";@@ -304,9 +304,9 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {);})}</ScrollView>- <RequestActionButton+ <Buttonlabel="Submit answers"- size="large"+ fullWidthtone={props.answers ? "primary" : "secondary"}disabled={!props.canOperateThread || responseDisabled || props.answers === null}onPress={() => void props.onSubmit()}diff --git a/apps/mobile/src/features/threads/ProviderSubagentBar.tsx b/apps/mobile/src/features/threads/ProviderSubagentBar.tsxindex 15d19d45e88..16d16c219e0 100644--- a/apps/mobile/src/features/threads/ProviderSubagentBar.tsx+++ b/apps/mobile/src/features/threads/ProviderSubagentBar.tsx@@ -7,7 +7,7 @@ import { View } from "react-native";import { AppText as Text } from "../../components/ui/AppText";import { ProviderIcon } from "../../components/ProviderIcon";-import { RequestActionButton } from "./RequestActionButton";+import { Button } from "../../components/ui/Button";import { useVisibleSecondClock } from "./use-visible-second-clock";export function ProviderSubagentBar(props: {@@ -60,7 +60,7 @@ export function ProviderSubagentBar(props: {</Text></View>{props.onOpenParent ? (- <RequestActionButton label="Open parent" tone="secondary" onPress={props.onOpenParent} />+ <Button label="Open parent" tone="secondary" onPress={props.onOpenParent} />) : null}</View>);diff --git a/apps/mobile/src/features/threads/RequestActionButton.tsx b/apps/mobile/src/features/threads/RequestActionButton.tsxdeleted file mode 100644index 3177d50c26b..00000000000--- a/apps/mobile/src/features/threads/RequestActionButton.tsx+++ /dev/null@@ -1,44 +0,0 @@-import type { ComponentProps } from "react";-import { Pressable } from "react-native";--import { AppText as Text } from "../../components/ui/AppText";-import { cn } from "../../lib/cn";--export function RequestActionButton({- label,- tone = "primary",- size = "default",- disabled,- ...props-}: Omit<ComponentProps<typeof Pressable>, "children" | "className" | "style"> & {- label: string;- tone?: "primary" | "secondary" | "danger";- size?: "default" | "large";-}) {- return (- <Pressable- {...props}- accessibilityRole="button"- accessibilityState={{ ...props.accessibilityState, disabled: Boolean(disabled) }}- disabled={disabled}- className={cn(- "items-center justify-center active:opacity-70 disabled:opacity-50",- size === "large" ? "rounded-2xl px-4 py-3.5" : "rounded-[14px] px-3.5 py-3",- tone === "primary" ? "bg-primary" : tone === "danger" ? "bg-danger" : "bg-subtle-strong",- )}- >- <Text- className={cn(- "text-sm",- tone === "primary"- ? "font-t3-extrabold text-primary-foreground"- : tone === "danger"- ? "font-t3-bold text-danger-foreground"- : "font-t3-bold text-foreground",- )}- >- {label}- </Text>- </Pressable>- );-}diff --git a/apps/mobile/src/features/threads/SecretRequestCard.tsx b/apps/mobile/src/features/threads/SecretRequestCard.tsxindex 7b67287fb92..3d705b297ce 100644--- a/apps/mobile/src/features/threads/SecretRequestCard.tsx+++ b/apps/mobile/src/features/threads/SecretRequestCard.tsx@@ -18,7 +18,7 @@ import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText";import { serverEnvironment } from "../../state/server";import { useAtomCommand } from "../../state/use-atom-command";-import { RequestActionButton } from "./RequestActionButton";+import { Button } from "../../components/ui/Button";const LOCK_SYMBOL: AppSymbolName = { ios: "lock", android: "lock" };const PRIVATE_SYMBOL: AppSymbolName = { ios: "checkmark.shield", android: "lock" };@@ -128,8 +128,10 @@ function PendingSecretRequestForm(props: {{error}</Text>) : null}- <RequestActionButton+ <Buttonlabel="Save securely"+ tone="primary"+ fullWidthdisabled={submitting || secret.trim().length === 0}onPress={() => void send({ type: "save", secret })}/>diff --git a/apps/mobile/src/features/threads/ThreadCreationFailedCard.tsx b/apps/mobile/src/features/threads/ThreadCreationFailedCard.tsxindex fac6f28a3a7..141519800ee 100644--- a/apps/mobile/src/features/threads/ThreadCreationFailedCard.tsx+++ b/apps/mobile/src/features/threads/ThreadCreationFailedCard.tsx@@ -1,4 +1,4 @@-import { RequestActionButton } from "./RequestActionButton";+import { Button } from "../../components/ui/Button";import { View } from "react-native";import { AppText as Text } from "../../components/ui/AppText";@@ -19,7 +19,7 @@ export function ThreadCreationFailedCard(props: {Your prompt was kept in the project draft.</Text><View className="flex-row">- <RequestActionButton label="Edit task" onPress={props.onEditTask} />+ <Button label="Edit task" tone="primary" onPress={props.onEditTask} /></View></View>);diff --git a/apps/mobile/src/features/threads/git/gitSheetComponents.tsx b/apps/mobile/src/features/threads/git/gitSheetComponents.tsxindex 9196c988971..310aa6993b5 100644--- a/apps/mobile/src/features/threads/git/gitSheetComponents.tsx+++ b/apps/mobile/src/features/threads/git/gitSheetComponents.tsx@@ -1,9 +1,7 @@import { SymbolView } from "../../../components/ui/AppSymbol";import type { ComponentProps } from "react";-import { Platform, Pressable, View } from "react-native";-import { AppText as Text } from "../../../components/ui/AppText";+import { View } from "react-native";import { Button } from "../../../components/ui/Button";-import { cn } from "../../../lib/cn";export function SheetActionButton(props: {readonly icon: ComponentProps<typeof SymbolView>["name"];@@ -12,60 +10,10 @@ export function SheetActionButton(props: {readonly tone?: "primary" | "secondary" | "danger";readonly onPress: () => void;}) {- if (Platform.OS === "android")- return (- <View className="flex-1">- <Button- label={props.label}- icon={props.icon}- tone={props.tone}- disabled={props.disabled}- onPress={props.onPress}- fullWidth- />- </View>- );- const tone = props.tone ?? "secondary";- const textColorClassName =- tone === "primary"- ? "accent-primary-foreground"- : tone === "danger"- ? "accent-danger-foreground"- : "accent-secondary-foreground";-return (- <Pressable- className={cn(- "min-h-[48px] flex-1 items-center justify-center rounded-[18px] px-3 py-3 disabled:opacity-[0.45]",- tone === "primary" ? "bg-primary" : tone === "danger" ? "bg-danger" : "bg-secondary",- tone !== "primary" &&- (tone === "danger" ? "border border-danger-border" : "border border-secondary-border"),- )}- accessibilityRole="button"- disabled={props.disabled}- onPress={props.onPress}- >- <View className="max-w-full flex-row items-center justify-center gap-1.5">- <SymbolView- name={props.icon}- size={16}- tintColorClassName={textColorClassName}- type="monochrome"- />- <Text- className={cn(- "shrink text-center text-xs font-t3-bold tracking-[0.9px] uppercase",- tone === "primary"- ? "text-primary-foreground"- : tone === "danger"- ? "text-danger-foreground"- : "text-secondary-foreground",- )}- >- {props.label}- </Text>- </View>- </Pressable>+ <View className="flex-1">+ <Button {...props} fullWidth />+ </View>);}