bigbuffet-rw/app/soapbox/features/chats/components/chat_list.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-08-24 19:26:42 -07:00
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
2020-08-25 14:00:27 -07:00
import { injectIntl } from 'react-intl';
2020-08-24 19:26:42 -07:00
import ImmutablePureComponent from 'react-immutable-pure-component';
import { fetchChats } from 'soapbox/actions/chats';
2020-08-25 09:33:51 -07:00
import ChatListAccount from './chat_list_account';
2020-08-25 10:38:21 -07:00
import { makeGetChat } from 'soapbox/selectors';
2020-08-24 19:26:42 -07:00
2020-08-25 10:38:21 -07:00
const mapStateToProps = state => {
const getChat = makeGetChat();
return {
2020-08-27 12:02:52 -07:00
chats: state.get('chats').map(chat => getChat(state, chat.toJS())).toList(),
2020-08-25 10:38:21 -07:00
};
};
2020-08-24 19:26:42 -07:00
export default @connect(mapStateToProps)
@injectIntl
class ChatList extends ImmutablePureComponent {
static propTypes = {
dispatch: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
2020-08-25 15:24:47 -07:00
onClickChat: PropTypes.func,
2020-08-27 12:02:52 -07:00
emptyMessage: PropTypes.node,
2020-08-24 19:26:42 -07:00
};
componentDidMount() {
this.props.dispatch(fetchChats());
}
render() {
2020-08-27 12:02:52 -07:00
const { chats, emptyMessage } = this.props;
2020-08-24 19:26:42 -07:00
return (
<div className='chat-list'>
<div className='chat-list__content'>
2020-08-27 12:02:52 -07:00
{chats.count() === 0 &&
<div className='empty-column-indicator'>{emptyMessage}</div>
}
{chats.map(chat => (
2020-08-25 10:38:21 -07:00
<div key={chat.get('id')} className='chat-list-item'>
2020-08-25 09:33:51 -07:00
<ChatListAccount
2020-08-25 15:24:47 -07:00
chat={chat}
onClick={this.props.onClickChat}
2020-08-25 09:33:51 -07:00
/>
2020-08-24 19:26:42 -07:00
</div>
))}
</div>
</div>
);
}
}