MessagesContainer.ts 987 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { connect } from 'react-redux';
  2. import { ClusterName, RootState, TopicName } from 'redux/interfaces';
  3. import { RouteComponentProps, withRouter } from 'react-router-dom';
  4. import { fetchTopicMessages } from 'redux/actions';
  5. import {
  6. getIsTopicMessagesFetched,
  7. getTopicMessages,
  8. } from 'redux/reducers/topics/selectors';
  9. import Messages from './Messages';
  10. interface RouteProps {
  11. clusterName: ClusterName;
  12. topicName: TopicName;
  13. }
  14. type OwnProps = RouteComponentProps<RouteProps>;
  15. const mapStateToProps = (
  16. state: RootState,
  17. {
  18. match: {
  19. params: { topicName, clusterName },
  20. },
  21. }: OwnProps
  22. ) => ({
  23. clusterName,
  24. topicName,
  25. isFetched: getIsTopicMessagesFetched(state),
  26. messages: getTopicMessages(state),
  27. });
  28. const mapDispatchToProps = {
  29. fetchTopicMessages: (clusterName: ClusterName, topicName: TopicName) =>
  30. fetchTopicMessages(clusterName, topicName),
  31. };
  32. export default withRouter(
  33. connect(mapStateToProps, mapDispatchToProps)(Messages)
  34. );