Changeset View
Changeset View
Standalone View
Standalone View
native/chat/settings/thread-settings-parent.react.js
// @flow | // @flow | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { Text, View } from 'react-native'; | import { Text, View } from 'react-native'; | ||||
import { useGetAvatarForThread } from 'lib/shared/avatar-utils.js'; | |||||
import { type ThreadInfo } from 'lib/types/thread-types.js'; | import { type ThreadInfo } from 'lib/types/thread-types.js'; | ||||
import Avatar from '../../components/avatar.react.js'; | |||||
import Button from '../../components/button.react.js'; | import Button from '../../components/button.react.js'; | ||||
import ThreadAvatar from '../../components/thread-avatar.react.js'; | |||||
import ThreadPill from '../../components/thread-pill.react.js'; | import ThreadPill from '../../components/thread-pill.react.js'; | ||||
import { useStyles } from '../../themes/colors.js'; | import { useStyles } from '../../themes/colors.js'; | ||||
import { useShouldRenderAvatars } from '../../utils/avatar-utils.js'; | import { useShouldRenderAvatars } from '../../utils/avatar-utils.js'; | ||||
import { useNavigateToThread } from '../message-list-types.js'; | import { useNavigateToThread } from '../message-list-types.js'; | ||||
type ParentButtonProps = { | type ParentButtonProps = { | ||||
+parentThreadInfo: ThreadInfo, | +parentThreadInfo: ThreadInfo, | ||||
}; | }; | ||||
function ParentButton(props: ParentButtonProps): React.Node { | function ParentButton(props: ParentButtonProps): React.Node { | ||||
const styles = useStyles(unboundStyles); | const styles = useStyles(unboundStyles); | ||||
const navigateToThread = useNavigateToThread(); | const navigateToThread = useNavigateToThread(); | ||||
const onPressParentThread = React.useCallback(() => { | const onPressParentThread = React.useCallback(() => { | ||||
navigateToThread({ threadInfo: props.parentThreadInfo }); | navigateToThread({ threadInfo: props.parentThreadInfo }); | ||||
}, [props.parentThreadInfo, navigateToThread]); | }, [props.parentThreadInfo, navigateToThread]); | ||||
const avatarInfo = useGetAvatarForThread(props.parentThreadInfo); | |||||
const shouldRenderAvatars = useShouldRenderAvatars(); | const shouldRenderAvatars = useShouldRenderAvatars(); | ||||
const avatar = React.useMemo(() => { | const avatar = React.useMemo(() => { | ||||
if (!shouldRenderAvatars) { | if (!shouldRenderAvatars) { | ||||
return null; | return null; | ||||
} | } | ||||
return ( | return ( | ||||
<View style={styles.avatarContainer}> | <View style={styles.avatarContainer}> | ||||
<Avatar size="small" avatarInfo={avatarInfo} /> | <ThreadAvatar size="small" threadInfo={props.parentThreadInfo} /> | ||||
</View> | </View> | ||||
); | ); | ||||
}, [avatarInfo, shouldRenderAvatars, styles.avatarContainer]); | }, [props.parentThreadInfo, shouldRenderAvatars, styles.avatarContainer]); | ||||
return ( | return ( | ||||
<Button onPress={onPressParentThread} style={styles.parentContainer}> | <Button onPress={onPressParentThread} style={styles.parentContainer}> | ||||
{avatar} | {avatar} | ||||
<ThreadPill threadInfo={props.parentThreadInfo} /> | <ThreadPill threadInfo={props.parentThreadInfo} /> | ||||
</Button> | </Button> | ||||
); | ); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |