feat: display language icon for auto translated msgs (#5398)

* feat: display language icon for auto translated msgs

* add translate icon to stoybook

	modified:   app/containers/message/Message.stories.tsx

* fix test

* refactor: use colors straightly without finding them with theme

* refactor some code

* fix test storyshot

* fix test issue
This commit is contained in:
Sathurshan 2024-03-04 15:55:41 +05:30 committed by GitHub
parent 65e076be6b
commit eefb8793a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 57 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,22 @@
import React, { memo } from 'react';
import { View } from 'react-native';
import { CustomIcon } from '../../../CustomIcon';
import { useTheme } from '../../../../theme';
import styles from '../../styles';
const Translated = memo(({ isTranslated }: { isTranslated: boolean }) => {
const { colors } = useTheme();
if (!isTranslated) {
return null;
}
return (
<View style={styles.rightIcons}>
<CustomIcon name='language' size={16} color={colors.auxiliaryText} />
</View>
);
});
export default Translated;

View File

@ -5,6 +5,7 @@ import Encrypted from './Encrypted';
import Edited from './Edited';
import MessageError from './MessageError';
import ReadReceipt from './ReadReceipt';
import Translated from './Translated';
import { MessageType } from '../../../../definitions';
const styles = StyleSheet.create({
@ -20,13 +21,15 @@ interface IRightIcons {
isReadReceiptEnabled?: boolean;
unread?: boolean;
hasError: boolean;
isTranslated: boolean;
}
const RightIcons = ({ type, msg, isEdited, hasError, isReadReceiptEnabled, unread }: IRightIcons) => (
const RightIcons = ({ type, msg, isEdited, hasError, isReadReceiptEnabled, unread, isTranslated }: IRightIcons) => (
<View style={styles.actionIcons}>
<Encrypted type={type} />
<Edited testID={`${msg}-edited`} isEdited={isEdited} />
<MessageError hasError={hasError} />
<Translated isTranslated={isTranslated} />
<ReadReceipt isReadReceiptEnabled={isReadReceiptEnabled} unread={unread} />
</View>
);

View File

@ -127,6 +127,13 @@ export const Edited = () => (
</>
);
export const Translated = () => (
<>
<Message msg='Message header' isTranslated />
<Message msg='Message without header' isTranslated isHeader={false} />
</>
);
export const Encrypted = () => (
<>
<Message msg='Message' type='e2e' />
@ -939,6 +946,7 @@ export const LongNameUser = () => (
<>
<Message msg={'this is a normal message'} author={longNameAuthor} />
<Message msg={'Edited message'} author={longNameAuthor} isEdited />
<Message msg={'Translated message'} author={longNameAuthor} isTranslated />
<Message msg={'Encrypted message'} author={longNameAuthor} type={E2E_MESSAGE_TYPE} />
<Message msg={'Error message'} author={longNameAuthor} hasError />
<Message msg={'Message with read receipt'} author={longNameAuthor} isReadReceiptEnabled read />
@ -947,6 +955,7 @@ export const LongNameUser = () => (
msg={'Show all icons '}
author={longNameAuthor}
isEdited
isTranslated
type={E2E_MESSAGE_TYPE}
hasError
isReadReceiptEnabled
@ -958,6 +967,7 @@ export const LongNameUser = () => (
author={longNameAuthor}
isHeader={false}
isEdited
isTranslated
type={E2E_MESSAGE_TYPE}
hasError
isReadReceiptEnabled
@ -969,6 +979,7 @@ export const LongNameUser = () => (
author={longNameAuthor}
isHeader={false}
isEdited
isTranslated
type={E2E_MESSAGE_TYPE}
hasError
isReadReceiptEnabled

View File

@ -117,6 +117,7 @@ const Message = React.memo((props: IMessage) => {
hasError={props.hasError}
isReadReceiptEnabled={props.isReadReceiptEnabled}
unread={props.unread}
isTranslated={props.isTranslated}
/>
) : null}
</View>

View File

@ -60,10 +60,24 @@ interface IMessageUser {
isEdited: boolean;
isReadReceiptEnabled?: boolean;
unread?: boolean;
isTranslated: boolean;
}
const User = React.memo(
({ isHeader, useRealName, author, alias, ts, timeFormat, hasError, navToRoomInfo, type, isEdited, ...props }: IMessageUser) => {
({
isHeader,
useRealName,
author,
alias,
ts,
timeFormat,
hasError,
navToRoomInfo,
type,
isEdited,
isTranslated,
...props
}: IMessageUser) => {
const { user } = useContext(MessageContext);
const { colors } = useTheme();
@ -110,6 +124,7 @@ const User = React.memo(
hasError={hasError}
isReadReceiptEnabled={props.isReadReceiptEnabled}
unread={props.unread}
isTranslated={isTranslated}
/>
</View>
);