Change interfaces and add TaskListComponent and styles

This commit is contained in:
Gerzon Z 2021-09-23 15:23:20 -04:00
parent ddfdba438b
commit 4895fd2e2e
12 changed files with 85 additions and 57 deletions

View File

@ -243,8 +243,8 @@ class Markdown extends PureComponent<IMarkdownProps, any> {
}; };
renderHashtag = ({ hashtag }: { hashtag: string }) => { renderHashtag = ({ hashtag }: { hashtag: string }) => {
const { channels, navToRoomInfo, style, theme } = this.props; const { channels, navToRoomInfo, style } = this.props;
return <MarkdownHashtag hashtag={hashtag} channels={channels} navToRoomInfo={navToRoomInfo} theme={theme} style={style} />; return <MarkdownHashtag hashtag={hashtag} channels={channels} navToRoomInfo={navToRoomInfo} style={style} />;
}; };
renderAtMention = ({ mentionName }: { mentionName: string }) => { renderAtMention = ({ mentionName }: { mentionName: string }) => {

View File

@ -6,6 +6,12 @@ interface ICodeLineProps {
value: CodeLineProps['value']; value: CodeLineProps['value'];
} }
const CodeLine: React.FC<ICodeLineProps> = ({ value }) => <Text>{value.type === 'PLAIN_TEXT' && value.value}</Text>; const CodeLine: React.FC<ICodeLineProps> = ({ value }) => {
if (value.type !== 'PLAIN_TEXT') {
return null;
}
return <Text>{value.value}</Text>;
};
export default CodeLine; export default CodeLine;

View File

@ -17,7 +17,7 @@ const Emoji: React.FC<IEmojiProps> = ({ value, style, isBigEmoji }) => {
const { theme } = useTheme(); const { theme } = useTheme();
const emojiUnicode = shortnameToUnicode(`:${value.value}:`); const emojiUnicode = shortnameToUnicode(`:${value.value}:`);
return ( return (
<Text style={[{ color: themes[theme!].bodyText }, isBigEmoji ? styles.textBig : styles.text, style]}>{emojiUnicode}</Text> <Text style={[{ color: themes[theme].bodyText }, isBigEmoji ? styles.textBig : styles.text, style]}>{emojiUnicode}</Text>
); );
}; };

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { StyleProp, Text, ViewStyle } from 'react-native'; import { StyleProp, ViewStyle } from 'react-native';
import { Paragraph as ParagraphProps } from '@rocket.chat/message-parser'; import { Paragraph as ParagraphProps } from '@rocket.chat/message-parser';
import Hashtag from '../Hashtag'; import Hashtag from '../Hashtag';
@ -11,28 +11,21 @@ import Italic from './Italic';
import Emoji from './Emoji'; import Emoji from './Emoji';
import Mention from './Mention'; import Mention from './Mention';
import InlineCode from './InlineCode'; import InlineCode from './InlineCode';
import { UserMention } from '../../message/interfaces';
interface IUser {
_id: string;
username: string;
name: string;
}
type UserMention = Pick<IUser, '_id' | 'username' | 'name'>;
interface IParagraphProps { interface IParagraphProps {
value: ParagraphProps['value']; value: ParagraphProps['value'];
mentions: UserMention[]; mentions?: UserMention[];
channels: { channels?: {
name: string; name: string;
_id: number; _id: number;
}[]; }[];
navToRoomInfo: Function; navToRoomInfo?: Function;
style: StyleProp<ViewStyle>[]; style?: StyleProp<ViewStyle>[];
} }
const Inline: React.FC<IParagraphProps> = ({ value, mentions, channels, navToRoomInfo, style }) => ( const Inline: React.FC<IParagraphProps> = ({ value, mentions, channels, navToRoomInfo, style }) => (
<Text> <>
{value.map(block => { {value.map(block => {
switch (block.type) { switch (block.type) {
case 'PLAIN_TEXT': case 'PLAIN_TEXT':
@ -57,7 +50,7 @@ const Inline: React.FC<IParagraphProps> = ({ value, mentions, channels, navToRoo
return null; return null;
} }
})} })}
</Text> </>
); );
export default Inline; export default Inline;

View File

@ -6,14 +6,7 @@ import styles from '../styles';
import { events, logEvent } from '../../../utils/log'; import { events, logEvent } from '../../../utils/log';
import { useTheme } from '../../../theme'; import { useTheme } from '../../../theme';
import { themes } from '../../../constants/colors'; import { themes } from '../../../constants/colors';
import { UserMention } from '../../message/interfaces';
interface IUser {
_id: string;
username: string;
name: string;
}
type UserMention = Pick<IUser, '_id' | 'username' | 'name'>;
interface IMentionProps { interface IMentionProps {
value: UserMentionProps['value']; value: UserMentionProps['value'];

View File

@ -1,6 +1,5 @@
/* eslint-disable react/no-array-index-key */
import React from 'react'; import React from 'react';
import { View, Text } from 'react-native'; import { View, Text, StyleSheet } from 'react-native';
import { OrderedList as OrderedListProps } from '@rocket.chat/message-parser'; import { OrderedList as OrderedListProps } from '@rocket.chat/message-parser';
import Inline from './Inline'; import Inline from './Inline';
@ -9,10 +8,16 @@ interface IOrderedListProps {
value: OrderedListProps['value']; value: OrderedListProps['value'];
} }
const styles = StyleSheet.create({
container: {
flexDirection: 'row'
}
});
const OrderedList: React.FC<IOrderedListProps> = React.memo(({ value }) => ( const OrderedList: React.FC<IOrderedListProps> = React.memo(({ value }) => (
<> <>
{value.map((item, index) => ( {value.map((item, index) => (
<View style={{ flexDirection: 'row' }}> <View style={styles.container}>
<Text>{index + 1}. </Text> <Text>{index + 1}. </Text>
<Inline value={item.value} /> <Inline value={item.value} />
</View> </View>

View File

@ -1,30 +1,31 @@
import React from 'react'; import React from 'react';
import { StyleProp, ViewStyle } from 'react-native'; import { StyleProp, Text, ViewStyle } from 'react-native';
import { Paragraph as ParagraphProps } from '@rocket.chat/message-parser'; import { Paragraph as ParagraphProps } from '@rocket.chat/message-parser';
import { UserMention } from '../../message/interfaces';
import Inline from './Inline'; import Inline from './Inline';
import styles from '../styles';
interface IUser { import { useTheme } from '../../../theme';
_id: string; import { themes } from '../../../constants/colors';
username: string;
name: string;
}
type UserMention = Pick<IUser, '_id' | 'username' | 'name'>;
interface IParagraphProps { interface IParagraphProps {
value: ParagraphProps['value']; value: ParagraphProps['value'];
mentions: UserMention[]; mentions?: UserMention[];
channels: { channels?: {
name: string; name: string;
_id: number; _id: number;
}[]; }[];
navToRoomInfo: Function; navToRoomInfo?: Function;
style: StyleProp<ViewStyle>; style?: StyleProp<ViewStyle>[];
} }
const Paragraph: React.FC<IParagraphProps> = ({ value, mentions, channels, navToRoomInfo, style }) => ( const Paragraph: React.FC<IParagraphProps> = ({ value, mentions, channels, navToRoomInfo, style }) => {
const { theme } = useTheme();
return (
<Text style={[styles.text, style, { color: themes[theme].bodyText }]}>
<Inline value={value} mentions={mentions} channels={channels} navToRoomInfo={navToRoomInfo} style={style} /> <Inline value={value} mentions={mentions} channels={channels} navToRoomInfo={navToRoomInfo} style={style} />
); </Text>
);
};
export default Paragraph; export default Paragraph;

View File

@ -1,4 +1,3 @@
/* eslint-disable react/no-array-index-key */
import React from 'react'; import React from 'react';
import { View } from 'react-native'; import { View } from 'react-native';
import { Quote as QuoteProps } from '@rocket.chat/message-parser'; import { Quote as QuoteProps } from '@rocket.chat/message-parser';

View File

@ -1,4 +1,3 @@
/* eslint-disable react/no-array-index-key */
import React from 'react'; import React from 'react';
import { StyleSheet, Text } from 'react-native'; import { StyleSheet, Text } from 'react-native';
import { Strike as StrikeProps } from '@rocket.chat/message-parser'; import { Strike as StrikeProps } from '@rocket.chat/message-parser';

View File

@ -0,0 +1,26 @@
import React from 'react';
import { Text } from 'react-native';
import { Tasks as TasksProps } from '@rocket.chat/message-parser';
import { Checkbox } from 'react-native-ui-lib';
import Inline from './Inline';
interface ITasksProps {
value: TasksProps['value'];
}
const TaskList: React.FC<ITasksProps> = ({ value }) => (
<Text
style={{
marginLeft: 0,
paddingLeft: 0
}}>
{value.map(item => (
<>
<Checkbox checked={item.status} /> <Inline value={item.value} />
</>
))}
</Text>
);
export default TaskList;

View File

@ -9,14 +9,9 @@ import Code from './Code';
import BigEmoji from './BigEmoji'; import BigEmoji from './BigEmoji';
import OrderedList from './OrderedList'; import OrderedList from './OrderedList';
import UnorderedList from './UnorderedList'; import UnorderedList from './UnorderedList';
import { UserMention } from '../../message/interfaces';
import TaskList from './TaskList';
interface IUser {
_id: string;
username: string;
name: string;
}
type UserMention = Pick<IUser, '_id' | 'username' | 'name'>;
interface IBodyProps { interface IBodyProps {
tokens: MarkdownAST; tokens: MarkdownAST;
mentions: UserMention[]; mentions: UserMention[];
@ -44,7 +39,7 @@ const Body: React.FC<IBodyProps> = ({ tokens, mentions, channels, navToRoomInfo,
case 'ORDERED_LIST': case 'ORDERED_LIST':
return <OrderedList value={block.value} />; return <OrderedList value={block.value} />;
case 'TASKS': case 'TASKS':
return <OrderedList value={block.value} />; return <TaskList value={block.value} />;
case 'QUOTE': case 'QUOTE':
return <Quote value={block.value} />; return <Quote value={block.value} />;
case 'PARAGRAPH': case 'PARAGRAPH':

View File

@ -1,3 +1,5 @@
import { MarkdownAST } from '@rocket.chat/message-parser';
export interface IMessageAttachments { export interface IMessageAttachments {
attachments: any; attachments: any;
timeFormat: string; timeFormat: string;
@ -48,12 +50,21 @@ export interface IMessageCallButton {
callJitsi: Function; callJitsi: Function;
} }
export interface IUser {
_id: string;
username: string;
name: string;
}
export type UserMention = Pick<IUser, '_id' | 'username' | 'name'>;
export interface IMessageContent { export interface IMessageContent {
isTemp: boolean; isTemp: boolean;
isInfo: boolean; isInfo: boolean;
tmid: string; tmid: string;
isThreadRoom: boolean; isThreadRoom: boolean;
msg: string; msg: string;
md: MarkdownAST;
theme: string; theme: string;
isEdited: boolean; isEdited: boolean;
isEncrypted: boolean; isEncrypted: boolean;
@ -62,7 +73,7 @@ export interface IMessageContent {
name: string; name: string;
_id: number; _id: number;
}[]; }[];
mentions: object[]; mentions: UserMention[];
navToRoomInfo: Function; navToRoomInfo: Function;
useRealName: boolean; useRealName: boolean;
isIgnored: boolean; isIgnored: boolean;