2021-09-22 17:29:26 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2022-02-04 22:15:01 +00:00
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
|
|
|
import { RouteProp } from '@react-navigation/native';
|
2021-09-22 17:29:26 +00:00
|
|
|
import { StyleSheet, Text, View, ScrollView } from 'react-native';
|
|
|
|
|
|
|
|
import I18n from '../i18n';
|
|
|
|
import SafeAreaView from '../containers/SafeAreaView';
|
|
|
|
import StatusBar from '../containers/StatusBar';
|
|
|
|
import Button from '../containers/Button';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, useTheme } from '../theme';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { goRoom } from '../lib/methods/helpers/goRoom';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../lib/constants';
|
2021-09-22 17:29:26 +00:00
|
|
|
import Markdown from '../containers/markdown';
|
2022-02-04 22:15:01 +00:00
|
|
|
import { ICannedResponse } from '../definitions/ICannedResponse';
|
|
|
|
import { ChatsStackParamList } from '../stacks/types';
|
2021-09-22 17:29:26 +00:00
|
|
|
import sharedStyles from './Styles';
|
2022-05-13 15:01:34 +00:00
|
|
|
import { useAppSelector } from '../lib/hooks';
|
2021-09-22 17:29:26 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
scroll: {
|
|
|
|
flex: 1
|
|
|
|
},
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
marginTop: 12,
|
|
|
|
marginHorizontal: 15
|
|
|
|
},
|
|
|
|
cannedText: {
|
|
|
|
marginTop: 8,
|
|
|
|
marginBottom: 16,
|
|
|
|
fontSize: 14,
|
|
|
|
paddingTop: 0,
|
|
|
|
paddingBottom: 0,
|
|
|
|
...sharedStyles.textRegular
|
|
|
|
},
|
|
|
|
cannedTagWrap: {
|
|
|
|
borderRadius: 4,
|
|
|
|
marginRight: 4,
|
|
|
|
marginTop: 8,
|
|
|
|
height: 16
|
|
|
|
},
|
|
|
|
cannedTagContainer: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
flexWrap: 'wrap'
|
|
|
|
},
|
|
|
|
cannedTag: {
|
|
|
|
fontSize: 12,
|
|
|
|
paddingTop: 0,
|
|
|
|
paddingBottom: 0,
|
|
|
|
paddingHorizontal: 4,
|
|
|
|
...sharedStyles.textRegular
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
margin: 24,
|
|
|
|
marginBottom: 24
|
|
|
|
},
|
|
|
|
item: {
|
|
|
|
paddingVertical: 10,
|
|
|
|
justifyContent: 'center'
|
|
|
|
},
|
|
|
|
itemLabel: {
|
|
|
|
marginBottom: 10,
|
|
|
|
fontSize: 14,
|
|
|
|
...sharedStyles.textMedium
|
|
|
|
},
|
|
|
|
itemContent: {
|
|
|
|
fontSize: 14,
|
|
|
|
...sharedStyles.textRegular
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-04 22:15:01 +00:00
|
|
|
interface IItem {
|
|
|
|
label: string;
|
|
|
|
content?: string;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2022-02-04 22:15:01 +00:00
|
|
|
testID?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Item = ({ label, content, theme, testID }: IItem) =>
|
2021-09-22 17:29:26 +00:00
|
|
|
content ? (
|
|
|
|
<View style={styles.item} testID={testID}>
|
|
|
|
<Text accessibilityLabel={label} style={[styles.itemLabel, { color: themes[theme].titleText }]}>
|
|
|
|
{label}
|
|
|
|
</Text>
|
2022-07-04 18:10:14 +00:00
|
|
|
<Markdown style={[styles.itemContent, { color: themes[theme].auxiliaryText }]} msg={content} theme={theme} />
|
2021-09-22 17:29:26 +00:00
|
|
|
</View>
|
|
|
|
) : null;
|
|
|
|
|
2022-02-04 22:15:01 +00:00
|
|
|
interface ICannedResponseDetailProps {
|
|
|
|
navigation: StackNavigationProp<ChatsStackParamList, 'CannedResponseDetail'>;
|
|
|
|
route: RouteProp<ChatsStackParamList, 'CannedResponseDetail'>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CannedResponseDetail = ({ navigation, route }: ICannedResponseDetailProps): JSX.Element => {
|
2021-09-22 17:29:26 +00:00
|
|
|
const { cannedResponse } = route?.params;
|
|
|
|
const { theme } = useTheme();
|
2022-05-13 15:01:34 +00:00
|
|
|
const { isMasterDetail } = useAppSelector(state => state.app);
|
2021-09-22 17:29:26 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
navigation.setOptions({
|
|
|
|
title: `!${cannedResponse?.shortcut}`
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
2022-02-04 22:15:01 +00:00
|
|
|
const navigateToRoom = (item: ICannedResponse) => {
|
2021-09-22 17:29:26 +00:00
|
|
|
const { room } = route.params;
|
|
|
|
|
|
|
|
if (room.rid) {
|
2022-11-25 13:21:56 +00:00
|
|
|
goRoom({ item: room, isMasterDetail, popToRoot: true, usedCannedResponse: item.text });
|
2021-09-22 17:29:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SafeAreaView>
|
|
|
|
<ScrollView contentContainerStyle={[styles.scroll, { backgroundColor: themes[theme].messageboxBackground }]}>
|
|
|
|
<StatusBar />
|
|
|
|
<View style={styles.container}>
|
|
|
|
<Item label={I18n.t('Shortcut')} content={`!${cannedResponse?.shortcut}`} theme={theme} />
|
|
|
|
<Item label={I18n.t('Content')} content={cannedResponse?.text} theme={theme} />
|
|
|
|
<Item label={I18n.t('Sharing')} content={cannedResponse?.scopeName} theme={theme} />
|
|
|
|
|
|
|
|
<View style={styles.item}>
|
|
|
|
<Text style={[styles.itemLabel, { color: themes[theme].titleText }]}>{I18n.t('Tags')}</Text>
|
|
|
|
<View style={styles.cannedTagContainer}>
|
|
|
|
{cannedResponse?.tags?.length > 0 ? (
|
|
|
|
cannedResponse.tags.map(t => (
|
|
|
|
<View style={[styles.cannedTagWrap, { backgroundColor: themes[theme].searchboxBackground }]}>
|
|
|
|
<Text style={[styles.cannedTag, { color: themes[theme].auxiliaryTintColor }]}>{t}</Text>
|
|
|
|
</View>
|
|
|
|
))
|
|
|
|
) : (
|
|
|
|
<Text style={[styles.cannedText, { color: themes[theme].auxiliaryTintColor }]}>-</Text>
|
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</View>
|
2022-05-20 16:37:57 +00:00
|
|
|
<Button title={I18n.t('Use')} style={styles.button} type='primary' onPress={() => navigateToRoom(cannedResponse)} />
|
2021-09-22 17:29:26 +00:00
|
|
|
</ScrollView>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CannedResponseDetail;
|