[FIX] Different token types inside list items (#3458)

* Fix different token types inside list items

* Fixing more styles

* Update tests

Co-authored-by: Gerzon Z <gerzonc@icloud.com>
This commit is contained in:
Diego Mello 2021-10-27 10:13:20 -03:00 committed by GitHub
parent e0a0a31257
commit b2db7c8adf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1618 additions and 717 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,10 @@
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import { Text } 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';
import AtMention from '../AtMention'; import AtMention from '../AtMention';
import styles from '../styles';
import Link from './Link'; import Link from './Link';
import Plain from './Plain'; import Plain from './Plain';
import Bold from './Bold'; import Bold from './Bold';
@ -20,7 +22,7 @@ interface IParagraphProps {
const Inline = ({ value }: IParagraphProps): JSX.Element => { const Inline = ({ value }: IParagraphProps): JSX.Element => {
const { useRealName, username, navToRoomInfo, mentions, channels } = useContext(MarkdownContext); const { useRealName, username, navToRoomInfo, mentions, channels } = useContext(MarkdownContext);
return ( return (
<> <Text style={styles.inline}>
{value.map(block => { {value.map(block => {
switch (block.type) { switch (block.type) {
case 'IMAGE': case 'IMAGE':
@ -55,7 +57,7 @@ const Inline = ({ value }: IParagraphProps): JSX.Element => {
return null; return null;
} }
})} })}
</> </Text>
); );
}; };

View File

@ -161,5 +161,8 @@ export default StyleSheet.create<any>({
}, },
alignRight: { alignRight: {
textAlign: 'right' textAlign: 'right'
},
inline: {
flexShrink: 1
} }
}); });

View File

@ -5,6 +5,7 @@ import { storiesOf } from '@storybook/react-native';
import NewMarkdown from '../../app/containers/markdown/new'; import NewMarkdown from '../../app/containers/markdown/new';
import { themes } from '../../app/constants/colors'; import { themes } from '../../app/constants/colors';
import { longText } from '../utils';
const stories = storiesOf('NewMarkdown', module); const stories = storiesOf('NewMarkdown', module);
@ -49,8 +50,7 @@ const longTextMsg = [
value: [ value: [
{ {
type: 'PLAIN_TEXT', type: 'PLAIN_TEXT',
value: value: longText
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
} }
] ]
} }
@ -108,43 +108,13 @@ const sequentialEmptySpacesMsg = [
} }
]; ];
const boldOrUnderscoreMsg = [
{
type: 'PARAGRAPH',
value: [
{
type: 'BOLD',
value: [
{
type: 'PLAIN_TEXT',
value: 'This is bold'
}
]
},
{
type: 'PLAIN_TEXT',
value: ' and '
},
{
type: 'ITALIC',
value: [
{
type: 'PLAIN_TEXT',
value: 'this is italic'
}
]
}
]
}
];
stories.add('Text', () => ( stories.add('Text', () => (
<View style={styles.container}> <View style={styles.container}>
<NewMarkdown tokens={simpleTextMsg} /> <NewMarkdown tokens={simpleTextMsg} />
<NewMarkdown tokens={longTextMsg} /> <NewMarkdown tokens={longTextMsg} />
<NewMarkdown tokens={lineBreakMsg} /> <NewMarkdown tokens={lineBreakMsg} />
<NewMarkdown tokens={sequentialEmptySpacesMsg} /> <NewMarkdown tokens={sequentialEmptySpacesMsg} />
<NewMarkdown tokens={boldOrUnderscoreMsg} /> <NewMarkdown tokens={[...simpleTextMsg, ...longTextMsg]} />
</View> </View>
)); ));
@ -375,6 +345,20 @@ const blockQuoteTokens = [
] ]
} }
] ]
},
{
type: 'QUOTE',
value: [
{
type: 'PARAGRAPH',
value: [
{
type: 'PLAIN_TEXT',
value: longText
}
]
}
]
} }
]; ];
@ -546,14 +530,7 @@ const multilineCodeToken = [
type: 'CODE_LINE', type: 'CODE_LINE',
value: { value: {
type: 'PLAIN_TEXT', type: 'PLAIN_TEXT',
value: 'Multi line ' value: 'Multi \nLine \nCode'
}
},
{
type: 'CODE_LINE',
value: {
type: 'PLAIN_TEXT',
value: 'Code'
} }
} }
] ]
@ -567,53 +544,141 @@ stories.add('Code', () => (
</View> </View>
)); ));
const unorederedListToken = [ const items = [
[
{ {
type: 'UNORDERED_LIST', type: 'PLAIN_TEXT',
value: [ value: 'Plain text '
},
{ {
type: 'LIST_ITEM', type: 'EMOJI',
value: {
type: 'PLAIN_TEXT',
value: 'bulb'
}
},
{
type: 'ITALIC',
value: [ value: [
{ {
type: 'PLAIN_TEXT', type: 'PLAIN_TEXT',
value: 'Open Source' value: ' italic '
} }
] ]
}, },
{ {
type: 'LIST_ITEM', type: 'BOLD',
value: [ value: [
{ {
type: 'PLAIN_TEXT', type: 'PLAIN_TEXT',
value: 'Rocket.Chat' value: ' bold '
} }
] ]
},
{
type: 'STRIKE',
value: [
{
type: 'PLAIN_TEXT',
value: ' strike '
} }
] ]
},
{
type: 'MENTION_CHANNEL',
value: {
type: 'PLAIN_TEXT',
value: 'general'
}
},
{
type: 'LINK',
value: {
src: {
type: 'PLAIN_TEXT',
value: 'https://google.com'
},
label: {
type: 'PLAIN_TEXT',
value: ' link '
}
}
},
{
type: 'MENTION_USER',
value: {
type: 'PLAIN_TEXT',
value: 'rocket.cat'
}
},
{
type: 'INLINE_CODE',
value: {
type: 'PLAIN_TEXT',
value: ' inline code'
}
}
],
[
{
type: 'PLAIN_TEXT',
value: longText
}
]
];
const listItems = [
{
type: 'LIST_ITEM',
value: items[0]
},
{
type: 'LIST_ITEM',
value: items[1]
}
];
const unorederedListToken = [
{
type: 'UNORDERED_LIST',
value: listItems
} }
]; ];
const orderedListToken = [ const orderedListToken = [
{ {
type: 'ORDERED_LIST', type: 'ORDERED_LIST',
value: [ value: listItems
{
type: 'LIST_ITEM',
value: [
{
type: 'PLAIN_TEXT',
value: 'Open Source'
} }
] ];
const listMentions = [
{
_id: 'rocket.cat',
username: 'rocket.cat'
}
];
const listChannels = [
{
_id: 'general',
name: 'general'
}
];
const tasks = [
{
type: 'TASKS',
value: [
{
type: 'TASK',
status: true,
value: items[0]
}, },
{ {
type: 'LIST_ITEM', type: 'TASK',
value: [ status: false,
{ value: items[1]
type: 'PLAIN_TEXT',
value: 'Rocket.Chat'
}
]
} }
] ]
} }
@ -621,7 +686,8 @@ const orderedListToken = [
stories.add('Lists', () => ( stories.add('Lists', () => (
<View style={styles.container}> <View style={styles.container}>
<NewMarkdown tokens={unorederedListToken} /> <NewMarkdown tokens={unorederedListToken} mentions={listMentions} channels={listChannels} />
<NewMarkdown tokens={orderedListToken} /> <NewMarkdown tokens={orderedListToken} mentions={listMentions} channels={listChannels} />
<NewMarkdown tokens={tasks} mentions={listMentions} channels={listChannels} />
</View> </View>
)); ));