Chore: Evaluate ShareView - TypeScript (#4087)
This commit is contained in:
parent
59be3b68b8
commit
fe84090703
|
@ -677,7 +677,12 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
canUploadFile = (file: any) => {
|
canUploadFile = (file: any) => {
|
||||||
const { permissionToUpload } = this.state;
|
const { permissionToUpload } = this.state;
|
||||||
const { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize } = this.props;
|
const { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize } = this.props;
|
||||||
const result = canUploadFile(file, FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize, permissionToUpload);
|
const result = canUploadFile({
|
||||||
|
file,
|
||||||
|
allowList: FileUpload_MediaTypeWhiteList,
|
||||||
|
maxFileSize: FileUpload_MaxFileSize,
|
||||||
|
permissionToUploadFile: permissionToUpload
|
||||||
|
});
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,3 +56,14 @@ export interface IServerAttachment {
|
||||||
url: string;
|
url: string;
|
||||||
user: Pick<IUser, '_id' | 'username' | 'name'>;
|
user: Pick<IUser, '_id' | 'username' | 'name'>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IShareAttachment {
|
||||||
|
filename: string;
|
||||||
|
description?: string;
|
||||||
|
size: number;
|
||||||
|
mime?: string;
|
||||||
|
path: string;
|
||||||
|
canUpload: boolean;
|
||||||
|
error?: any;
|
||||||
|
uri: string;
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { ISubscription, SubscriptionType, TSubscriptionModel } from '../definiti
|
||||||
import { ICannedResponse } from '../definitions/ICannedResponse';
|
import { ICannedResponse } from '../definitions/ICannedResponse';
|
||||||
import { TDataSelect } from '../definitions/IDataSelect';
|
import { TDataSelect } from '../definitions/IDataSelect';
|
||||||
import { ModalStackParamList } from './MasterDetailStack/types';
|
import { ModalStackParamList } from './MasterDetailStack/types';
|
||||||
|
import { TThreadModel } from '../definitions';
|
||||||
|
|
||||||
export type ChatsStackParamList = {
|
export type ChatsStackParamList = {
|
||||||
ModalStackNavigator: NavigatorScreenParams<ModalStackParamList>;
|
ModalStackNavigator: NavigatorScreenParams<ModalStackParamList>;
|
||||||
|
@ -246,7 +247,7 @@ export type InsideStackParamList = {
|
||||||
serverInfo: IServer;
|
serverInfo: IServer;
|
||||||
text: string;
|
text: string;
|
||||||
room: TSubscriptionModel;
|
room: TSubscriptionModel;
|
||||||
thread: any; // TODO: Change
|
thread: TThreadModel;
|
||||||
};
|
};
|
||||||
ModalBlockView: {
|
ModalBlockView: {
|
||||||
data: any; // TODO: Change;
|
data: any; // TODO: Change;
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
import { IAttachment } from '../views/ShareView/interfaces';
|
import { IShareAttachment } from '../definitions';
|
||||||
|
|
||||||
export const canUploadFile = (
|
export const canUploadFile = ({
|
||||||
file: IAttachment,
|
file,
|
||||||
allowList: string,
|
allowList,
|
||||||
maxFileSize: number,
|
maxFileSize,
|
||||||
permissionToUploadFile: boolean
|
permissionToUploadFile
|
||||||
): { success: boolean; error?: string } => {
|
}: {
|
||||||
|
file: IShareAttachment;
|
||||||
|
allowList?: string;
|
||||||
|
maxFileSize?: number;
|
||||||
|
permissionToUploadFile: boolean;
|
||||||
|
}): { success: boolean; error?: string } => {
|
||||||
if (!(file && file.path)) {
|
if (!(file && file.path)) {
|
||||||
return { success: true };
|
return { success: true };
|
||||||
}
|
}
|
||||||
if (maxFileSize > -1 && file.size > maxFileSize) {
|
if (maxFileSize && maxFileSize > -1 && file.size > maxFileSize) {
|
||||||
return { success: false, error: 'error-file-too-large' };
|
return { success: false, error: 'error-file-too-large' };
|
||||||
}
|
}
|
||||||
if (!permissionToUploadFile) {
|
if (!permissionToUploadFile) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { useTheme } from '../../theme';
|
||||||
import { isAndroid, isTablet } from '../../utils/deviceInfo';
|
import { isAndroid, isTablet } from '../../utils/deviceInfo';
|
||||||
import sharedStyles from '../Styles';
|
import sharedStyles from '../Styles';
|
||||||
import { makeThreadName } from '../../utils/room';
|
import { makeThreadName } from '../../utils/room';
|
||||||
import { ISubscription } from '../../definitions';
|
import { ISubscription, TThreadModel } from '../../definitions';
|
||||||
import { getRoomTitle, isGroupChat } from '../../lib/methods';
|
import { getRoomTitle, isGroupChat } from '../../lib/methods';
|
||||||
|
|
||||||
const androidMarginLeft = isTablet ? 0 : 4;
|
const androidMarginLeft = isTablet ? 0 : 4;
|
||||||
|
@ -37,7 +37,7 @@ const styles = StyleSheet.create({
|
||||||
|
|
||||||
interface IHeader {
|
interface IHeader {
|
||||||
room: ISubscription;
|
room: ISubscription;
|
||||||
thread: { id?: string };
|
thread: TThreadModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Header = React.memo(({ room, thread }: IHeader) => {
|
const Header = React.memo(({ room, thread }: IHeader) => {
|
||||||
|
|
|
@ -12,10 +12,10 @@ import sharedStyles from '../Styles';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import { isAndroid } from '../../utils/deviceInfo';
|
import { isAndroid } from '../../utils/deviceInfo';
|
||||||
import { allowPreview } from './utils';
|
import { allowPreview } from './utils';
|
||||||
import { IAttachment, IUseDimensions } from './interfaces';
|
|
||||||
import { THUMBS_HEIGHT } from './constants';
|
import { THUMBS_HEIGHT } from './constants';
|
||||||
import { TSupportedThemes } from '../../theme';
|
import { TSupportedThemes } from '../../theme';
|
||||||
import { themes } from '../../lib/constants';
|
import { themes } from '../../lib/constants';
|
||||||
|
import { IShareAttachment } from '../../definitions';
|
||||||
|
|
||||||
const MESSAGEBOX_HEIGHT = 56;
|
const MESSAGEBOX_HEIGHT = 56;
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ const IconPreview = React.memo(({ iconName, title, description, theme, width, he
|
||||||
));
|
));
|
||||||
|
|
||||||
interface IPreview {
|
interface IPreview {
|
||||||
item: IAttachment;
|
item: IShareAttachment;
|
||||||
theme: TSupportedThemes;
|
theme: TSupportedThemes;
|
||||||
isShareExtension: boolean;
|
isShareExtension: boolean;
|
||||||
length: number;
|
length: number;
|
||||||
|
@ -65,7 +65,7 @@ interface IPreview {
|
||||||
|
|
||||||
const Preview = React.memo(({ item, theme, isShareExtension, length }: IPreview) => {
|
const Preview = React.memo(({ item, theme, isShareExtension, length }: IPreview) => {
|
||||||
const type = item?.mime;
|
const type = item?.mime;
|
||||||
const { width, height } = useDimensions() as IUseDimensions;
|
const { width, height } = useDimensions();
|
||||||
const { isLandscape } = useOrientation();
|
const { isLandscape } = useOrientation();
|
||||||
const insets = useSafeAreaInsets();
|
const insets = useSafeAreaInsets();
|
||||||
const headerHeight = getHeaderHeight(isLandscape);
|
const headerHeight = getHeaderHeight(isLandscape);
|
||||||
|
|
|
@ -8,8 +8,8 @@ import { CustomIcon } from '../../containers/CustomIcon';
|
||||||
import { isIOS } from '../../utils/deviceInfo';
|
import { isIOS } from '../../utils/deviceInfo';
|
||||||
import { THUMBS_HEIGHT } from './constants';
|
import { THUMBS_HEIGHT } from './constants';
|
||||||
import { allowPreview } from './utils';
|
import { allowPreview } from './utils';
|
||||||
import { IAttachment } from './interfaces';
|
|
||||||
import { TSupportedThemes } from '../../theme';
|
import { TSupportedThemes } from '../../theme';
|
||||||
|
import { IShareAttachment } from '../../definitions';
|
||||||
|
|
||||||
const THUMB_SIZE = 64;
|
const THUMB_SIZE = 64;
|
||||||
|
|
||||||
|
@ -62,18 +62,18 @@ const styles = StyleSheet.create({
|
||||||
});
|
});
|
||||||
|
|
||||||
interface IThumbContent {
|
interface IThumbContent {
|
||||||
item: IAttachment;
|
item: IShareAttachment;
|
||||||
theme: TSupportedThemes;
|
theme: TSupportedThemes;
|
||||||
isShareExtension: boolean;
|
isShareExtension: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IThumb extends IThumbContent {
|
interface IThumb extends IThumbContent {
|
||||||
onPress(item: IAttachment): void;
|
onPress(item: IShareAttachment): void;
|
||||||
onRemove(item: IAttachment): void;
|
onRemove(item: IShareAttachment): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IThumbs extends Omit<IThumb, 'item'> {
|
interface IThumbs extends Omit<IThumb, 'item'> {
|
||||||
attachments: IAttachment[];
|
attachments: IShareAttachment[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const ThumbContent = React.memo(({ item, theme, isShareExtension }: IThumbContent) => {
|
const ThumbContent = React.memo(({ item, theme, isShareExtension }: IThumbContent) => {
|
||||||
|
|
|
@ -26,20 +26,19 @@ import Thumbs from './Thumbs';
|
||||||
import Preview from './Preview';
|
import Preview from './Preview';
|
||||||
import Header from './Header';
|
import Header from './Header';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import { IAttachment } from './interfaces';
|
import { IApplicationState, IServer, IShareAttachment, IUser, TSubscriptionModel, TThreadModel } from '../../definitions';
|
||||||
import { IUser, TSubscriptionModel } from '../../definitions';
|
|
||||||
import { hasPermission, sendFileMessage, sendMessage } from '../../lib/methods';
|
import { hasPermission, sendFileMessage, sendMessage } from '../../lib/methods';
|
||||||
|
|
||||||
interface IShareViewState {
|
interface IShareViewState {
|
||||||
selected: IAttachment;
|
selected: IShareAttachment;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
readOnly: boolean;
|
readOnly: boolean;
|
||||||
attachments: IAttachment[];
|
attachments: IShareAttachment[];
|
||||||
text: string;
|
text: string;
|
||||||
room: TSubscriptionModel;
|
room: TSubscriptionModel;
|
||||||
thread: any; // change
|
thread: TThreadModel;
|
||||||
maxFileSize: number;
|
maxFileSize?: number;
|
||||||
mediaAllowList: string;
|
mediaAllowList?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IShareViewProps {
|
interface IShareViewProps {
|
||||||
|
@ -65,7 +64,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
||||||
private messagebox: React.RefObject<IMessageBoxShareView>;
|
private messagebox: React.RefObject<IMessageBoxShareView>;
|
||||||
private files: any[];
|
private files: any[];
|
||||||
private isShareExtension: boolean;
|
private isShareExtension: boolean;
|
||||||
private serverInfo: any;
|
private serverInfo: IServer;
|
||||||
|
|
||||||
constructor(props: IShareViewProps) {
|
constructor(props: IShareViewProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -75,7 +74,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
||||||
this.serverInfo = props.route.params?.serverInfo ?? {};
|
this.serverInfo = props.route.params?.serverInfo ?? {};
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
selected: {} as IAttachment,
|
selected: {} as IShareAttachment,
|
||||||
loading: false,
|
loading: false,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
attachments: [],
|
attachments: [],
|
||||||
|
@ -163,7 +162,12 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
||||||
const items = await Promise.all(
|
const items = await Promise.all(
|
||||||
this.files.map(async item => {
|
this.files.map(async item => {
|
||||||
// Check server settings
|
// Check server settings
|
||||||
const { success: canUpload, error } = canUploadFile(item, mediaAllowList, maxFileSize, permissionToUploadFile);
|
const { success: canUpload, error } = canUploadFile({
|
||||||
|
file: item,
|
||||||
|
allowList: mediaAllowList,
|
||||||
|
maxFileSize,
|
||||||
|
permissionToUploadFile
|
||||||
|
});
|
||||||
item.canUpload = canUpload;
|
item.canUpload = canUpload;
|
||||||
item.error = error;
|
item.error = error;
|
||||||
|
|
||||||
|
@ -230,7 +234,6 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
||||||
},
|
},
|
||||||
thread?.id,
|
thread?.id,
|
||||||
server,
|
server,
|
||||||
// @ts-ignore
|
|
||||||
{ id: user.id, token: user.token }
|
{ id: user.id, token: user.token }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -252,7 +255,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
selectFile = (item: IAttachment) => {
|
selectFile = (item: IShareAttachment) => {
|
||||||
const { attachments, selected } = this.state;
|
const { attachments, selected } = this.state;
|
||||||
if (attachments.length > 0) {
|
if (attachments.length > 0) {
|
||||||
const text = this.messagebox.current?.text;
|
const text = this.messagebox.current?.text;
|
||||||
|
@ -266,7 +269,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
removeFile = (item: IAttachment) => {
|
removeFile = (item: IShareAttachment) => {
|
||||||
const { selected, attachments } = this.state;
|
const { selected, attachments } = this.state;
|
||||||
let newSelected;
|
let newSelected;
|
||||||
if (item.path === selected.path) {
|
if (item.path === selected.path) {
|
||||||
|
@ -367,11 +370,11 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state: any) => ({
|
const mapStateToProps = (state: IApplicationState) => ({
|
||||||
user: getUserSelector(state),
|
user: getUserSelector(state),
|
||||||
server: state.share.server.server || state.server.server,
|
server: state.share.server.server || state.server.server,
|
||||||
FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList,
|
FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList as string,
|
||||||
FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize
|
FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize as number
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withTheme(ShareView));
|
export default connect(mapStateToProps)(withTheme(ShareView));
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
export interface IAttachment {
|
|
||||||
filename: string;
|
|
||||||
description?: string;
|
|
||||||
size: number;
|
|
||||||
mime?: string;
|
|
||||||
path: string;
|
|
||||||
canUpload: boolean;
|
|
||||||
error?: any;
|
|
||||||
uri: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IUseDimensions {
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
}
|
|
Loading…
Reference in New Issue