From 40cb3b1ae730e2c1d6ae739d4557fde9255c378c Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Tue, 29 Mar 2022 17:06:50 -0300 Subject: [PATCH] Chore: Evaluate UiKit - TypeScript (#3939) * Chore: Evaluate UiKit - TypeScript * minor tweak --- app/containers/ReactionsModal.tsx | 2 +- app/containers/SearchBox.tsx | 6 +- app/containers/UIKit/Actions.tsx | 4 +- app/containers/UIKit/DatePicker.tsx | 14 ++-- app/containers/UIKit/Image.tsx | 17 +++-- app/containers/UIKit/MultiSelect/Chips.tsx | 15 ++-- app/containers/UIKit/MultiSelect/Input.tsx | 4 +- app/containers/UIKit/MultiSelect/Items.tsx | 19 +++-- app/containers/UIKit/MultiSelect/index.tsx | 37 +++++++--- app/containers/UIKit/Overflow.tsx | 9 ++- app/containers/UIKit/Section.tsx | 19 +++-- app/containers/UIKit/Select.tsx | 16 ++--- app/containers/UIKit/index.tsx | 71 ++++++++----------- app/containers/UIKit/interfaces.ts | 21 +++--- app/containers/UIKit/utils.ts | 13 +++- app/containers/message/Attachments.tsx | 1 - app/containers/message/Image.tsx | 9 +-- app/definitions/IAttachment.ts | 2 +- app/externalModules.d.ts | 1 - app/views/AttachmentView.tsx | 4 +- .../CreateDiscussionView/SelectChannel.tsx | 5 +- .../CreateDiscussionView/SelectUsers.tsx | 1 - app/views/LivechatEditView.tsx | 1 - app/views/RoomInfoEditView/index.tsx | 2 - 24 files changed, 151 insertions(+), 142 deletions(-) diff --git a/app/containers/ReactionsModal.tsx b/app/containers/ReactionsModal.tsx index 3240baff6..2cf27a284 100644 --- a/app/containers/ReactionsModal.tsx +++ b/app/containers/ReactionsModal.tsx @@ -74,7 +74,7 @@ interface IItem { interface IModalContent { message?: TMessageModel; - onClose: Function; + onClose: () => void; theme: string; } diff --git a/app/containers/SearchBox.tsx b/app/containers/SearchBox.tsx index 463413b71..e19cd5343 100644 --- a/app/containers/SearchBox.tsx +++ b/app/containers/SearchBox.tsx @@ -47,11 +47,11 @@ const styles = StyleSheet.create({ interface ISearchBox extends TextInputProps { value?: string; hasCancel?: boolean; - onCancelPress?: Function; + onCancelPress?: () => void; inputRef?: React.Ref; } -const CancelButton = ({ onCancelPress }: { onCancelPress?: Function }) => { +const CancelButton = ({ onCancelPress }: { onCancelPress?: () => void }) => { const { theme } = useTheme(); return ( @@ -84,7 +84,7 @@ const SearchBox = ({ hasCancel, onCancelPress, inputRef, ...props }: ISearchBox) {...props} /> - {hasCancel ? : null} + {hasCancel && onCancelPress ? : null} ); }; diff --git a/app/containers/UIKit/Actions.tsx b/app/containers/UIKit/Actions.tsx index 801e8d4ae..ad267013d 100644 --- a/app/containers/UIKit/Actions.tsx +++ b/app/containers/UIKit/Actions.tsx @@ -4,8 +4,10 @@ import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit'; import Button from '../Button'; import I18n from '../../i18n'; import { IActions } from './interfaces'; +import { useTheme } from '../../theme'; -export const Actions = ({ blockId, appId, elements, parser, theme }: IActions) => { +export const Actions = ({ blockId, appId, elements, parser }: IActions) => { + const { theme } = useTheme(); const [showMoreVisible, setShowMoreVisible] = useState(() => elements && elements.length > 5); const renderedElements = showMoreVisible ? elements?.slice(0, 5) : elements; diff --git a/app/containers/UIKit/DatePicker.tsx b/app/containers/UIKit/DatePicker.tsx index 08b5343a8..69ebb1296 100644 --- a/app/containers/UIKit/DatePicker.tsx +++ b/app/containers/UIKit/DatePicker.tsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { StyleSheet, Text, View } from 'react-native'; -import DateTimePicker from '@react-native-community/datetimepicker'; +import DateTimePicker, { Event } from '@react-native-community/datetimepicker'; import Touchable from 'react-native-platform-touchable'; import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit'; import moment from 'moment'; @@ -11,6 +11,7 @@ import { themes } from '../../constants/colors'; import sharedStyles from '../../views/Styles'; import { CustomIcon } from '../../lib/Icons'; import { isAndroid } from '../../utils/deviceInfo'; +import { useTheme } from '../../theme'; import ActivityIndicator from '../ActivityIndicator'; import { IDatePicker } from './interfaces'; @@ -36,14 +37,17 @@ const styles = StyleSheet.create({ } }); -export const DatePicker = ({ element, language, action, context, theme, loading, value, error }: IDatePicker) => { +export const DatePicker = ({ element, language, action, context, loading, value, error }: IDatePicker) => { + const { theme } = useTheme(); const [show, onShow] = useState(false); const initial_date = element?.initial_date; const placeholder = element?.placeholder; const [currentDate, onChangeDate] = useState(new Date(initial_date || value)); - const onChange = ({ nativeEvent: { timestamp } }: any, date: any) => { + // timestamp as number exists in Event + // @ts-ignore + const onChange = ({ nativeEvent: { timestamp } }: Event, date?: Date) => { const newDate = date || new Date(timestamp); onChangeDate(newDate); action({ value: moment(newDate).format('YYYY-MM-DD') }); @@ -52,7 +56,9 @@ export const DatePicker = ({ element, language, action, context, theme, loading, } }; - let button = ); }, - (prevProps, nextProps) => dequal(prevProps.file, nextProps.file) && prevProps.theme === nextProps.theme + (prevProps, nextProps) => dequal(prevProps.file, nextProps.file) ); ImageContainer.displayName = 'MessageImageContainer'; diff --git a/app/definitions/IAttachment.ts b/app/definitions/IAttachment.ts index 94d0e6195..7aedd95ad 100644 --- a/app/definitions/IAttachment.ts +++ b/app/definitions/IAttachment.ts @@ -2,7 +2,7 @@ import { IUser } from './IUser'; export interface IAttachment { ts?: string | Date; - title: string; + title?: string; type?: string; description?: string; title_link?: string; diff --git a/app/externalModules.d.ts b/app/externalModules.d.ts index 02c57204f..bec0d8103 100644 --- a/app/externalModules.d.ts +++ b/app/externalModules.d.ts @@ -3,7 +3,6 @@ declare module 'commonmark'; declare module 'commonmark-react-renderer'; declare module 'remove-markdown'; declare module 'react-native-image-progress'; -declare module 'react-native-platform-touchable'; declare module 'react-native-ui-lib/keyboard'; declare module '@rocket.chat/ui-kit'; declare module '@rocket.chat/sdk'; diff --git a/app/views/AttachmentView.tsx b/app/views/AttachmentView.tsx index 1aef32b07..b51b116d3 100644 --- a/app/views/AttachmentView.tsx +++ b/app/views/AttachmentView.tsx @@ -84,7 +84,9 @@ class AttachmentView extends React.Component {I18n.t('Parent_channel_or_group')} ({ - value: channel, + value: channel.name || channel.fname, text: { text: RocketChat.getRoomTitle(channel) }, imageUrl: getAvatar(channel) }))} diff --git a/app/views/CreateDiscussionView/SelectUsers.tsx b/app/views/CreateDiscussionView/SelectUsers.tsx index 6ef6e25df..cee43dfb5 100644 --- a/app/views/CreateDiscussionView/SelectUsers.tsx +++ b/app/views/CreateDiscussionView/SelectUsers.tsx @@ -77,7 +77,6 @@ const SelectUsers = ({ <> {I18n.t('Invite_users')} diff --git a/app/views/RoomInfoEditView/index.tsx b/app/views/RoomInfoEditView/index.tsx index 615453be6..06d858d92 100644 --- a/app/views/RoomInfoEditView/index.tsx +++ b/app/views/RoomInfoEditView/index.tsx @@ -464,7 +464,6 @@ class RoomInfoEditView extends React.Component { const { systemMessages, enableSysMes } = this.state; - const { theme } = this.props; if (!enableSysMes) { return null; @@ -481,7 +480,6 @@ class RoomInfoEditView extends React.Component ); };