|
| 1 | +import { BottomSheetModal } from '@gorhom/bottom-sheet'; |
| 2 | +import { useTranslation } from '@ronas-it/react-native-common-modules/i18n'; |
| 3 | +import { ReactElement, ReactNode, useRef } from 'react'; |
| 4 | +import { |
| 5 | + AppBottomSheet, |
| 6 | + AppBottomSheetKeyboardAwareScrollView, |
| 7 | + AppPressable, |
| 8 | + AppSafeAreaView, |
| 9 | + AppText, |
| 10 | + Icon, |
| 11 | + SheetHeader, |
| 12 | + View, |
| 13 | +} from '@open-webui-react-native/mobile/shared/ui/ui-kit'; |
| 14 | + |
| 15 | +export interface ToolOutputBottomSheetProps { |
| 16 | + toolName: string; |
| 17 | + input: string; |
| 18 | + output: string; |
| 19 | +} |
| 20 | + |
| 21 | +export function ToolOutputBottomSheet({ toolName, input, output }: ToolOutputBottomSheetProps): ReactElement { |
| 22 | + const translate = useTranslation('CHAT.AI_MESSAGE.TOOL_OUTPUT_SHEET'); |
| 23 | + const sheetRef = useRef<BottomSheetModal>(null); |
| 24 | + |
| 25 | + const renderTrigger = ({ onPress }: { onPress: () => void }): ReactNode => ( |
| 26 | + <AppPressable |
| 27 | + onPress={onPress} |
| 28 | + className='flex-row items-center gap-8 rounded-xl bg-background-secondary px-12 py-10 active:opacity-70'> |
| 29 | + <Icon name='tick' className='size-20 shrink-0 color-emerald-500' /> |
| 30 | + <View className='min-w-0 flex-1 flex-row flex-wrap items-center'> |
| 31 | + <AppText className='text-sm-sm sm:text-sm text-text-secondary'>{translate('TEXT_VIEW_RESULT_PREFIX')} </AppText> |
| 32 | + <AppText className='text-sm-sm sm:text-sm font-mono font-semibold text-text-primary'>{toolName}</AppText> |
| 33 | + </View> |
| 34 | + <Icon name='chevronDown' className='size-16 shrink-0 color-text-secondary' /> |
| 35 | + </AppPressable> |
| 36 | + ); |
| 37 | + |
| 38 | + return ( |
| 39 | + <AppBottomSheet |
| 40 | + ref={sheetRef} |
| 41 | + isModal={true} |
| 42 | + isScrollable={true} |
| 43 | + snapPoints={['100%']} |
| 44 | + className='px-0' |
| 45 | + renderTrigger={renderTrigger} |
| 46 | + content={ |
| 47 | + <View className='flex-1 bg-background-primary'> |
| 48 | + <SheetHeader title={toolName} onGoBack={() => sheetRef.current?.close()} /> |
| 49 | + <AppBottomSheetKeyboardAwareScrollView |
| 50 | + className='flex-1' |
| 51 | + contentContainerClassName='px-content-offset pb-safe pt-8 android:pb-24'> |
| 52 | + <AppSafeAreaView edges={['bottom']}> |
| 53 | + <AppText className='mb-8 text-xs font-medium uppercase tracking-wide text-text-secondary'> |
| 54 | + {translate('TEXT_INPUT')} |
| 55 | + </AppText> |
| 56 | + <AppText selectable className='mb-16 text-sm-sm sm:text-sm font-mono text-text-primary'> |
| 57 | + {input} |
| 58 | + </AppText> |
| 59 | + <AppText className='mb-8 text-xs font-medium uppercase tracking-wide text-text-secondary'> |
| 60 | + {translate('TEXT_OUTPUT')} |
| 61 | + </AppText> |
| 62 | + <AppText selectable className='text-sm-sm sm:text-sm font-mono text-text-primary'> |
| 63 | + {output} |
| 64 | + </AppText> |
| 65 | + </AppSafeAreaView> |
| 66 | + </AppBottomSheetKeyboardAwareScrollView> |
| 67 | + </View> |
| 68 | + } |
| 69 | + /> |
| 70 | + ); |
| 71 | +} |
0 commit comments