mattermost-mobile/app/components/post_list/post_list.js
Harrison Healey c28d64c8da #96/#112/PLT-5370/PLT-5372 Styling posts and channel view (#213)
* Updated post rendering in center channel to include dates, display names, themeing, profile pictures, and threads

* Added status to ProfilePicture component

* Changed MemberListRow to use a ProfilePicture

* Removed unused prop

* Fixed incorrect copyright year on new file

* Removed unnecessary ref
2017-02-02 13:53:42 -03:00

84 lines
2 KiB
JavaScript

// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import {ListView, StyleSheet} from 'react-native';
import Post from 'app/components/post';
import DateHeader from './date_header';
const style = StyleSheet.create({
container: {
transform: [{rotate: '180deg'}]
},
row: {
transform: [{rotate: '180deg'}]
}
});
export default class PostList extends React.Component {
static propTypes = {
posts: React.PropTypes.object.isRequired,
theme: React.PropTypes.object.isRequired
};
constructor(props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (a, b) => a !== b
}).cloneWithRows(this.props.posts)
};
}
componentWillReceiveProps(nextProps) {
this.setState({
dataSource: this.state.dataSource.cloneWithRowsAndSections(nextProps.posts)
});
}
renderRow = (row) => {
if (row instanceof Date) {
return this.renderDateHeader(row);
}
return this.renderPost(row);
}
renderDateHeader = (date) => {
return (
<DateHeader
theme={this.props.theme}
style={style.row}
date={date}
/>
);
}
renderPost = (post) => {
return (
<Post
style={style.row}
post={post}
isFirstReply={post.isFirstReply}
isLastReply={post.isLastReply}
commentedOnPost={post.commentedOnPost}
/>
);
};
render() {
return (
<ListView
style={style.container}
enableEmptySections={true}
dataSource={this.state.dataSource}
renderSectionHeader={this.renderSectionHeader}
renderRow={this.renderRow}
showsVerticalScrollIndicator={false}
/>
);
}
}