Fixes an issue with channel intro not displaying (#667)

This commit is contained in:
Chris Duarte 2017-06-26 12:57:55 -07:00 committed by enahum
parent 8d72c0a020
commit 0b6d2628ed
4 changed files with 29 additions and 27 deletions

View file

@ -19,9 +19,9 @@ import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
class ChannelIntro extends PureComponent {
static propTypes = {
creator: PropTypes.object,
currentChannel: PropTypes.object.isRequired,
currentChannelMembers: PropTypes.array.isRequired,
currentUser: PropTypes.object.isRequired,
intl: intlShape.isRequired,
navigator: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired
@ -86,7 +86,7 @@ class ChannelIntro extends PureComponent {
const {currentChannelMembers, theme} = this.props;
const style = getStyleSheet(theme);
const names = currentChannelMembers.map((member, index) => (
return currentChannelMembers.map((member, index) => (
<TouchableOpacity
key={member.id}
onPress={() => preventDoubleTap(this.goToUserProfile, this, member.id)}
@ -96,8 +96,6 @@ class ChannelIntro extends PureComponent {
</Text>
</TouchableOpacity>
));
return <View style={{flexDirection: 'row'}}>{names}</View>;
};
buildDMContent = () => {
@ -132,7 +130,7 @@ class ChannelIntro extends PureComponent {
};
buildOpenChannelContent = () => {
const {currentChannel, currentChannelMembers, currentUser, intl, theme} = this.props;
const {creator, currentChannel, intl, theme} = this.props;
const style = getStyleSheet(theme);
const date = intl.formatDate(currentChannel.create_at, {
@ -142,8 +140,7 @@ class ChannelIntro extends PureComponent {
});
let mainMessageIntl;
if (currentChannel.creator_id) {
const creator = currentChannel.creator_id === currentUser.id ? currentUser : currentChannelMembers[currentChannel.creator_id];
if (creator) {
const creatorName = this.getDisplayName(creator);
mainMessageIntl = {
id: 'intro_messages.creator',
@ -201,10 +198,9 @@ class ChannelIntro extends PureComponent {
};
buildPrivateChannelContent = () => {
const {currentChannel, currentChannelMembers, currentUser, intl, theme} = this.props;
const {creator, currentChannel, intl, theme} = this.props;
const style = getStyleSheet(theme);
const creator = currentChannel.creator_id === currentUser.id ? currentUser : currentChannelMembers[currentChannel.creator_id];
const creatorName = this.getDisplayName(creator);
const date = intl.formatDate(currentChannel.create_at, {
year: 'numeric',
@ -352,14 +348,19 @@ const getStyleSheet = makeStyleSheetFromTheme((theme) => {
lineHeight: 18
},
namesContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
marginBottom: 12
},
profile: {
height: 67,
marginBottom: 12,
marginRight: 12
},
profilesContainer: {
flexDirection: 'row',
marginBottom: 12
flexWrap: 'wrap',
justifyContent: 'flex-start'
}
});
});

View file

@ -19,16 +19,17 @@ function mapStateToProps(state) {
if (currentChannel.type === General.DM_CHANNEL) {
const otherChannelMember = currentChannel.name.split('__').find((m) => m !== currentUser.id);
currentChannelMembers.push(state.entities.users.profiles[otherChannelMember]);
} else {
currentChannelMembers = getProfilesInCurrentChannel(state);
currentChannelMembers = currentChannelMembers.filter((m) => m.id !== currentUser.id);
}
if (currentChannel.type === General.GM_CHANNEL) {
currentChannelMembers = getProfilesInCurrentChannel(state);
}
const creator = currentChannel.creator_id === currentUser.id ? currentUser : state.entities.users.profiles[currentChannel.creator_id];
return {
creator,
currentChannel,
currentChannelMembers,
currentUser,
theme: getTheme(state)
};
}

View file

@ -82,16 +82,9 @@ export default class PostList extends PureComponent {
};
renderChannelIntro = () => {
const {channel, channelIsLoading, navigator, posts} = this.props;
// Check the webapp for atEnd, and replace it here
if (channel.hasOwnProperty('id')) {
const firstPostHasRendered = channel.total_msg_count ? posts.length > 0 : true;
const messageCount = channel.total_msg_count - posts.length;
if (channelIsLoading || !firstPostHasRendered || messageCount > 0) {
return null;
}
const {channel, channelIsLoading, navigator, refreshing, showLoadMore} = this.props;
if (channel.hasOwnProperty('id') && !showLoadMore && !refreshing && !channelIsLoading) {
return (
<View>
<ChannelIntro navigator={navigator}/>
@ -122,7 +115,7 @@ export default class PostList extends PureComponent {
/>
);
}
if (item === LOAD_MORE_POSTS) {
if (item === LOAD_MORE_POSTS && this.props.showLoadMore) {
return (
<LoadMorePosts
loading={this.props.isLoadingMore}

View file

@ -70,6 +70,11 @@ class ChannelPostList extends PureComponent {
// Load the posts when the channel actually changes
this.loadPosts(nextProps.channel.id);
}
const showLoadMore = nextProps.posts.length === this.props.posts.length && nextProps.posts.length > nextProps.postVisibility;
this.setState({
showLoadMore
});
}
channelLoaded = () => {
@ -119,8 +124,10 @@ class ChannelPostList extends PureComponent {
};
loadMorePosts = () => {
const {actions, channel} = this.props;
actions.increasePostVisibility(channel.id);
if (this.state.showLoadMore) {
const {actions, channel} = this.props;
actions.increasePostVisibility(channel.id);
}
};
loadPosts = async (channelId) => {
@ -162,7 +169,7 @@ class ChannelPostList extends PureComponent {
posts={posts.slice(0, postVisibility)}
loadMore={this.loadMorePosts}
isLoadingMore={loadingPosts}
showLoadMore={(channel.total_msg_count - posts.length) > 0}
showLoadMore={this.state.showLoadMore}
onPostPress={this.goToThread}
renderReplies={true}
indicateNewMessages={true}