Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/containers/markdown/AtMention.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import React, { useContext } from 'react';
import { Text } from 'react-native';

import { useTheme } from '../../theme';
import { themes } from '../../constants/colors';
import styles from './styles';
import { events, logEvent } from '../../utils/log';
import MarkdownContext from './new/MarkdownContext';

interface IAtMention {
mention: string;
Expand All @@ -17,6 +18,7 @@ interface IAtMention {

const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, style = [], useRealName }: IAtMention) => {
const { theme } = useTheme();
const { preview } = useContext(MarkdownContext);
if (mention === 'all' || mention === 'here') {
return (
<Text
Expand All @@ -43,7 +45,7 @@ const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, styl
};
}

const user = mentions?.find?.((m: any) => m && m.username === mention);
const user = mentions?.find?.((m: { username: string }) => m && m.username === mention);

const handlePress = () => {
logEvent(events.ROOM_MENTION_GO_USER_INFO);
Expand All @@ -56,13 +58,15 @@ const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, styl

if (user) {
return (
<Text style={[styles.mention, mentionStyle, ...style]} onPress={handlePress}>
<Text style={!preview ? [styles.mention, mentionStyle, ...style] : styles.text} onPress={handlePress}>
{useRealName && user.name ? user.name : user.username}
</Text>
);
}

return <Text style={[styles.text, { color: themes[theme!].bodyText }, ...style]}>{`@${mention}`}</Text>;
return (
<Text style={!preview ? [styles.text, { color: themes[theme!].bodyText }, ...style] : styles.text}>{`@${mention}`}</Text>
);
});

export default AtMention;
1 change: 1 addition & 0 deletions app/containers/markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ class Markdown extends PureComponent<IMarkdownProps, any> {
channels={channels}
navToRoomInfo={navToRoomInfo}
onLinkPress={onLinkPress}
preview={preview}
/>
);
}
Expand Down
9 changes: 6 additions & 3 deletions app/containers/markdown/new/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ interface ILinkProps {

const Link = ({ value }: ILinkProps): JSX.Element => {
const { theme } = useTheme();
const { onLinkPress } = useContext(MarkdownContext);
const { onLinkPress, preview } = useContext(MarkdownContext);
const { src, label } = value;
const handlePress = () => {
if (!src.value) {
if (!src.value || preview) {
return;
}
if (onLinkPress) {
Expand All @@ -38,7 +38,10 @@ const Link = ({ value }: ILinkProps): JSX.Element => {
};

return (
<Text onPress={handlePress} onLongPress={onLongPress} style={[styles.link, { color: themes[theme!].actionTintColor }]}>
<Text
onPress={handlePress}
onLongPress={onLongPress}
style={[styles.link, !preview && { color: themes[theme!].actionTintColor }]}>
{(block => {
switch (block.type) {
case 'PLAIN_TEXT':
Expand Down
4 changes: 3 additions & 1 deletion app/containers/markdown/new/MarkdownContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface IMarkdownContext {
navToRoomInfo: Function;
getCustomEmoji?: Function;
onLinkPress?: Function;
preview: boolean;
}

const defaultState = {
Expand All @@ -22,7 +23,8 @@ const defaultState = {
useRealName: false,
username: '',
baseUrl: '',
navToRoomInfo: () => {}
navToRoomInfo: () => {},
preview: false
};

const MarkdownContext = React.createContext<IMarkdownContext>(defaultState);
Expand Down
7 changes: 5 additions & 2 deletions app/containers/markdown/new/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface IBodyProps {
useRealName: boolean;
username: string;
baseUrl: string;
preview: boolean;
}

const Body = ({
Expand All @@ -36,7 +37,8 @@ const Body = ({
navToRoomInfo,
getCustomEmoji,
baseUrl,
onLinkPress
onLinkPress,
preview
}: IBodyProps): JSX.Element => (
<MarkdownContext.Provider
value={{
Expand All @@ -47,7 +49,8 @@ const Body = ({
navToRoomInfo,
getCustomEmoji,
baseUrl,
onLinkPress
onLinkPress,
preview
}}>
{tokens.map(block => {
switch (block.type) {
Expand Down
42 changes: 42 additions & 0 deletions storybook/stories/NewMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import { StyleSheet, View } from 'react-native';
import { storiesOf } from '@storybook/react-native';

import Markdown from '../../app/containers/markdown';
import NewMarkdown from '../../app/containers/markdown/new';
import { themes } from '../../app/constants/colors';

Expand Down Expand Up @@ -625,3 +626,44 @@ stories.add('Lists', () => (
<NewMarkdown tokens={orderedListToken} />
</View>
));

stories.add('Preview', () => (
<View style={styles.container}>
<Markdown
msg={
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
}
md={longTextMsg}
theme={theme}
numberOfLines={1}
preview
/>
<Markdown
msg='@name @rocket.cat @here @all'
md={multipleMentionTokens}
mentions={multipleMentions}
navToRoomInfo={() => {}}
style={[]}
useRealName
theme={theme}
numberOfLines={1}
username='rocket.cat'
preview
/>
<Markdown
msg=':green_heart: :joy: :grin:'
md={bigEmojiTokens}
getCustomEmoji={getCustomEmoji}
theme={theme}
numberOfLines={1}
preview
/>
<Markdown
msg='[ ](https://open.rocket.chat/group/test?msg=abcdef) Test'
md={rocketChatLink}
theme={theme}
numberOfLines={1}
preview
/>
</View>
));