Skip to content

Commit

Permalink
Chore: Evaluate Markdown - TypeScript (#3948)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinaldonetof authored Mar 25, 2022
1 parent d5ac663 commit 6418803
Show file tree
Hide file tree
Showing 30 changed files with 60 additions and 59 deletions.
15 changes: 8 additions & 7 deletions app/containers/markdown/AtMention.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React from 'react';
import { Text } from 'react-native';
import { StyleProp, Text, TextStyle } from 'react-native';

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

interface IAtMention {
mention: string;
username?: string;
navToRoomInfo?: Function;
style?: any;
style?: StyleProp<TextStyle>[];
useRealName?: boolean;
mentions: any;
mentions?: IUserMention[];
}

const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, style = [], useRealName }: IAtMention) => {
Expand All @@ -23,7 +24,7 @@ const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, styl
style={[
styles.mention,
{
color: themes[theme!].mentionGroupColor
color: themes[theme].mentionGroupColor
},
...style
]}>
Expand All @@ -35,11 +36,11 @@ const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, styl
let mentionStyle = {};
if (mention === username) {
mentionStyle = {
color: themes[theme!].mentionMeColor
color: themes[theme].mentionMeColor
};
} else {
mentionStyle = {
color: themes[theme!].mentionOtherColor
color: themes[theme].mentionOtherColor
};
}

Expand All @@ -64,7 +65,7 @@ const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, styl
);
}

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

export default AtMention;
2 changes: 1 addition & 1 deletion app/containers/markdown/BlockQuote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { themes } from '../../constants/colors';
import styles from './styles';

interface IBlockQuote {
children: JSX.Element;
children: React.ReactElement | null;
theme: string;
}

Expand Down
6 changes: 3 additions & 3 deletions app/containers/markdown/Hashtag.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Text, TextStyle, StyleProp } from 'react-native';
import { StyleProp, Text, TextStyle } from 'react-native';

import { themes } from '../../constants/colors';
import { useTheme } from '../../theme';
Expand Down Expand Up @@ -33,7 +33,7 @@ const Hashtag = React.memo(({ hashtag, channels, navToRoomInfo, style = [] }: IH
style={[
styles.mention,
{
color: themes[theme!].mentionOtherColor
color: themes[theme].mentionOtherColor
},
...style
]}
Expand All @@ -42,7 +42,7 @@ const Hashtag = React.memo(({ hashtag, channels, navToRoomInfo, style = [] }: IH
</Text>
);
}
return <Text style={[styles.text, { color: themes[theme!].bodyText }, ...style]}>{`#${hashtag}`}</Text>;
return <Text style={[styles.text, { color: themes[theme].bodyText }, ...style]}>{`#${hashtag}`}</Text>;
});

export default Hashtag;
2 changes: 1 addition & 1 deletion app/containers/markdown/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import openLink from '../../utils/openLink';
import { TOnLinkPress } from './interfaces';

interface ILink {
children: JSX.Element;
children: React.ReactElement | null;
link: string;
theme: string;
onLinkPress?: TOnLinkPress;
Expand Down
7 changes: 3 additions & 4 deletions app/containers/markdown/List.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

interface IList {
children: JSX.Element;
children: React.ReactElement[] | null;
ordered: boolean;
start: number;
tight: boolean;
Expand All @@ -11,9 +11,8 @@ interface IList {
const List = React.memo(({ children, ordered, tight, start = 1, numberOfLines = 0 }: IList) => {
let bulletWidth = 15;

if (ordered) {
// @ts-ignore
const lastNumber = start + children.length - 1;
if (ordered && children) {
const lastNumber = start + children?.length - 1;
bulletWidth = 9 * lastNumber.toString().length + 7;
}

Expand Down
2 changes: 1 addition & 1 deletion app/containers/markdown/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const style = StyleSheet.create({
});

interface IListItem {
children: JSX.Element;
children: React.ReactElement | null;
bulletWidth: number;
level: number;
ordered: boolean;
Expand Down
6 changes: 3 additions & 3 deletions app/containers/markdown/Preview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { StyleProp, Text, TextStyle } from 'react-native';
import { Text, TextStyle } from 'react-native';
import removeMarkdown from 'remove-markdown';

import shortnameToUnicode from '../../utils/shortnameToUnicode';
Expand All @@ -13,10 +13,10 @@ interface IMarkdownPreview {
msg?: string;
numberOfLines?: number;
testID?: string;
style?: StyleProp<TextStyle>[];
style?: TextStyle[];
}

const MarkdownPreview = ({ msg, numberOfLines = 1, testID, style = [] }: IMarkdownPreview): React.ReactElement | null => {
const MarkdownPreview = ({ msg, numberOfLines = 1, testID, style = [] }: IMarkdownPreview) => {
if (!msg) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion app/containers/markdown/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import I18n from '../../i18n';
import { themes } from '../../constants/colors';

interface ITable {
children: JSX.Element;
children: React.ReactElement | null;
numColumns: number;
theme: string;
}
Expand Down
2 changes: 1 addition & 1 deletion app/containers/markdown/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import styles from './styles';

interface ITableCell {
align: '' | 'left' | 'center' | 'right';
children: JSX.Element;
children: React.ReactElement | null;
isLastCell: boolean;
theme: string;
}
Expand Down
4 changes: 2 additions & 2 deletions app/containers/markdown/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { themes } from '../../constants/colors';
import styles from './styles';

interface ITableRow {
children: JSX.Element;
children: React.ReactElement | null;
isLastRow: boolean;
theme: string;
}
Expand All @@ -16,7 +16,7 @@ const TableRow = React.memo(({ isLastRow, children: _children, theme }: ITableRo
rowStyle.push(styles.rowBottomBorder);
}

const children: any = React.Children.toArray(_children);
const children = React.Children.toArray(_children) as React.ReactElement[];
children[children.length - 1] = React.cloneElement(children[children.length - 1], {
isLastCell: true
});
Expand Down
1 change: 1 addition & 0 deletions app/containers/markdown/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface IUserMention {
_id: string;
username: string;
name?: string;
type?: string;
}

export interface IUserChannel {
Expand Down
2 changes: 1 addition & 1 deletion app/containers/markdown/new/BigEmoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const styles = StyleSheet.create({
}
});

const BigEmoji = ({ value }: IBigEmojiProps): JSX.Element => (
const BigEmoji = ({ value }: IBigEmojiProps) => (
<View style={styles.container}>
{value.map(block => (
<Emoji value={block.value} isBigEmoji />
Expand Down
2 changes: 1 addition & 1 deletion app/containers/markdown/new/Bold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const styles = StyleSheet.create({
}
});

const Bold = ({ value }: IBoldProps): JSX.Element => (
const Bold = ({ value }: IBoldProps) => (
<Text style={styles.text}>
{value.map(block => {
switch (block.type) {
Expand Down
8 changes: 4 additions & 4 deletions app/containers/markdown/new/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ interface ICodeProps {
value: CodeProps['value'];
}

const Code = ({ value }: ICodeProps): JSX.Element => {
const Code = ({ value }: ICodeProps) => {
const { theme } = useTheme();

return (
<Text
style={[
styles.codeBlock,
{
color: themes[theme!].bodyText,
backgroundColor: themes[theme!].bannerBackground,
borderColor: themes[theme!].borderColor
color: themes[theme].bodyText,
backgroundColor: themes[theme].bannerBackground,
borderColor: themes[theme].borderColor
}
]}>
{value.map(block => {
Expand Down
2 changes: 1 addition & 1 deletion app/containers/markdown/new/CodeLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface ICodeLineProps {
value: CodeLineProps['value'];
}

const CodeLine = ({ value }: ICodeLineProps): JSX.Element | null => {
const CodeLine = ({ value }: ICodeLineProps) => {
if (value.type !== 'PLAIN_TEXT') {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions app/containers/markdown/new/Emoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IEmojiProps {
isBigEmoji?: boolean;
}

const Emoji = ({ value, isBigEmoji }: IEmojiProps): JSX.Element => {
const Emoji = ({ value, isBigEmoji }: IEmojiProps) => {
const { theme } = useTheme();
const { baseUrl, getCustomEmoji } = useContext(MarkdownContext);
const emojiUnicode = shortnameToUnicode(`:${value.value}:`);
Expand All @@ -23,7 +23,7 @@ const Emoji = ({ value, isBigEmoji }: IEmojiProps): JSX.Element => {
if (emoji) {
return <CustomEmoji baseUrl={baseUrl} style={[isBigEmoji ? styles.customEmojiBig : styles.customEmoji]} emoji={emoji} />;
}
return <Text style={[{ color: themes[theme!].bodyText }, isBigEmoji ? styles.textBig : styles.text]}>{emojiUnicode}</Text>;
return <Text style={[{ color: themes[theme].bodyText }, isBigEmoji ? styles.textBig : styles.text]}>{emojiUnicode}</Text>;
};

export default Emoji;
4 changes: 2 additions & 2 deletions app/containers/markdown/new/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ interface IHeadingProps {
level: HeadingProps['level'];
}

const Heading = ({ value, level }: IHeadingProps): JSX.Element => {
const Heading = ({ value, level }: IHeadingProps) => {
const { theme } = useTheme();
const textStyle = styles[`heading${level}`];

return (
<Text style={[textStyle, { color: themes[theme!].bodyText }]}>
<Text style={[textStyle, { color: themes[theme].bodyText }]}>
{value.map(block => {
switch (block.type) {
case 'PLAIN_TEXT':
Expand Down
4 changes: 2 additions & 2 deletions app/containers/markdown/new/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ const MessageImage = ({ img, theme }: TMessageImage) => (
/>
);

const Image = ({ value }: IImageProps): JSX.Element => {
const Image = ({ value }: IImageProps) => {
const { theme } = useTheme();
const { src } = value;

return <MessageImage img={src.value} theme={theme!} />;
return <MessageImage img={src.value} theme={theme} />;
};

export default Image;
2 changes: 1 addition & 1 deletion app/containers/markdown/new/Inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface IParagraphProps {
value: ParagraphProps['value'];
}

const Inline = ({ value }: IParagraphProps): JSX.Element => {
const Inline = ({ value }: IParagraphProps) => {
const { useRealName, username, navToRoomInfo, mentions, channels } = useContext(MarkdownContext);
return (
<Text style={styles.inline}>
Expand Down
8 changes: 4 additions & 4 deletions app/containers/markdown/new/InlineCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ interface IInlineCodeProps {
value: InlineCodeProps['value'];
}

const InlineCode = ({ value }: IInlineCodeProps): JSX.Element => {
const InlineCode = ({ value }: IInlineCodeProps) => {
const { theme } = useTheme();

return (
<Text
style={[
styles.codeInline,
{
color: themes[theme!].bodyText,
backgroundColor: themes[theme!].bannerBackground,
borderColor: themes[theme!].borderColor
color: themes[theme].bodyText,
backgroundColor: themes[theme].bannerBackground,
borderColor: themes[theme].borderColor
}
]}>
{(block => {
Expand Down
2 changes: 1 addition & 1 deletion app/containers/markdown/new/Italic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const styles = StyleSheet.create({
}
});

const Italic = ({ value }: IItalicProps): JSX.Element => (
const Italic = ({ value }: IItalicProps) => (
<Text style={styles.text}>
{value.map(block => {
switch (block.type) {
Expand Down
4 changes: 2 additions & 2 deletions app/containers/markdown/new/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ILinkProps {
value: LinkProps['value'];
}

const Link = ({ value }: ILinkProps): JSX.Element => {
const Link = ({ value }: ILinkProps) => {
const { theme } = useTheme();
const { onLinkPress } = useContext(MarkdownContext);
const { src, label } = value;
Expand All @@ -38,7 +38,7 @@ 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, { color: themes[theme].actionTintColor }]}>
{(block => {
switch (block.type) {
case 'PLAIN_TEXT':
Expand Down
4 changes: 2 additions & 2 deletions app/containers/markdown/new/OrderedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ interface IOrderedListProps {
value: OrderedListProps['value'];
}

const OrderedList = ({ value }: IOrderedListProps): JSX.Element => {
const OrderedList = ({ value }: IOrderedListProps) => {
const { theme } = useTheme();
return (
<View>
{value.map((item, index) => (
<View style={styles.row}>
<Text style={[styles.text, { color: themes[theme!].bodyText }]}>{index + 1}. </Text>
<Text style={[styles.text, { color: themes[theme].bodyText }]}>{index + 1}. </Text>
<Inline value={item.value} />
</View>
))}
Expand Down
4 changes: 2 additions & 2 deletions app/containers/markdown/new/Paragraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ interface IParagraphProps {
value: ParagraphProps['value'];
}

const Paragraph = ({ value }: IParagraphProps): JSX.Element => {
const Paragraph = ({ value }: IParagraphProps) => {
const { theme } = useTheme();
return (
<Text style={[styles.text, { color: themes[theme!].bodyText }]}>
<Text style={[styles.text, { color: themes[theme].bodyText }]}>
<Inline value={value} />
</Text>
);
Expand Down
4 changes: 2 additions & 2 deletions app/containers/markdown/new/Plain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ interface IPlainProps {
value: PlainProps['value'];
}

const Plain = ({ value }: IPlainProps): JSX.Element => {
const Plain = ({ value }: IPlainProps) => {
const { theme } = useTheme();
return (
<Text accessibilityLabel={value} style={[styles.plainText, { color: themes[theme!].bodyText }]}>
<Text accessibilityLabel={value} style={[styles.plainText, { color: themes[theme].bodyText }]}>
{value}
</Text>
);
Expand Down
Loading

0 comments on commit 6418803

Please sign in to comment.