2019-07-18 17:44:02 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import {
|
2019-12-04 16:39:53 +00:00
|
|
|
View, Text, FlatList, Keyboard, BackHandler
|
2019-07-18 17:44:02 +00:00
|
|
|
} from 'react-native';
|
|
|
|
import ShareExtension from 'rn-extensions-share';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import RNFetchBlob from 'rn-fetch-blob';
|
|
|
|
import * as mime from 'react-native-mime-types';
|
2019-09-16 20:26:32 +00:00
|
|
|
import { isEqual, orderBy } from 'lodash';
|
|
|
|
import { Q } from '@nozbe/watermelondb';
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
import database from '../../lib/database';
|
2020-06-15 14:00:46 +00:00
|
|
|
import { isIOS } from '../../utils/deviceInfo';
|
2019-07-18 17:44:02 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
|
|
|
import log from '../../utils/log';
|
2019-07-29 18:26:18 +00:00
|
|
|
import { canUploadFile } from '../../utils/media';
|
2019-07-18 17:44:02 +00:00
|
|
|
import DirectoryItem, { ROW_HEIGHT } from '../../presentation/DirectoryItem';
|
2019-07-29 16:33:28 +00:00
|
|
|
import ServerItem from '../../presentation/ServerItem';
|
2020-03-30 20:19:01 +00:00
|
|
|
import { CancelModalButton, CustomHeaderButtons, Item } from '../../containers/HeaderButton';
|
2019-07-18 17:44:02 +00:00
|
|
|
import ShareListHeader from './Header';
|
2019-12-04 16:39:53 +00:00
|
|
|
import ActivityIndicator from '../../containers/ActivityIndicator';
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
import styles from './styles';
|
2019-07-29 16:33:28 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2019-09-19 13:32:24 +00:00
|
|
|
import { animateNextTransition } from '../../utils/layoutAnimation';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { withTheme } from '../../theme';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
const LIMIT = 50;
|
|
|
|
const getItemLayout = (data, index) => ({ length: ROW_HEIGHT, offset: ROW_HEIGHT * index, index });
|
2019-07-18 17:44:02 +00:00
|
|
|
const keyExtractor = item => item.rid;
|
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class ShareListView extends React.Component {
|
2019-07-18 17:44:02 +00:00
|
|
|
static propTypes = {
|
|
|
|
navigation: PropTypes.object,
|
|
|
|
server: PropTypes.string,
|
|
|
|
token: PropTypes.string,
|
2019-12-04 16:39:53 +00:00
|
|
|
userId: PropTypes.string,
|
|
|
|
theme: PropTypes.string
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.data = [];
|
|
|
|
this.state = {
|
2019-07-29 16:33:28 +00:00
|
|
|
showError: false,
|
2019-07-18 17:44:02 +00:00
|
|
|
searching: false,
|
2019-07-29 16:33:28 +00:00
|
|
|
searchText: '',
|
2019-07-18 17:44:02 +00:00
|
|
|
value: '',
|
|
|
|
isMedia: false,
|
|
|
|
mediaLoading: false,
|
|
|
|
fileInfo: null,
|
2019-07-29 16:33:28 +00:00
|
|
|
searchResults: [],
|
2019-07-18 17:44:02 +00:00
|
|
|
chats: [],
|
2019-07-29 16:33:28 +00:00
|
|
|
servers: [],
|
|
|
|
loading: true,
|
|
|
|
serverInfo: null
|
2019-07-18 17:44:02 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
|
|
|
this.unsubscribeFocus = props.navigation.addListener('focus', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress));
|
|
|
|
this.unsubscribeBlur = props.navigation.addListener('blur', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress));
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 16:41:40 +00:00
|
|
|
componentDidMount() {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { server } = this.props;
|
2020-02-05 16:41:40 +00:00
|
|
|
setTimeout(async() => {
|
|
|
|
try {
|
|
|
|
const { value, type } = await ShareExtension.data();
|
|
|
|
let fileInfo = null;
|
|
|
|
const isMedia = (type === 'media');
|
|
|
|
if (isMedia) {
|
|
|
|
this.setState({ mediaLoading: true });
|
|
|
|
const data = await RNFetchBlob.fs.stat(this.uriToPath(value));
|
|
|
|
fileInfo = {
|
|
|
|
name: data.filename,
|
|
|
|
description: '',
|
|
|
|
size: data.size,
|
|
|
|
mime: mime.lookup(data.path),
|
|
|
|
path: isIOS ? data.path : `file://${ data.path }`
|
|
|
|
};
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
value, fileInfo, isMedia, mediaLoading: false
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
this.setState({ mediaLoading: false });
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
2019-07-29 16:33:28 +00:00
|
|
|
|
2020-02-05 16:41:40 +00:00
|
|
|
this.getSubscriptions(server);
|
|
|
|
}, 500);
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 16:37:49 +00:00
|
|
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
2019-07-29 16:33:28 +00:00
|
|
|
const { server } = this.props;
|
|
|
|
if (nextProps.server !== server) {
|
|
|
|
this.getSubscriptions(nextProps.server);
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
2019-07-29 16:33:28 +00:00
|
|
|
const { searching } = this.state;
|
|
|
|
if (nextState.searching !== searching) {
|
2019-07-18 17:44:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-07-29 16:33:28 +00:00
|
|
|
|
|
|
|
const { isMedia } = this.state;
|
|
|
|
if (nextState.isMedia !== isMedia) {
|
|
|
|
this.getSubscriptions(nextProps.server, nextState.fileInfo);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
const { server, theme } = this.props;
|
2019-07-29 16:33:28 +00:00
|
|
|
if (server !== nextProps.server) {
|
2019-07-18 17:44:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-12-04 16:39:53 +00:00
|
|
|
if (theme !== nextProps.theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
const { searchResults } = this.state;
|
|
|
|
if (!isEqual(nextState.searchResults, searchResults)) {
|
2019-07-18 17:44:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.unsubscribeFocus) {
|
|
|
|
this.unsubscribeFocus();
|
|
|
|
}
|
|
|
|
if (this.unsubscribeBlur) {
|
|
|
|
this.unsubscribeBlur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setHeader = () => {
|
|
|
|
const { searching } = this.state;
|
|
|
|
const { navigation, theme } = this.props;
|
|
|
|
|
|
|
|
if (isIOS) {
|
|
|
|
navigation.setOptions({
|
|
|
|
header: () => (
|
|
|
|
<ShareListHeader
|
|
|
|
searching={searching}
|
|
|
|
initSearch={this.initSearch}
|
|
|
|
cancelSearch={this.cancelSearch}
|
|
|
|
search={this.search}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
navigation.setOptions({
|
|
|
|
headerLeft: () => (searching
|
|
|
|
? (
|
|
|
|
<CustomHeaderButtons left>
|
|
|
|
<Item title='cancel' iconName='Cross' onPress={this.cancelSearch} />
|
|
|
|
</CustomHeaderButtons>
|
|
|
|
)
|
|
|
|
: (
|
|
|
|
<CancelModalButton
|
|
|
|
onPress={ShareExtension.close}
|
|
|
|
testID='share-extension-close'
|
|
|
|
/>
|
|
|
|
)),
|
|
|
|
headerTitle: () => <ShareListHeader searching={searching} search={this.search} theme={theme} />,
|
|
|
|
headerRight: () => (
|
|
|
|
searching
|
|
|
|
? null
|
|
|
|
: (
|
|
|
|
<CustomHeaderButtons>
|
|
|
|
<Item title='search' iconName='magnifier' onPress={this.initSearch} />
|
|
|
|
</CustomHeaderButtons>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:44:02 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
|
|
|
internalSetState = (...args) => {
|
|
|
|
const { navigation } = this.props;
|
2019-09-19 13:32:24 +00:00
|
|
|
if (navigation.isFocused()) {
|
|
|
|
animateNextTransition();
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
this.setState(...args);
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
getSubscriptions = async(server, fileInfo) => {
|
2019-07-29 18:26:18 +00:00
|
|
|
const { fileInfo: fileData } = this.state;
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
|
|
|
const serversDB = database.servers;
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
if (server) {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.data = await db.collections
|
|
|
|
.get('subscriptions')
|
|
|
|
.query(
|
|
|
|
Q.where('archived', false),
|
|
|
|
Q.where('open', true)
|
|
|
|
).fetch();
|
|
|
|
this.data = orderBy(this.data, ['roomUpdatedAt'], ['desc']);
|
|
|
|
|
|
|
|
const serversCollection = serversDB.collections.get('servers');
|
|
|
|
this.servers = await serversCollection.query().fetch();
|
2019-07-29 16:33:28 +00:00
|
|
|
this.chats = this.data.slice(0, LIMIT);
|
2019-10-08 12:36:15 +00:00
|
|
|
let serverInfo = {};
|
|
|
|
try {
|
|
|
|
serverInfo = await serversCollection.find(server);
|
|
|
|
} catch (error) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2019-09-24 20:16:59 +00:00
|
|
|
const canUploadFileResult = canUploadFile(fileInfo || fileData, serverInfo);
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
this.internalSetState({
|
|
|
|
chats: this.chats ? this.chats.slice() : [],
|
|
|
|
servers: this.servers ? this.servers.slice() : [],
|
2019-07-29 16:33:28 +00:00
|
|
|
loading: false,
|
2019-09-24 20:16:59 +00:00
|
|
|
showError: !canUploadFileResult.success,
|
|
|
|
error: canUploadFileResult.error,
|
2019-07-29 16:33:28 +00:00
|
|
|
serverInfo
|
2019-07-18 17:44:02 +00:00
|
|
|
});
|
|
|
|
this.forceUpdate();
|
2019-07-29 16:33:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
uriToPath = uri => decodeURIComponent(isIOS ? uri.replace(/^file:\/\//, '') : uri);
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
getRoomTitle = (item) => {
|
2019-07-29 16:33:28 +00:00
|
|
|
const { serverInfo } = this.state;
|
|
|
|
const { useRealName } = serverInfo;
|
2019-07-18 17:44:02 +00:00
|
|
|
return ((item.prid || useRealName) && item.fname) || item.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
shareMessage = (item) => {
|
|
|
|
const { value, isMedia, fileInfo } = this.state;
|
|
|
|
const { navigation } = this.props;
|
|
|
|
|
|
|
|
navigation.navigate('ShareView', {
|
|
|
|
rid: item.rid,
|
|
|
|
value,
|
|
|
|
isMedia,
|
|
|
|
fileInfo,
|
|
|
|
name: this.getRoomTitle(item)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
search = (text) => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const result = this.data.filter(item => item.name.includes(text)) || [];
|
2019-07-18 17:44:02 +00:00
|
|
|
this.internalSetState({
|
2019-07-29 16:33:28 +00:00
|
|
|
searchResults: result.slice(0, LIMIT),
|
|
|
|
searchText: text
|
2019-07-18 17:44:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
initSearch = () => {
|
|
|
|
const { chats } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setState({ searching: true, searchResults: chats }, () => this.setHeader());
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
cancelSearch = () => {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.internalSetState({ searching: false, searchResults: [], searchText: '' }, () => this.setHeader());
|
2019-07-29 16:33:28 +00:00
|
|
|
Keyboard.dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleBackPress = () => {
|
|
|
|
const { searching } = this.state;
|
|
|
|
if (searching) {
|
|
|
|
this.cancelSearch();
|
|
|
|
return true;
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
2019-07-29 16:33:28 +00:00
|
|
|
return false;
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderSectionHeader = (header) => {
|
|
|
|
const { searching } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2019-07-29 16:33:28 +00:00
|
|
|
if (searching) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
return (
|
2019-12-04 16:39:53 +00:00
|
|
|
<View style={[styles.headerContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
|
|
|
<Text style={[styles.headerText, { color: themes[theme].titleText }]}>
|
2019-07-29 16:33:28 +00:00
|
|
|
{I18n.t(header)}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
renderItem = ({ item }) => {
|
2019-12-04 16:39:53 +00:00
|
|
|
const {
|
2020-02-11 14:09:14 +00:00
|
|
|
userId, token, server, theme
|
2019-12-04 16:39:53 +00:00
|
|
|
} = this.props;
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
|
|
|
<DirectoryItem
|
|
|
|
user={{
|
2019-10-29 18:14:41 +00:00
|
|
|
id: userId,
|
2019-07-18 17:44:02 +00:00
|
|
|
token
|
|
|
|
}}
|
|
|
|
title={this.getRoomTitle(item)}
|
2020-02-11 14:09:14 +00:00
|
|
|
baseUrl={server}
|
2019-07-18 17:44:02 +00:00
|
|
|
avatar={this.getRoomTitle(item)}
|
|
|
|
description={
|
|
|
|
item.t === 'c'
|
|
|
|
? (item.topic || item.description)
|
|
|
|
: item.fname
|
|
|
|
}
|
|
|
|
type={item.t}
|
|
|
|
onPress={() => this.shareMessage(item)}
|
|
|
|
testID={`share-extension-item-${ item.name }`}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-07-18 17:44:02 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderSeparator = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return <View style={[styles.separator, { borderColor: themes[theme].separatorColor }]} />;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderBorderBottom = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return <View style={[styles.borderBottom, { borderColor: themes[theme].separatorColor }]} />;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderSelectServer = () => {
|
2019-07-18 17:44:02 +00:00
|
|
|
const { servers } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { server, theme, navigation } = this.props;
|
2019-07-18 17:44:02 +00:00
|
|
|
const currentServer = servers.find(serverFiltered => serverFiltered.id === server);
|
|
|
|
return currentServer ? (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-07-18 17:44:02 +00:00
|
|
|
{this.renderSectionHeader('Select_Server')}
|
2019-12-04 16:39:53 +00:00
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.bordered,
|
|
|
|
{
|
|
|
|
borderColor: themes[theme].separatorColor,
|
|
|
|
backgroundColor: themes[theme].auxiliaryBackground
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
>
|
2019-07-18 17:44:02 +00:00
|
|
|
<ServerItem
|
|
|
|
server={server}
|
2020-06-15 14:00:46 +00:00
|
|
|
onPress={() => navigation.navigate('SelectServerView', { servers: this.servers })}
|
2019-07-18 17:44:02 +00:00
|
|
|
item={currentServer}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-07-18 17:44:02 +00:00
|
|
|
/>
|
|
|
|
</View>
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-07-18 17:44:02 +00:00
|
|
|
) : null;
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderEmptyComponent = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return (
|
|
|
|
<View style={[styles.container, styles.emptyContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
|
|
|
<Text style={[styles.title, { color: themes[theme].titleText }]}>{I18n.t('No_results_found')}</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderHeader = () => {
|
|
|
|
const { searching } = this.state;
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-07-29 16:33:28 +00:00
|
|
|
{ !searching
|
|
|
|
? (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-07-29 16:33:28 +00:00
|
|
|
{this.renderSelectServer()}
|
|
|
|
{this.renderSectionHeader('Chats')}
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-07-29 16:33:28 +00:00
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-07-18 17:44:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
renderContent = () => {
|
|
|
|
const {
|
|
|
|
chats, mediaLoading, loading, searchResults, searching, searchText
|
|
|
|
} = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
if (mediaLoading || loading) {
|
2019-12-04 16:39:53 +00:00
|
|
|
return <ActivityIndicator theme={theme} />;
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-07-29 16:33:28 +00:00
|
|
|
<FlatList
|
|
|
|
data={searching ? searchResults : chats}
|
|
|
|
keyExtractor={keyExtractor}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.flatlist, { backgroundColor: themes[theme].auxiliaryBackground }]}
|
|
|
|
contentContainerStyle={{ backgroundColor: themes[theme].backgroundColor }}
|
2019-07-29 16:33:28 +00:00
|
|
|
renderItem={this.renderItem}
|
|
|
|
getItemLayout={getItemLayout}
|
|
|
|
ItemSeparatorComponent={this.renderSeparator}
|
|
|
|
ListHeaderComponent={this.renderHeader}
|
|
|
|
ListFooterComponent={!searching && this.renderBorderBottom}
|
2019-12-04 16:39:53 +00:00
|
|
|
ListHeaderComponentStyle={!searching ? { ...styles.borderBottom, borderColor: themes[theme].separatorColor } : {}}
|
2019-07-29 16:33:28 +00:00
|
|
|
ListEmptyComponent={searching && searchText ? this.renderEmptyComponent : null}
|
|
|
|
enableEmptySections
|
|
|
|
removeClippedSubviews
|
2019-07-18 17:44:02 +00:00
|
|
|
keyboardShouldPersistTaps='always'
|
2019-07-29 16:33:28 +00:00
|
|
|
initialNumToRender={12}
|
|
|
|
windowSize={20}
|
|
|
|
/>
|
2019-07-18 17:44:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderError = () => {
|
2019-07-29 16:33:28 +00:00
|
|
|
const {
|
2019-09-24 20:16:59 +00:00
|
|
|
fileInfo: file, loading, searching, error
|
2019-07-29 16:33:28 +00:00
|
|
|
} = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2019-07-29 16:33:28 +00:00
|
|
|
|
|
|
|
if (loading) {
|
2019-12-04 16:39:53 +00:00
|
|
|
return <ActivityIndicator theme={theme} />;
|
2019-07-29 16:33:28 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
2019-12-04 16:39:53 +00:00
|
|
|
<View style={[styles.container, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
2019-07-29 16:33:28 +00:00
|
|
|
{ !searching
|
|
|
|
? (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-07-29 16:33:28 +00:00
|
|
|
{this.renderSelectServer()}
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-07-29 16:33:28 +00:00
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
2019-12-04 16:39:53 +00:00
|
|
|
<View style={[styles.container, styles.centered, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
|
|
|
<Text style={[styles.title, { color: themes[theme].titleText }]}>{I18n.t(error)}</Text>
|
2020-06-05 13:28:58 +00:00
|
|
|
<CustomIcon name='cancel' size={120} color={themes[theme].dangerColor} />
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.fileMime, { color: themes[theme].titleText }]}>{ file.mime }</Text>
|
2019-07-29 16:33:28 +00:00
|
|
|
</View>
|
2019-07-18 17:44:02 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-07-29 16:33:28 +00:00
|
|
|
const { showError } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
2020-06-15 14:00:46 +00:00
|
|
|
<SafeAreaView theme={theme}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<StatusBar theme={theme} />
|
2019-07-29 16:33:28 +00:00
|
|
|
{ showError ? this.renderError() : this.renderContent() }
|
2019-07-18 17:44:02 +00:00
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = (({ share }) => ({
|
|
|
|
userId: share.user && share.user.id,
|
|
|
|
token: share.user && share.user.token,
|
2020-02-11 14:09:14 +00:00
|
|
|
server: share.server
|
2019-08-07 13:51:34 +00:00
|
|
|
}));
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(ShareListView));
|