From b312e817c435c002d93b2600e368c35685d8acd4 Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:12:35 +0800 Subject: [PATCH] Import apps/android/src/screens/bot/cards.tsx --- apps/android/src/screens/bot/cards.tsx | 289 +++++++++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 apps/android/src/screens/bot/cards.tsx diff --git a/apps/android/src/screens/bot/cards.tsx b/apps/android/src/screens/bot/cards.tsx new file mode 100644 index 0000000..a6a8728 --- /dev/null +++ b/apps/android/src/screens/bot/cards.tsx @@ -0,0 +1,289 @@ +import { useState } from 'react' +import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native' +import { X } from 'lucide-react-native' +import { strings as s } from '../../locales/i18n' +import { object, text, type BotObject } from '../../services/bot-catalog' +import { Button } from '../../ui/components' +import { radius, spacing, type } from '../../ui/theme' +import { useTheme, type ThemeColors } from '../../ui/theme-context' +import { useThemedStyles } from '../../ui/use-themed-styles' +import { createBotStyles } from './styles' + +export { BotViewCard } from './view-card' + +const keyLetter = (index: number) => String.fromCharCode(65 + index) + +export function BotQuestion({ question, busy, answer, dismiss }: { question: BotObject; busy: boolean; answer: (value: BotObject) => void; dismiss: () => void }) { + const styles = useThemedStyles(createBotStyles) + const localStyles = useThemedStyles(createCardStyles) + const { colors, scheme } = useTheme() + const [selected, setSelected] = useState([]) + const [custom, setCustom] = useState('') + const options = (Array.isArray(question.options) ? question.options : []).map(option => typeof option === 'string' ? { label: option } : object(option)) + const isMulti = question.multiSelect === true + const needsCustomInput = options.length === 0 + const promptTitle = text(question.question) || text(question.header) || s.bots.question + const subHeader = text(question.question) && text(question.header) ? text(question.header) : '' + const detailText = text(question.detail) + + const handleOptionPress = (label: string) => { + if (busy) return + if (isMulti) { + setSelected(current => current.includes(label) ? current.filter(item => item !== label) : [...current, label]) + return + } + setSelected([label]) + answer({ selected: [label] }) + } + + return ( + + + + + {Boolean(subHeader) && {subHeader}} + {promptTitle} + {Boolean(detailText) && {detailText}} + + [localStyles.closeBtn, pressed && { opacity: 0.55 }, busy && { opacity: 0.35 }]} + > + + + + + {options.length > 0 && ( + + {options.map((option, i) => { + const label = text(option.label) + const desc = text(option.description) + const isChecked = selected.includes(label) + return ( + handleOptionPress(label)} + style={({ pressed }) => [ + localStyles.optionRow, + pressed && localStyles.optionRowPressed, + busy && { opacity: 0.5 }, + ]} + > + + + {keyLetter(i)} + + + + {label} + {Boolean(desc) && {desc}} + + + ) + })} + + )} + + {(isMulti || needsCustomInput) && ( + + {needsCustomInput && ( + + )} + +