Fix ShareView and ShareListView types

This commit is contained in:
Diego Mello 2023-03-22 13:54:34 -03:00
parent f60a9f6332
commit 221702520c
6 changed files with 53 additions and 44 deletions

View File

@ -6,6 +6,7 @@ import { IMessage } from '../../definitions/IMessage';
import { ISubscription, SubscriptionType, TSubscriptionModel } from '../../definitions/ISubscription'; import { ISubscription, SubscriptionType, TSubscriptionModel } from '../../definitions/ISubscription';
import { ILivechatDepartment } from '../../definitions/ILivechatDepartment'; import { ILivechatDepartment } from '../../definitions/ILivechatDepartment';
import { ILivechatTag } from '../../definitions/ILivechatTag'; import { ILivechatTag } from '../../definitions/ILivechatTag';
import { TServerModel, TThreadModel } from '../../definitions';
export type MasterDetailChatsStackParamList = { export type MasterDetailChatsStackParamList = {
RoomView: { RoomView: {
@ -213,9 +214,13 @@ export type MasterDetailInsideStackParamList = {
ShareView: { ShareView: {
attachments: IAttachment[]; attachments: IAttachment[];
isShareView?: boolean; isShareView?: boolean;
serverInfo: {}; isShareExtension: boolean;
serverInfo: TServerModel;
text: string; text: string;
room: ISubscription; room: TSubscriptionModel;
thread: any; // TODO: Change thread?: TThreadModel;
replying?: boolean;
replyingMessage?: IMessage;
closeReply?: Function;
}; };
}; };

View File

@ -3,6 +3,7 @@ import { NavigatorScreenParams } from '@react-navigation/core';
import { TSubscriptionModel } from '../../definitions/ISubscription'; import { TSubscriptionModel } from '../../definitions/ISubscription';
import { TServerModel } from '../../definitions/IServer'; import { TServerModel } from '../../definitions/IServer';
import { IAttachment } from '../../definitions/IAttachment'; import { IAttachment } from '../../definitions/IAttachment';
import { IMessage, TThreadModel } from '../../definitions';
export type ShareInsideStackParamList = { export type ShareInsideStackParamList = {
ShareListView: undefined; ShareListView: undefined;
@ -13,7 +14,10 @@ export type ShareInsideStackParamList = {
serverInfo: TServerModel; serverInfo: TServerModel;
text: string; text: string;
room: TSubscriptionModel; room: TSubscriptionModel;
thread?: any; // TODO: Change thread?: TThreadModel;
replying?: boolean;
replyingMessage?: IMessage;
closeReply?: Function;
}; };
SelectServerView: undefined; SelectServerView: undefined;
}; };

View File

@ -3,7 +3,7 @@ import { TextInputProps } from 'react-native';
import { IItem } from '../views/TeamChannelsView'; import { IItem } from '../views/TeamChannelsView';
import { IOptionsField } from '../views/NotificationPreferencesView/options'; import { IOptionsField } from '../views/NotificationPreferencesView/options';
import { IServer } from '../definitions/IServer'; import { TServerModel } from '../definitions/IServer';
import { IAttachment } from '../definitions/IAttachment'; import { IAttachment } from '../definitions/IAttachment';
import { IMessage, TAnyMessageModel, TMessageModel } from '../definitions/IMessage'; import { IMessage, TAnyMessageModel, TMessageModel } from '../definitions/IMessage';
import { ISubscription, SubscriptionType, TSubscriptionModel } from '../definitions/ISubscription'; import { ISubscription, SubscriptionType, TSubscriptionModel } from '../definitions/ISubscription';
@ -283,10 +283,10 @@ export type InsideStackParamList = {
attachments: IAttachment[]; attachments: IAttachment[];
isShareView?: boolean; isShareView?: boolean;
isShareExtension: boolean; isShareExtension: boolean;
serverInfo: IServer; serverInfo: TServerModel;
text: string; text: string;
room: TSubscriptionModel; room: TSubscriptionModel;
thread: TThreadModel; thread?: TThreadModel;
replying?: boolean; replying?: boolean;
replyingMessage?: IMessage; replyingMessage?: IMessage;
closeReply?: Function; closeReply?: Function;

View File

@ -23,8 +23,8 @@ import { sanitizeLikeString } from '../../lib/database/utils';
import styles from './styles'; import styles from './styles';
import ShareListHeader from './Header'; import ShareListHeader from './Header';
import { TServerModel, TSubscriptionModel } from '../../definitions'; import { TServerModel, TSubscriptionModel } from '../../definitions';
import { ShareInsideStackParamList } from '../../definitions/navigationTypes';
import { getRoomAvatar, isAndroid, isIOS } from '../../lib/methods/helpers'; import { getRoomAvatar, isAndroid, isIOS } from '../../lib/methods/helpers';
import { ShareInsideStackParamList } from '../../stacks/ShareExtensionStack/types';
interface IDataFromShare { interface IDataFromShare {
value: string; value: string;
@ -57,10 +57,10 @@ interface INavigationOption {
} }
interface IShareListViewProps extends INavigationOption { interface IShareListViewProps extends INavigationOption {
server: string; server?: string;
token: string; token?: string;
userId: string; userId?: string;
theme: TSupportedThemes; theme?: TSupportedThemes;
} }
const permission: Rationale = { const permission: Rationale = {
@ -117,7 +117,7 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
const attachments = info.map(file => ({ const attachments = info.map(file => ({
filename: decodeURIComponent(file.uri.substring(file.uri.lastIndexOf('/') + 1)), filename: decodeURIComponent(file.uri.substring(file.uri.lastIndexOf('/') + 1)),
description: '', description: '',
size: file.size, size: file.exists ? file.size : null,
mime: mime.lookup(file.uri), mime: mime.lookup(file.uri),
path: file.uri path: file.uri
})) as IFileToShare[]; })) as IFileToShare[];
@ -187,7 +187,7 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
initSearch={this.initSearch} initSearch={this.initSearch}
cancelSearch={this.cancelSearch} cancelSearch={this.cancelSearch}
onChangeSearchText={this.search} onChangeSearchText={this.search}
theme={theme} theme={theme!}
/> />
) )
}); });
@ -203,7 +203,7 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
) : ( ) : (
<HeaderButton.CancelModal onPress={ShareExtension.close} testID='share-extension-close' /> <HeaderButton.CancelModal onPress={ShareExtension.close} testID='share-extension-close' />
), ),
headerTitle: () => <ShareListHeader searching={searching} onChangeSearchText={this.search} theme={theme} />, headerTitle: () => <ShareListHeader searching={searching} onChangeSearchText={this.search} theme={theme!} />,
headerRight: () => headerRight: () =>
searching ? null : ( searching ? null : (
<HeaderButton.Container> <HeaderButton.Container>
@ -255,7 +255,7 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
})); }));
}; };
getSubscriptions = async (server: string) => { getSubscriptions = async (server: IShareListViewProps['server']) => {
const serversDB = database.servers; const serversDB = database.servers;
if (server) { if (server) {
@ -348,8 +348,8 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
return ( return (
<> <>
<View style={[styles.headerContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}> <View style={[styles.headerContainer, { backgroundColor: themes[theme!].auxiliaryBackground }]}>
<Text style={[styles.headerText, { color: themes[theme].titleText }]}>{I18n.t(header)}</Text> <Text style={[styles.headerText, { color: themes[theme!].titleText }]}>{I18n.t(header)}</Text>
</View> </View>
<List.Separator /> <List.Separator />
</> </>
@ -401,8 +401,8 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
renderEmptyComponent = () => { renderEmptyComponent = () => {
const { theme } = this.props; const { theme } = this.props;
return ( return (
<View style={[styles.container, styles.emptyContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}> <View style={[styles.container, styles.emptyContainer, { backgroundColor: themes[theme!].auxiliaryBackground }]}>
<Text style={[styles.title, { color: themes[theme].titleText }]}>{I18n.t('No_results_found')}</Text> <Text style={[styles.title, { color: themes[theme!].titleText }]}>{I18n.t('No_results_found')}</Text>
</View> </View>
); );
}; };
@ -438,11 +438,11 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
return ( return (
<SafeAreaView> <SafeAreaView>
<ScrollView <ScrollView
style={{ backgroundColor: themes[theme].backgroundColor }} style={{ backgroundColor: themes[theme!].backgroundColor }}
contentContainerStyle={[styles.container, styles.centered, { backgroundColor: themes[theme].backgroundColor }]} contentContainerStyle={[styles.container, styles.centered, { backgroundColor: themes[theme!].backgroundColor }]}
> >
<Text style={[styles.permissionTitle, { color: themes[theme].titleText }]}>{permission.title}</Text> <Text style={[styles.permissionTitle, { color: themes[theme!].titleText }]}>{permission.title}</Text>
<Text style={[styles.permissionMessage, { color: themes[theme].bodyText }]}>{permission.message}</Text> <Text style={[styles.permissionMessage, { color: themes[theme!].bodyText }]}>{permission.message}</Text>
</ScrollView> </ScrollView>
</SafeAreaView> </SafeAreaView>
); );
@ -453,8 +453,8 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
<FlatList <FlatList
data={searching ? searchResults : chats} data={searching ? searchResults : chats}
keyExtractor={keyExtractor} keyExtractor={keyExtractor}
style={[styles.flatlist, { backgroundColor: themes[theme].auxiliaryBackground }]} style={[styles.flatlist, { backgroundColor: themes[theme!].auxiliaryBackground }]}
contentContainerStyle={{ backgroundColor: themes[theme].backgroundColor }} contentContainerStyle={{ backgroundColor: themes[theme!].backgroundColor }}
renderItem={this.renderItem} renderItem={this.renderItem}
getItemLayout={getItemLayout} getItemLayout={getItemLayout}
ItemSeparatorComponent={List.Separator} ItemSeparatorComponent={List.Separator}
@ -470,9 +470,9 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
} }
const mapStateToProps = ({ share }: any) => ({ const mapStateToProps = ({ share }: any) => ({
userId: share.user && share.user.id, userId: share?.user?.id,
token: share.user && share.user.token, token: share?.user?.token,
server: share.server.server server: share?.server?.server
}); });
export default connect(mapStateToProps)(withTheme(ShareListView)); export default connect(mapStateToProps)(withTheme(ShareListView));

View File

@ -36,7 +36,7 @@ const styles = StyleSheet.create({
interface IHeader { interface IHeader {
room: ISubscription; room: ISubscription;
thread: TThreadModel; thread?: TThreadModel;
} }
const Header = React.memo(({ room, thread }: IHeader) => { const Header = React.memo(({ room, thread }: IHeader) => {

View File

@ -41,7 +41,7 @@ interface IShareViewState {
attachments: IShareAttachment[]; attachments: IShareAttachment[];
text: string; text: string;
room: TSubscriptionModel; room: TSubscriptionModel;
thread: TThreadModel; thread?: TThreadModel;
maxFileSize?: number; maxFileSize?: number;
mediaAllowList?: string; mediaAllowList?: string;
} }
@ -49,7 +49,7 @@ interface IShareViewState {
interface IShareViewProps { interface IShareViewProps {
navigation: StackNavigationProp<InsideStackParamList, 'ShareView'>; navigation: StackNavigationProp<InsideStackParamList, 'ShareView'>;
route: RouteProp<InsideStackParamList, 'ShareView'>; route: RouteProp<InsideStackParamList, 'ShareView'>;
theme: TSupportedThemes; theme?: TSupportedThemes;
user: { user: {
id: string; id: string;
username: string; username: string;
@ -94,7 +94,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
attachments: [], attachments: [],
text: props.route.params?.text ?? '', text: props.route.params?.text ?? '',
room: props.route.params?.room ?? {}, room: props.route.params?.room ?? {},
thread: props.route.params?.thread ?? {}, thread: props.route.params?.thread,
maxFileSize: this.isShareExtension ? this.serverInfo?.FileUpload_MaxFileSize : props.FileUpload_MaxFileSize, maxFileSize: this.isShareExtension ? this.serverInfo?.FileUpload_MaxFileSize : props.FileUpload_MaxFileSize,
mediaAllowList: this.isShareExtension ? this.serverInfo?.FileUpload_MediaTypeWhiteList : props.FileUpload_MediaTypeWhiteList mediaAllowList: this.isShareExtension ? this.serverInfo?.FileUpload_MediaTypeWhiteList : props.FileUpload_MediaTypeWhiteList
}; };
@ -124,23 +124,23 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
const options: StackNavigationOptions = { const options: StackNavigationOptions = {
headerTitle: () => <Header room={room} thread={thread} />, headerTitle: () => <Header room={room} thread={thread} />,
headerTitleAlign: 'left', headerTitleAlign: 'left',
headerTintColor: themes[theme].previewTintColor headerTintColor: themes[theme!].previewTintColor
}; };
// if is share extension show default back button // if is share extension show default back button
if (!this.isShareExtension) { if (!this.isShareExtension) {
options.headerLeft = () => <HeaderButton.CloseModal navigation={navigation} color={themes[theme].previewTintColor} />; options.headerLeft = () => <HeaderButton.CloseModal navigation={navigation} color={themes[theme!].previewTintColor} />;
} }
if (!attachments.length && !readOnly) { if (!attachments.length && !readOnly) {
options.headerRight = () => ( options.headerRight = () => (
<HeaderButton.Container> <HeaderButton.Container>
<HeaderButton.Item title={I18n.t('Send')} onPress={this.send} color={themes[theme].previewTintColor} /> <HeaderButton.Item title={I18n.t('Send')} onPress={this.send} color={themes[theme!].previewTintColor} />
</HeaderButton.Container> </HeaderButton.Container>
); );
} }
options.headerBackground = () => <View style={[styles.container, { backgroundColor: themes[theme].previewBackground }]} />; options.headerBackground = () => <View style={[styles.container, { backgroundColor: themes[theme!].previewBackground }]} />;
navigation.setOptions(options); navigation.setOptions(options);
}; };
@ -331,7 +331,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
key={selected?.path} key={selected?.path}
item={selected} item={selected}
length={attachments.length} length={attachments.length}
theme={theme} theme={theme!}
isShareExtension={this.isShareExtension} isShareExtension={this.isShareExtension}
/> />
<MessageBox <MessageBox
@ -351,7 +351,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
> >
<Thumbs <Thumbs
attachments={attachments} attachments={attachments}
theme={theme} theme={theme!}
isShareExtension={this.isShareExtension} isShareExtension={this.isShareExtension}
onPress={this.selectFile} onPress={this.selectFile}
onRemove={this.removeFile} onRemove={this.removeFile}
@ -364,7 +364,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
return ( return (
<FormTextInput <FormTextInput
containerStyle={styles.inputContainer} containerStyle={styles.inputContainer}
inputStyle={[styles.input, styles.textInput, { backgroundColor: themes[theme].focusedBackground }]} inputStyle={[styles.input, styles.textInput, { backgroundColor: themes[theme!].focusedBackground }]}
placeholder='' placeholder=''
onChangeText={this.onChangeText} onChangeText={this.onChangeText}
defaultValue='' defaultValue=''
@ -382,16 +382,16 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
const { theme } = this.props; const { theme } = this.props;
if (readOnly || isBlocked(room)) { if (readOnly || isBlocked(room)) {
return ( return (
<View style={[styles.container, styles.centered, { backgroundColor: themes[theme].backgroundColor }]}> <View style={[styles.container, styles.centered, { backgroundColor: themes[theme!].backgroundColor }]}>
<Text style={[styles.title, { color: themes[theme].titleText }]}> <Text style={[styles.title, { color: themes[theme!].titleText }]}>
{isBlocked(room) ? I18n.t('This_room_is_blocked') : I18n.t('This_room_is_read_only')} {isBlocked(room) ? I18n.t('This_room_is_blocked') : I18n.t('This_room_is_read_only')}
</Text> </Text>
</View> </View>
); );
} }
return ( return (
<SafeAreaView style={{ backgroundColor: themes[theme].backgroundColor }}> <SafeAreaView style={{ backgroundColor: themes[theme!].backgroundColor }}>
<StatusBar barStyle='light-content' backgroundColor={themes[theme].previewBackground} /> <StatusBar barStyle='light-content' backgroundColor={themes[theme!].previewBackground} />
{this.renderContent()} {this.renderContent()}
</SafeAreaView> </SafeAreaView>
); );