|
| 1 | +import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView"; |
| 2 | +import { useAtomSet, useAtomValue } from "@effect/atom-react"; |
| 3 | +import { useNavigation } from "@react-navigation/native"; |
| 4 | +import { pastedTextThresholdLabel } from "@t3tools/client-runtime/text-paste"; |
| 5 | +import { |
| 6 | + DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD, |
| 7 | + type PastedTextAttachmentThreshold, |
| 8 | +} from "@t3tools/contracts"; |
| 9 | +import { AsyncResult } from "effect/reactivity"; |
| 10 | +import { Platform, View } from "react-native"; |
| 11 | +import { useSafeAreaInsets } from "react-native-safe-area-context"; |
| 12 | + |
| 13 | +import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader"; |
| 14 | +import { AppText as Text } from "../../components/ui/AppText"; |
| 15 | +import { NativeStackScreenOptions } from "../../native/StackHeader"; |
| 16 | +import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences"; |
| 17 | +import { SettingsChoiceRow } from "./components/SettingsChoiceRow"; |
| 18 | +import { SettingsSection } from "./components/SettingsSection"; |
| 19 | + |
| 20 | +const THRESHOLD_OPTIONS: ReadonlyArray<{ |
| 21 | + readonly threshold: PastedTextAttachmentThreshold; |
| 22 | + readonly description: string; |
| 23 | +}> = [ |
| 24 | + { threshold: 1_000, description: "Most logs, stack traces, and code snippets become files." }, |
| 25 | + { threshold: 5_000, description: "Long logs and documents become files; snippets stay as text." }, |
| 26 | + { threshold: 32_768, description: "Default. Only very large pastes become files." }, |
| 27 | +]; |
| 28 | + |
| 29 | +const PASTE_AS_TEXT_SHORTCUT = Platform.OS === "ios" ? "Command + Shift + V" : "Ctrl + Shift + V"; |
| 30 | + |
| 31 | +export function SettingsLargePastesRouteScreen() { |
| 32 | + const navigation = useNavigation(); |
| 33 | + const insets = useSafeAreaInsets(); |
| 34 | + const preferencesResult = useAtomValue(mobilePreferencesAtom); |
| 35 | + const savePreferences = useAtomSet(updateMobilePreferencesAtom); |
| 36 | + const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting; |
| 37 | + const selectedThreshold = AsyncResult.isSuccess(preferencesResult) |
| 38 | + ? (preferencesResult.value.pastedTextAttachmentThreshold ?? |
| 39 | + DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD) |
| 40 | + : null; |
| 41 | + |
| 42 | + return ( |
| 43 | + <View collapsable={false} className="flex-1 bg-sheet"> |
| 44 | + {Platform.OS === "android" ? ( |
| 45 | + <> |
| 46 | + <NativeStackScreenOptions options={{ headerShown: false }} /> |
| 47 | + <AndroidScreenHeader title="Large pastes" onBack={() => navigation.goBack()} /> |
| 48 | + </> |
| 49 | + ) : null} |
| 50 | + <ScrollView |
| 51 | + contentInsetAdjustmentBehavior="automatic" |
| 52 | + showsVerticalScrollIndicator={false} |
| 53 | + className="flex-1" |
| 54 | + contentContainerClassName="gap-3 px-5 pt-4" |
| 55 | + contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }} |
| 56 | + > |
| 57 | + <SettingsSection title="Attach pastes as files from"> |
| 58 | + {THRESHOLD_OPTIONS.map(({ threshold, description }, index) => ( |
| 59 | + <SettingsChoiceRow |
| 60 | + key={threshold} |
| 61 | + label={pastedTextThresholdLabel(threshold)} |
| 62 | + description={description} |
| 63 | + selected={selectedThreshold === threshold} |
| 64 | + separated={index > 0} |
| 65 | + disabled={!preferencesReady} |
| 66 | + onPress={() => savePreferences({ pastedTextAttachmentThreshold: threshold })} |
| 67 | + /> |
| 68 | + ))} |
| 69 | + </SettingsSection> |
| 70 | + <Text className="px-2 text-sm text-foreground-muted"> |
| 71 | + Sizes count bytes, so non-Latin text and emoji become files with fewer characters. Shorter |
| 72 | + pastes go into the message as text. With a hardware keyboard, press{" "} |
| 73 | + {PASTE_AS_TEXT_SHORTCUT} to paste a long block as text instead. |
| 74 | + </Text> |
| 75 | + </ScrollView> |
| 76 | + </View> |
| 77 | + ); |
| 78 | +} |
0 commit comments