2017-08-15 19:28:46 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import Meteor from 'react-native-meteor';
|
2017-08-18 21:30:16 +00:00
|
|
|
import { connect } from 'react-redux';
|
2017-08-15 19:28:46 +00:00
|
|
|
import { CachedImage } from 'react-native-img-cache';
|
2017-09-21 17:08:00 +00:00
|
|
|
import { Text, TouchableOpacity, View } from 'react-native';
|
2017-08-15 19:28:46 +00:00
|
|
|
import {
|
|
|
|
Card,
|
|
|
|
CardImage,
|
|
|
|
// CardTitle,
|
|
|
|
CardContent
|
|
|
|
// CardAction
|
|
|
|
} from 'react-native-card-view';
|
|
|
|
import RocketChat from '../../lib/rocketchat';
|
|
|
|
|
2017-09-21 17:08:00 +00:00
|
|
|
import PhotoModal from './PhotoModal';
|
2017-08-15 19:28:46 +00:00
|
|
|
|
2017-08-18 14:50:20 +00:00
|
|
|
|
2017-08-18 21:30:16 +00:00
|
|
|
@connect(state => ({
|
|
|
|
base: state.settings.Site_Url,
|
|
|
|
canShowList: state.login.token.length || state.login.user.token
|
|
|
|
}))
|
2017-08-15 19:28:46 +00:00
|
|
|
export default class Cards extends React.PureComponent {
|
|
|
|
static propTypes = {
|
2017-08-22 01:24:41 +00:00
|
|
|
data: PropTypes.object.isRequired,
|
|
|
|
base: PropTypes.string
|
2017-08-15 19:28:46 +00:00
|
|
|
}
|
2017-09-01 19:17:53 +00:00
|
|
|
|
2017-08-15 19:28:46 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
const user = Meteor.user();
|
2017-09-21 17:08:00 +00:00
|
|
|
this.state = {
|
|
|
|
modalVisible: false
|
|
|
|
};
|
2017-08-15 19:28:46 +00:00
|
|
|
RocketChat.getUserToken().then((token) => {
|
2017-08-18 21:30:16 +00:00
|
|
|
this.setState({ img: `${ this.props.base }${ this.props.data.image_url }?rc_uid=${ user._id }&rc_token=${ token }` });
|
2017-08-15 19:28:46 +00:00
|
|
|
});
|
|
|
|
}
|
2017-09-01 19:17:53 +00:00
|
|
|
|
2017-11-23 19:12:18 +00:00
|
|
|
getDescription() {
|
|
|
|
if (this.props.data.description) {
|
|
|
|
return <Text style={{ alignSelf: 'center', fontWeight: 'bold' }}>{this.props.data.description}</Text>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 19:17:53 +00:00
|
|
|
getImage() {
|
|
|
|
return (
|
2017-09-21 17:08:00 +00:00
|
|
|
<View>
|
|
|
|
<TouchableOpacity onPress={() => this._onPressButton()}>
|
|
|
|
<Card>
|
|
|
|
<CardImage style={{ width: 256, height: 256 }}>
|
|
|
|
<CachedImage
|
|
|
|
style={{ width: 256, height: 256 }}
|
|
|
|
source={{ uri: encodeURI(this.state.img) }}
|
|
|
|
/>
|
|
|
|
</CardImage>
|
|
|
|
<CardContent>
|
|
|
|
<Text style={[{ fontSize: 12, alignSelf: 'center', fontStyle: 'italic' }]}>{this.props.data.title}</Text>
|
2017-11-23 19:12:18 +00:00
|
|
|
{this.getDescription()}
|
2017-09-21 17:08:00 +00:00
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
</TouchableOpacity>
|
|
|
|
<PhotoModal
|
|
|
|
title={this.props.data.title}
|
|
|
|
image={this.state.img}
|
|
|
|
isVisible={this.state.modalVisible}
|
|
|
|
onClose={() => this.setState({ modalVisible: false })}
|
|
|
|
/>
|
|
|
|
</View>
|
2017-09-01 19:17:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getOther() {
|
|
|
|
return (
|
|
|
|
<Text style={[{ fontSize: 12, alignSelf: 'center', fontStyle: 'italic' }]}>{this.props.data.title}</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-15 19:28:46 +00:00
|
|
|
_onPressButton() {
|
2017-09-21 17:08:00 +00:00
|
|
|
this.setState({
|
|
|
|
modalVisible: true
|
2017-08-15 19:28:46 +00:00
|
|
|
});
|
|
|
|
}
|
2017-09-01 19:17:53 +00:00
|
|
|
|
2017-08-15 19:28:46 +00:00
|
|
|
render() {
|
2017-09-01 19:17:53 +00:00
|
|
|
return this.state.img ? this.getImage() : this.getOther();
|
2017-08-15 19:28:46 +00:00
|
|
|
}
|
|
|
|
}
|