Chore: Evaluate ShareListView - TypeScript (#4117)
This commit is contained in:
parent
888bcae48e
commit
10c4fddd61
|
@ -1,8 +1,8 @@
|
||||||
import { NavigatorScreenParams } from '@react-navigation/core';
|
import { NavigatorScreenParams } from '@react-navigation/core';
|
||||||
import { StackNavigationOptions } from '@react-navigation/stack';
|
import { StackNavigationOptions } from '@react-navigation/stack';
|
||||||
|
|
||||||
import { ISubscription } from './ISubscription';
|
import { TSubscriptionModel } from './ISubscription';
|
||||||
import { IServer } from './IServer';
|
import { TServerModel } from './IServer';
|
||||||
import { IAttachment } from './IAttachment';
|
import { IAttachment } from './IAttachment';
|
||||||
import { MasterDetailInsideStackParamList } from '../stacks/MasterDetailStack/types';
|
import { MasterDetailInsideStackParamList } from '../stacks/MasterDetailStack/types';
|
||||||
import { OutsideParamList, InsideStackParamList } from '../stacks/types';
|
import { OutsideParamList, InsideStackParamList } from '../stacks/types';
|
||||||
|
@ -37,10 +37,10 @@ export type ShareInsideStackParamList = {
|
||||||
attachments: IAttachment[];
|
attachments: IAttachment[];
|
||||||
isShareView?: boolean;
|
isShareView?: boolean;
|
||||||
isShareExtension: boolean;
|
isShareExtension: boolean;
|
||||||
serverInfo: IServer;
|
serverInfo: TServerModel;
|
||||||
text: string;
|
text: string;
|
||||||
room: ISubscription;
|
room: TSubscriptionModel;
|
||||||
thread: any; // TODO: Change
|
thread?: any; // TODO: Change
|
||||||
};
|
};
|
||||||
SelectServerView: undefined;
|
SelectServerView: undefined;
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,8 @@ import SafeAreaView from '../../containers/SafeAreaView';
|
||||||
import { sanitizeLikeString } from '../../lib/database/utils';
|
import { sanitizeLikeString } from '../../lib/database/utils';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import ShareListHeader from './Header';
|
import ShareListHeader from './Header';
|
||||||
import { IServerInfo } from '../../definitions';
|
import { TServerModel, TSubscriptionModel } from '../../definitions';
|
||||||
|
import { ShareInsideStackParamList } from '../../definitions/navigationTypes';
|
||||||
import { getRoomAvatar } from '../../lib/methods';
|
import { getRoomAvatar } from '../../lib/methods';
|
||||||
|
|
||||||
interface IDataFromShare {
|
interface IDataFromShare {
|
||||||
|
@ -35,39 +36,25 @@ interface IFileToShare {
|
||||||
filename: string;
|
filename: string;
|
||||||
description: string;
|
description: string;
|
||||||
size: number;
|
size: number;
|
||||||
mime: any;
|
mime: string;
|
||||||
path: string;
|
path: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IChat {
|
|
||||||
rid: string;
|
|
||||||
t: string;
|
|
||||||
name: string;
|
|
||||||
fname: string;
|
|
||||||
blocked: boolean;
|
|
||||||
blocker: boolean;
|
|
||||||
prid: string;
|
|
||||||
uids: string[];
|
|
||||||
usernames: string[];
|
|
||||||
topic: string;
|
|
||||||
description: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
searching: boolean;
|
searching: boolean;
|
||||||
searchText: string;
|
searchText: string;
|
||||||
searchResults: IChat[];
|
searchResults: TSubscriptionModel[];
|
||||||
chats: IChat[];
|
chats: TSubscriptionModel[];
|
||||||
serversCount: number;
|
serversCount: number;
|
||||||
attachments: IFileToShare[];
|
attachments: IFileToShare[];
|
||||||
text: string;
|
text: string;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
serverInfo: IServerInfo;
|
serverInfo: TServerModel;
|
||||||
needsPermission: boolean;
|
needsPermission: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface INavigationOption {
|
interface INavigationOption {
|
||||||
navigation: StackNavigationProp<any, 'ShareListView'>;
|
navigation: StackNavigationProp<ShareInsideStackParamList, 'ShareListView'>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IShareListViewProps extends INavigationOption {
|
interface IShareListViewProps extends INavigationOption {
|
||||||
|
@ -84,7 +71,7 @@ const permission: Rationale = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getItemLayout = (data: any, index: number) => ({ length: data.length, offset: ROW_HEIGHT * index, index });
|
const getItemLayout = (data: any, index: number) => ({ length: data.length, offset: ROW_HEIGHT * index, index });
|
||||||
const keyExtractor = (item: IChat) => item.rid;
|
const keyExtractor = (item: TSubscriptionModel) => item.rid;
|
||||||
|
|
||||||
class ShareListView extends React.Component<IShareListViewProps, IState> {
|
class ShareListView extends React.Component<IShareListViewProps, IState> {
|
||||||
private unsubscribeFocus: (() => void) | undefined;
|
private unsubscribeFocus: (() => void) | undefined;
|
||||||
|
@ -102,7 +89,7 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
|
||||||
attachments: [],
|
attachments: [],
|
||||||
text: '',
|
text: '',
|
||||||
loading: true,
|
loading: true,
|
||||||
serverInfo: {} as IServerInfo,
|
serverInfo: {} as TServerModel,
|
||||||
needsPermission: isAndroid || false
|
needsPermission: isAndroid || false
|
||||||
};
|
};
|
||||||
this.setHeader();
|
this.setHeader();
|
||||||
|
@ -252,7 +239,7 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
|
||||||
const data = (await db
|
const data = (await db
|
||||||
.get('subscriptions')
|
.get('subscriptions')
|
||||||
.query(...defaultWhereClause)
|
.query(...defaultWhereClause)
|
||||||
.fetch()) as IChat[];
|
.fetch()) as TSubscriptionModel[];
|
||||||
|
|
||||||
return data.map(item => ({
|
return data.map(item => ({
|
||||||
rid: item.rid,
|
rid: item.rid,
|
||||||
|
@ -307,12 +294,12 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
|
||||||
|
|
||||||
uriToPath = (uri: string) => decodeURIComponent(isIOS ? uri.replace(/^file:\/\//, '') : uri);
|
uriToPath = (uri: string) => decodeURIComponent(isIOS ? uri.replace(/^file:\/\//, '') : uri);
|
||||||
|
|
||||||
getRoomTitle = (item: IChat) => {
|
getRoomTitle = (item: TSubscriptionModel) => {
|
||||||
const { serverInfo } = this.state;
|
const { serverInfo } = this.state;
|
||||||
return ((item.prid || serverInfo?.useRealName) && item.fname) || item.name;
|
return ((item.prid || serverInfo?.useRealName) && item.fname) || item.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
shareMessage = (room: IChat) => {
|
shareMessage = (room: TSubscriptionModel) => {
|
||||||
const { attachments, text, serverInfo } = this.state;
|
const { attachments, text, serverInfo } = this.state;
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
|
|
||||||
|
@ -369,7 +356,7 @@ class ShareListView extends React.Component<IShareListViewProps, IState> {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
renderItem = ({ item }: { item: IChat }) => {
|
renderItem = ({ item }: { item: TSubscriptionModel }) => {
|
||||||
const { serverInfo } = this.state;
|
const { serverInfo } = this.state;
|
||||||
let description;
|
let description;
|
||||||
switch (item.t) {
|
switch (item.t) {
|
||||||
|
|
Loading…
Reference in New Issue