|
| 1 | +/** |
| 2 | + * Created by leon<[email protected]> on 22/04/28. |
| 3 | + */ |
| 4 | +import RenderHtml from 'react-native-render-html' |
| 5 | +import React, { useMemo } from 'react' |
| 6 | +import { View, ViewStyle, TextStyle, StyleProp } from 'react-native' |
| 7 | + |
| 8 | +import { Text, Button, Spinner, Placeholder, Avatar } from '@src/components' |
| 9 | +import { ITheme, SylCommon, useTheme } from '@src/theme' |
| 10 | +import { translate } from '@src/i18n' |
| 11 | +import { NavigationService, ROUTES } from '@src/navigation' |
| 12 | +import { V2exObject } from '@src/types' |
| 13 | +import { BorderLine, TextWithIconPress } from '../common' |
| 14 | +import dayjs from 'dayjs' |
| 15 | + |
| 16 | +/** |
| 17 | + * TopicReplayItem props |
| 18 | + */ |
| 19 | +export interface TopicReplayItemProps { |
| 20 | + containerStyle?: StyleProp<ViewStyle> |
| 21 | + |
| 22 | + info: V2exObject.TopicReply |
| 23 | +} |
| 24 | + |
| 25 | +const TopicReplayItem: React.FC<TopicReplayItemProps> = ({ containerStyle, info }: TopicReplayItemProps) => { |
| 26 | + const { theme } = useTheme() |
| 27 | + const avatar_link = useMemo(() => (info.member ? info.member.avatar || info.member.avatar_normal : undefined), [info]) |
| 28 | + return ( |
| 29 | + <View style={[styles.container(theme), containerStyle]}> |
| 30 | + <View style={styles.infoContainer(theme)}> |
| 31 | + <Avatar size={40} source={{ uri: avatar_link }} username={info.member?.username} style={styles.avatar(theme)} /> |
| 32 | + |
| 33 | + <View style={styles.infoMain(theme)}> |
| 34 | + <View style={styles.infoMainItem(theme)}> |
| 35 | + <TextWithIconPress |
| 36 | + text={info.member?.username ?? 'none'} |
| 37 | + textStyle={[{ color: theme.colors.secondary }]} |
| 38 | + onPress={() => { |
| 39 | + NavigationService.navigate(ROUTES.Profile, { username: info.member?.username }) |
| 40 | + }} |
| 41 | + /> |
| 42 | + <TextWithIconPress |
| 43 | + text={translate('label.replyedTime').replace('$', dayjs(info.created * 1000).fromNow())} |
| 44 | + /> |
| 45 | + </View> |
| 46 | + <View style={styles.infoMainItem(theme)}> |
| 47 | + <RenderHtml |
| 48 | + source={{ |
| 49 | + html: `<div style="color:${theme.colors.bodyText}">${info.content_rendered}</div>` || '<p></p>' |
| 50 | + }} |
| 51 | + contentWidth={theme.dimens.layoutContainerWidth - 40 - theme.spacing.large} |
| 52 | + /> |
| 53 | + </View> |
| 54 | + </View> |
| 55 | + </View> |
| 56 | + <BorderLine width={0.4} /> |
| 57 | + </View> |
| 58 | + ) |
| 59 | +} |
| 60 | + |
| 61 | +const styles = { |
| 62 | + container: (theme: ITheme): ViewStyle => ({ |
| 63 | + paddingTop: theme.spacing.medium, |
| 64 | + width: '100%', |
| 65 | + flexDirection: 'column', |
| 66 | + justifyContent: 'flex-start', |
| 67 | + alignItems: 'center' |
| 68 | + }), |
| 69 | + infoContainer: (theme: ITheme): ViewStyle => ({ |
| 70 | + flexDirection: 'row', |
| 71 | + marginBottom: theme.spacing.small |
| 72 | + }), |
| 73 | + avatar: (theme: ITheme): ViewStyle => ({ |
| 74 | + width: 40, |
| 75 | + marginRight: theme.spacing.large |
| 76 | + }), |
| 77 | + infoMain: (theme: ITheme): ViewStyle => ({ |
| 78 | + flex: 1, |
| 79 | + justifyContent: 'flex-start', |
| 80 | + flexDirection: 'column' |
| 81 | + }), |
| 82 | + infoMainItem: (theme: ITheme): ViewStyle => ({ |
| 83 | + flexDirection: 'row', |
| 84 | + marginBottom: theme.spacing.small, |
| 85 | + justifyContent: 'space-between' |
| 86 | + }) |
| 87 | +} |
| 88 | + |
| 89 | +export default TopicReplayItem |
0 commit comments