2018-03-23 16:49:51 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { FlatList, Text, View } from 'react-native';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2018-04-03 16:24:59 +00:00
|
|
|
import LoggedView from '../View';
|
2018-03-23 16:49:51 +00:00
|
|
|
import { openSnippetedMessages, closeSnippetedMessages } from '../../actions/snippetedMessages';
|
|
|
|
import styles from './styles';
|
|
|
|
import Message from '../../containers/message';
|
|
|
|
|
2018-04-03 16:24:59 +00:00
|
|
|
const renderItem = ({ item }) => (
|
|
|
|
<Message
|
|
|
|
item={item}
|
|
|
|
style={styles.message}
|
|
|
|
reactions={item.reactions}
|
|
|
|
user={this.props.user}
|
|
|
|
baseUrl={this.props.baseUrl}
|
|
|
|
Message_TimeFormat='MMMM Do YYYY, h:mm:ss a'
|
|
|
|
onLongPress={() => {}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2018-03-23 16:49:51 +00:00
|
|
|
@connect(
|
|
|
|
state => ({
|
|
|
|
messages: state.snippetedMessages.messages,
|
|
|
|
user: state.login.user,
|
|
|
|
baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
|
|
|
|
}),
|
|
|
|
dispatch => ({
|
|
|
|
openSnippetedMessages: rid => dispatch(openSnippetedMessages(rid)),
|
|
|
|
closeSnippetedMessages: () => dispatch(closeSnippetedMessages())
|
|
|
|
})
|
|
|
|
)
|
2018-04-03 16:24:59 +00:00
|
|
|
export default class SnippetedMessagesView extends LoggedView {
|
2018-03-23 16:49:51 +00:00
|
|
|
static propTypes = {
|
|
|
|
navigation: PropTypes.object,
|
|
|
|
messages: PropTypes.array,
|
|
|
|
user: PropTypes.object,
|
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
openSnippetedMessages: PropTypes.func,
|
|
|
|
closeSnippetedMessages: PropTypes.func
|
|
|
|
}
|
|
|
|
|
2018-04-03 16:24:59 +00:00
|
|
|
constructor(props) {
|
|
|
|
super('SnippetedMessagesView', props);
|
|
|
|
}
|
|
|
|
|
2018-03-23 16:49:51 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.openSnippetedMessages(this.props.navigation.state.params.rid);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.props.closeSnippetedMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
renderEmpty = () => (
|
|
|
|
<View style={styles.listEmptyContainer}>
|
|
|
|
<Text>No snippet messages</Text>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (this.props.messages.length === 0) {
|
|
|
|
return this.renderEmpty();
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<FlatList
|
|
|
|
key='snippet-messages-view-list'
|
|
|
|
data={this.props.messages}
|
2018-04-03 16:24:59 +00:00
|
|
|
renderItem={renderItem}
|
2018-03-23 16:49:51 +00:00
|
|
|
style={styles.list}
|
|
|
|
keyExtractor={item => item._id}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|