2021-09-13 20:41:05 +00:00
|
|
|
import React, { useCallback } from 'react';
|
|
|
|
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import sharedStyles from '../../views/Styles';
|
2022-02-17 15:27:01 +00:00
|
|
|
import { MarkdownPreview } from '../markdown';
|
2021-09-13 20:41:05 +00:00
|
|
|
import RoomTypeIcon from '../RoomTypeIcon';
|
2022-04-15 02:27:36 +00:00
|
|
|
import { TUserStatus, IOmnichannelSource } from '../../definitions';
|
2022-03-31 22:29:14 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2022-10-04 12:56:39 +00:00
|
|
|
import { useAppSelector } from '../../lib/hooks';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
const HIT_SLOP = {
|
|
|
|
top: 5,
|
|
|
|
right: 5,
|
|
|
|
bottom: 5,
|
|
|
|
left: 5
|
|
|
|
};
|
|
|
|
const TITLE_SIZE = 16;
|
|
|
|
const SUBTITLE_SIZE = 12;
|
|
|
|
|
|
|
|
const getSubTitleSize = (scale: number) => SUBTITLE_SIZE * scale;
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center'
|
|
|
|
},
|
|
|
|
titleContainer: {
|
|
|
|
alignItems: 'center',
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
flexShrink: 1,
|
|
|
|
...sharedStyles.textSemibold
|
|
|
|
},
|
|
|
|
subtitle: {
|
|
|
|
flexShrink: 1,
|
|
|
|
...sharedStyles.textRegular
|
|
|
|
},
|
|
|
|
typingUsers: {
|
|
|
|
...sharedStyles.textSemibold
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
type TRoomHeaderSubTitle = {
|
|
|
|
usersTyping: [];
|
2022-06-13 20:16:20 +00:00
|
|
|
subtitle?: string;
|
2022-03-31 22:29:14 +00:00
|
|
|
renderFunc?: () => React.ReactElement;
|
2021-09-13 20:41:05 +00:00
|
|
|
scale: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
type TRoomHeaderHeaderTitle = {
|
2022-06-13 20:16:20 +00:00
|
|
|
title?: string;
|
|
|
|
tmid?: string;
|
|
|
|
prid?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
scale: number;
|
2022-06-13 20:16:20 +00:00
|
|
|
testID?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
interface IRoomHeader {
|
2022-06-13 20:16:20 +00:00
|
|
|
title?: string;
|
|
|
|
subtitle?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
type: string;
|
|
|
|
width: number;
|
|
|
|
height: number;
|
2023-08-29 19:15:26 +00:00
|
|
|
roomUserId?: string | null;
|
2022-06-13 20:16:20 +00:00
|
|
|
prid?: string;
|
|
|
|
tmid?: string;
|
|
|
|
teamMain?: boolean;
|
2023-08-29 19:15:26 +00:00
|
|
|
status?: TUserStatus;
|
2021-09-13 20:41:05 +00:00
|
|
|
usersTyping: [];
|
2022-06-13 20:16:20 +00:00
|
|
|
isGroupChat?: boolean;
|
|
|
|
parentTitle?: string;
|
|
|
|
onPress: Function;
|
|
|
|
testID?: string;
|
2022-04-15 02:27:36 +00:00
|
|
|
sourceType?: IOmnichannelSource;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-03-31 22:29:14 +00:00
|
|
|
const SubTitle = React.memo(({ usersTyping, subtitle, renderFunc, scale }: TRoomHeaderSubTitle) => {
|
2022-06-13 20:16:20 +00:00
|
|
|
const { colors } = useTheme();
|
2021-09-13 20:41:05 +00:00
|
|
|
const fontSize = getSubTitleSize(scale);
|
|
|
|
// typing
|
|
|
|
if (usersTyping.length) {
|
|
|
|
let usersText;
|
|
|
|
if (usersTyping.length === 2) {
|
|
|
|
usersText = usersTyping.join(` ${I18n.t('and')} `);
|
|
|
|
} else {
|
|
|
|
usersText = usersTyping.join(', ');
|
|
|
|
}
|
|
|
|
return (
|
2022-06-13 20:16:20 +00:00
|
|
|
<Text style={[styles.subtitle, { fontSize, color: colors.auxiliaryText }]} numberOfLines={1}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text style={styles.typingUsers}>{usersText} </Text>
|
|
|
|
{usersTyping.length > 1 ? I18n.t('are_typing') : I18n.t('is_typing')}...
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// renderFunc
|
|
|
|
if (renderFunc) {
|
|
|
|
return renderFunc();
|
|
|
|
}
|
|
|
|
|
|
|
|
// subtitle
|
|
|
|
if (subtitle) {
|
2022-06-13 20:16:20 +00:00
|
|
|
return <MarkdownPreview msg={subtitle} style={[styles.subtitle, { fontSize, color: colors.auxiliaryText }]} />;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2022-03-31 22:29:14 +00:00
|
|
|
const HeaderTitle = React.memo(({ title, tmid, prid, scale, testID }: TRoomHeaderHeaderTitle) => {
|
2022-06-13 20:16:20 +00:00
|
|
|
const { colors } = useTheme();
|
|
|
|
const titleStyle = { fontSize: TITLE_SIZE * scale, color: colors.headerTitleColor };
|
2021-09-13 20:41:05 +00:00
|
|
|
if (!tmid && !prid) {
|
|
|
|
return (
|
|
|
|
<Text style={[styles.title, titleStyle]} numberOfLines={1} testID={testID}>
|
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-17 15:27:01 +00:00
|
|
|
return <MarkdownPreview msg={title} style={[styles.title, titleStyle]} testID={testID} />;
|
2021-09-13 20:41:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const Header = React.memo(
|
|
|
|
({
|
|
|
|
title,
|
|
|
|
subtitle,
|
|
|
|
parentTitle,
|
|
|
|
type,
|
|
|
|
status,
|
|
|
|
width,
|
|
|
|
height,
|
2023-08-29 19:15:26 +00:00
|
|
|
roomUserId,
|
2021-09-13 20:41:05 +00:00
|
|
|
prid,
|
|
|
|
tmid,
|
|
|
|
onPress,
|
|
|
|
isGroupChat,
|
|
|
|
teamMain,
|
|
|
|
testID,
|
2022-04-15 02:27:36 +00:00
|
|
|
usersTyping = [],
|
|
|
|
sourceType
|
2021-09-13 20:41:05 +00:00
|
|
|
}: IRoomHeader) => {
|
2022-06-13 20:16:20 +00:00
|
|
|
const { colors } = useTheme();
|
2021-09-13 20:41:05 +00:00
|
|
|
const portrait = height > width;
|
|
|
|
let scale = 1;
|
2022-10-04 12:56:39 +00:00
|
|
|
const isMasterDetail = useAppSelector(state => state.app.isMasterDetail);
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-10-04 12:56:39 +00:00
|
|
|
if (!portrait && !tmid && !isMasterDetail) {
|
2021-09-13 20:41:05 +00:00
|
|
|
if (usersTyping.length > 0 || subtitle) {
|
|
|
|
scale = 0.8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let renderFunc;
|
|
|
|
if (tmid) {
|
|
|
|
renderFunc = () => (
|
|
|
|
<View style={styles.titleContainer}>
|
2023-08-29 19:15:26 +00:00
|
|
|
<RoomTypeIcon
|
|
|
|
userId={roomUserId}
|
|
|
|
type={prid ? 'discussion' : type}
|
|
|
|
isGroupChat={isGroupChat}
|
|
|
|
status={status}
|
|
|
|
teamMain={teamMain}
|
|
|
|
/>
|
2022-06-13 20:16:20 +00:00
|
|
|
<Text style={[styles.subtitle, { color: colors.auxiliaryText }]} numberOfLines={1}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{parentTitle}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleOnPress = useCallback(() => onPress(), []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
testID='room-header'
|
|
|
|
accessibilityLabel={title}
|
|
|
|
onPress={handleOnPress}
|
|
|
|
style={styles.container}
|
2022-03-31 22:29:14 +00:00
|
|
|
disabled={!!tmid}
|
2022-08-08 21:02:08 +00:00
|
|
|
hitSlop={HIT_SLOP}
|
|
|
|
>
|
2021-09-13 20:41:05 +00:00
|
|
|
<View style={styles.titleContainer}>
|
|
|
|
{tmid ? null : (
|
2022-04-15 02:27:36 +00:00
|
|
|
<RoomTypeIcon
|
2023-08-29 19:15:26 +00:00
|
|
|
userId={roomUserId}
|
2022-04-15 02:27:36 +00:00
|
|
|
type={prid ? 'discussion' : type}
|
|
|
|
isGroupChat={isGroupChat}
|
|
|
|
status={status}
|
|
|
|
teamMain={teamMain}
|
|
|
|
sourceType={sourceType}
|
|
|
|
/>
|
2021-09-13 20:41:05 +00:00
|
|
|
)}
|
2022-03-31 22:29:14 +00:00
|
|
|
<HeaderTitle title={title} tmid={tmid} prid={prid} scale={scale} testID={testID} />
|
2021-09-13 20:41:05 +00:00
|
|
|
</View>
|
2022-03-31 22:29:14 +00:00
|
|
|
<SubTitle usersTyping={tmid ? [] : usersTyping} subtitle={subtitle} renderFunc={renderFunc} scale={scale} />
|
2021-09-13 20:41:05 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-03-31 22:29:14 +00:00
|
|
|
export default Header;
|