From d3986689e5cb3f5c74338f18f35509b10a3d040c Mon Sep 17 00:00:00 2001 From: AlexAlexandre Date: Thu, 22 Jul 2021 15:30:37 -0300 Subject: [PATCH] [IMPROVE] fix the Reply message errors --- app/containers/message/Reply.tsx | 85 +++++++++++++++++++------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/app/containers/message/Reply.tsx b/app/containers/message/Reply.tsx index 5dcf0447f..b7b402c99 100644 --- a/app/containers/message/Reply.tsx +++ b/app/containers/message/Reply.tsx @@ -1,6 +1,5 @@ import React, { useContext } from 'react'; import { View, Text, StyleSheet } from 'react-native'; -import PropTypes from 'prop-types'; import moment from 'moment'; import { transparentize } from 'color2k'; import { dequal } from 'dequal'; @@ -69,7 +68,49 @@ const styles = StyleSheet.create({ } }); -const Title = React.memo(({ attachment, timeFormat, theme }) => { +type TAttachment = { + author_name: string; + message_link: string; + ts: string; + text: string; + title: string; + short: boolean; + value: string; + title_link: string; + author_link: string; + type: string; + color: string; + description: string; + fields: TAttachment[]; +} + +type TMessageTitle = { + attachment: Partial + timeFormat: string; + theme: string; +}; + +type TMessageDescription = { + attachment: Partial + getCustomEmoji: Function; + theme: string; +}; + +type TMessageFields = { + attachment: Partial; + theme: string; + getCustomEmoji: Function; +}; + +interface IMessageReply { + attachment: Partial + timeFormat: string; + index: number; + theme: string; + getCustomEmoji: Function; +} + +const Title = React.memo(({ attachment, timeFormat, theme }: TMessageTitle) => { if (!attachment.author_name) { return null; } @@ -82,15 +123,14 @@ const Title = React.memo(({ attachment, timeFormat, theme }) => { ); }); -const Description = React.memo(({ - attachment, getCustomEmoji, theme -}) => { +const Description = React.memo(({ attachment, getCustomEmoji, theme }: TMessageDescription) => { const text = attachment.text || attachment.title; if (!text) { return null; } const { baseUrl, user } = useContext(MessageContext); return ( + // @ts-ignore { +const Fields = React.memo(({ attachment, theme, getCustomEmoji }: TMessageFields) => { if (!attachment.fields) { return null; } @@ -123,6 +163,7 @@ const Fields = React.memo(({ attachment, theme, getCustomEmoji }) => { {attachment.fields.map(field => ( {field.title} + {/*@ts-ignore*/} { ); }, (prevProps, nextProps) => dequal(prevProps.attachment.fields, nextProps.attachment.fields) && prevProps.theme === nextProps.theme); -const Reply = React.memo(({ - attachment, timeFormat, index, getCustomEmoji, theme -}) => { +const Reply = React.memo(({ attachment, timeFormat, index, getCustomEmoji, theme }: IMessageReply) => { if (!attachment) { return null; } @@ -203,8 +242,9 @@ const Reply = React.memo(({ /> + {/*@ts-ignore*/} dequal(prevProps.attachment, nextProps.attachment) && prevProps.theme === nextProps.theme); -Reply.propTypes = { - attachment: PropTypes.object, - timeFormat: PropTypes.string, - index: PropTypes.number, - theme: PropTypes.string, - getCustomEmoji: PropTypes.func -}; Reply.displayName = 'MessageReply'; - -Title.propTypes = { - attachment: PropTypes.object, - timeFormat: PropTypes.string, - theme: PropTypes.string -}; Title.displayName = 'MessageReplyTitle'; - -Description.propTypes = { - attachment: PropTypes.object, - getCustomEmoji: PropTypes.func, - theme: PropTypes.string -}; Description.displayName = 'MessageReplyDescription'; - -Fields.propTypes = { - attachment: PropTypes.object, - theme: PropTypes.string, - getCustomEmoji: PropTypes.func -}; Fields.displayName = 'MessageReplyFields'; export default Reply;