Changeset View
Changeset View
Standalone View
Standalone View
native/components/thread-list-thread.react.js
// @flow | // @flow | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { useGetAvatarForThread } from 'lib/shared/avatar-utils.js'; | |||||
import type { ClientAvatar } from 'lib/types/avatar-types.js'; | |||||
import type { ThreadInfo, ResolvedThreadInfo } from 'lib/types/thread-types.js'; | import type { ThreadInfo, ResolvedThreadInfo } from 'lib/types/thread-types.js'; | ||||
import { useResolvedThreadInfo } from 'lib/utils/entity-helpers.js'; | import { useResolvedThreadInfo } from 'lib/utils/entity-helpers.js'; | ||||
import Avatar from './avatar.react.js'; | |||||
import Button from './button.react.js'; | import Button from './button.react.js'; | ||||
import ColorSplotch from './color-splotch.react.js'; | import ColorSplotch from './color-splotch.react.js'; | ||||
import { SingleLine } from './single-line.react.js'; | import { SingleLine } from './single-line.react.js'; | ||||
import ThreadAvatar from './thread-avatar.react.js'; | |||||
import { type Colors, useStyles, useColors } from '../themes/colors.js'; | import { type Colors, useStyles, useColors } from '../themes/colors.js'; | ||||
import type { ViewStyle, TextStyle } from '../types/styles.js'; | import type { ViewStyle, TextStyle } from '../types/styles.js'; | ||||
import { useShouldRenderAvatars } from '../utils/avatar-utils.js'; | import { useShouldRenderAvatars } from '../utils/avatar-utils.js'; | ||||
type SharedProps = { | type SharedProps = { | ||||
+onSelect: (threadID: string) => void, | +onSelect: (threadID: string) => void, | ||||
+style?: ViewStyle, | +style?: ViewStyle, | ||||
+textStyle?: TextStyle, | +textStyle?: TextStyle, | ||||
}; | }; | ||||
type BaseProps = { | type BaseProps = { | ||||
...SharedProps, | ...SharedProps, | ||||
+threadInfo: ThreadInfo, | +threadInfo: ThreadInfo, | ||||
}; | }; | ||||
type Props = { | type Props = { | ||||
...SharedProps, | ...SharedProps, | ||||
+threadInfo: ResolvedThreadInfo, | +threadInfo: ResolvedThreadInfo, | ||||
+avatarInfo: ClientAvatar, | |||||
+shouldRenderAvatars: boolean, | +shouldRenderAvatars: boolean, | ||||
+colors: Colors, | +colors: Colors, | ||||
+styles: typeof unboundStyles, | +styles: typeof unboundStyles, | ||||
}; | }; | ||||
class ThreadListThread extends React.PureComponent<Props> { | class ThreadListThread extends React.PureComponent<Props> { | ||||
render() { | render() { | ||||
const { modalIosHighlightUnderlay: underlayColor } = this.props.colors; | const { modalIosHighlightUnderlay: underlayColor } = this.props.colors; | ||||
let avatar; | let avatar; | ||||
if (this.props.shouldRenderAvatars) { | if (this.props.shouldRenderAvatars) { | ||||
avatar = <Avatar size="small" avatarInfo={this.props.avatarInfo} />; | avatar = <ThreadAvatar size="small" threadInfo={this.props.threadInfo} />; | ||||
} else { | } else { | ||||
avatar = <ColorSplotch color={this.props.threadInfo.color} />; | avatar = <ColorSplotch color={this.props.threadInfo.color} />; | ||||
} | } | ||||
return ( | return ( | ||||
<Button | <Button | ||||
onPress={this.onSelect} | onPress={this.onSelect} | ||||
iosFormat="highlight" | iosFormat="highlight" | ||||
Show All 30 Lines | |||||
}; | }; | ||||
const ConnectedThreadListThread: React.ComponentType<BaseProps> = | const ConnectedThreadListThread: React.ComponentType<BaseProps> = | ||||
React.memo<BaseProps>(function ConnectedThreadListThread(props: BaseProps) { | React.memo<BaseProps>(function ConnectedThreadListThread(props: BaseProps) { | ||||
const { threadInfo, ...rest } = props; | const { threadInfo, ...rest } = props; | ||||
const styles = useStyles(unboundStyles); | const styles = useStyles(unboundStyles); | ||||
const colors = useColors(); | const colors = useColors(); | ||||
const resolvedThreadInfo = useResolvedThreadInfo(threadInfo); | const resolvedThreadInfo = useResolvedThreadInfo(threadInfo); | ||||
const avatarInfo = useGetAvatarForThread(threadInfo); | |||||
const shouldRenderAvatars = useShouldRenderAvatars(); | const shouldRenderAvatars = useShouldRenderAvatars(); | ||||
return ( | return ( | ||||
<ThreadListThread | <ThreadListThread | ||||
{...rest} | {...rest} | ||||
threadInfo={resolvedThreadInfo} | threadInfo={resolvedThreadInfo} | ||||
avatarInfo={avatarInfo} | |||||
shouldRenderAvatars={shouldRenderAvatars} | shouldRenderAvatars={shouldRenderAvatars} | ||||
styles={styles} | styles={styles} | ||||
colors={colors} | colors={colors} | ||||
/> | /> | ||||
); | ); | ||||
}); | }); | ||||
export default ConnectedThreadListThread; | export default ConnectedThreadListThread; |