* typescript and view component for permalink with user and message * Old post edited handling in permalink * Added test and update flag value to EnablePermalinkPreview * Added test for permalink_preview component * Added test for content/index.tsx for permalink * Addressed review comments * Unit test for missing file and review comments * Added test to check handlePostEdited permalink sync only calls one time only * Change TouchableOpacity to Pressable * When user not found fetch the user from the server * Removed the redundant test in the test for permalink_preview/index? * ts to tsx * Removed the circular dependency * Address review comments * displayname fallback * remove permalink when permalink post is deleted * UX review comments * Linter fixes * Test fixes * Address review comments * Minor * Some more review comments --------- Co-authored-by: yasserfaraazkhan <attitude3cena.yf@gmail.com>
113 lines
3.2 KiB
TypeScript
113 lines
3.2 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {Node, Parser} from 'commonmark';
|
|
import Renderer from 'commonmark-react-renderer';
|
|
import React, {type ReactElement, useRef} from 'react';
|
|
import {type StyleProp, StyleSheet, Text, type TextStyle, View} from 'react-native';
|
|
|
|
import EditedIndicator from '@components/edited_indicator';
|
|
import Emoji from '@components/emoji';
|
|
import {useTheme} from '@context/theme';
|
|
|
|
type JumboEmojiProps = {
|
|
baseTextStyle: StyleProp<TextStyle>;
|
|
isEdited?: boolean;
|
|
value: string;
|
|
}
|
|
|
|
const style = StyleSheet.create({
|
|
block: {
|
|
alignItems: 'flex-start',
|
|
flexDirection: 'row',
|
|
flexWrap: 'wrap',
|
|
},
|
|
jumboEmoji: {
|
|
fontSize: 50,
|
|
lineHeight: 60,
|
|
},
|
|
newLine: {
|
|
lineHeight: 60,
|
|
},
|
|
});
|
|
|
|
const JumboEmoji = ({baseTextStyle, isEdited, value}: JumboEmojiProps) => {
|
|
const theme = useTheme();
|
|
|
|
const renderEmoji = ({emojiName, literal}: {context: string[]; emojiName: string; literal: string}) => {
|
|
return (
|
|
<View>
|
|
<Emoji
|
|
emojiName={emojiName}
|
|
literal={literal}
|
|
testID='markdown_emoji'
|
|
textStyle={[baseTextStyle, style.jumboEmoji]}
|
|
/>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
const renderParagraph = ({children}: {children: ReactElement}) => {
|
|
return (
|
|
<View style={style.block}><Text>{children}</Text></View>
|
|
);
|
|
};
|
|
|
|
const renderText = ({literal}: {literal: string}) => {
|
|
return renderEmoji({emojiName: literal, literal, context: []});
|
|
};
|
|
|
|
const renderNewLine = () => {
|
|
return <Text style={[baseTextStyle, style.newLine]}>{'\n'}</Text>;
|
|
};
|
|
|
|
const renderEditedIndicator = ({context}: {context: string[]}) => {
|
|
return (
|
|
<EditedIndicator
|
|
baseTextStyle={baseTextStyle}
|
|
theme={theme}
|
|
context={context}
|
|
iconSize={14}
|
|
checkHeadings={false}
|
|
testID='edited_indicator'
|
|
/>
|
|
);
|
|
};
|
|
|
|
const createRenderer = () => {
|
|
const renderers: any = {
|
|
editedIndicator: renderEditedIndicator,
|
|
emoji: renderEmoji,
|
|
paragraph: renderParagraph,
|
|
document: renderParagraph,
|
|
text: renderText,
|
|
hardbreak: renderNewLine,
|
|
softBreak: renderNewLine,
|
|
};
|
|
|
|
return new Renderer({
|
|
renderers,
|
|
renderParagraphsInLists: true,
|
|
});
|
|
};
|
|
|
|
const parser = useRef(new Parser()).current;
|
|
const renderer = useRef(createRenderer()).current;
|
|
const ast = parser.parse(value.replace(/\n*$/, ''));
|
|
|
|
if (isEdited) {
|
|
const editIndicatorNode = new Node('edited_indicator');
|
|
if (ast.lastChild && ['heading', 'paragraph'].includes(ast.lastChild.type)) {
|
|
ast.appendChild(editIndicatorNode);
|
|
} else {
|
|
const node = new Node('paragraph');
|
|
node.appendChild(editIndicatorNode);
|
|
|
|
ast.appendChild(node);
|
|
}
|
|
}
|
|
|
|
return renderer.render(ast) as ReactElement;
|
|
};
|
|
|
|
export default JumboEmoji;
|