File size: 1,745 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// @flow
import * as React from 'react';
import { withRouter } from 'react-router';
import compose from 'recompose/compose';
import { Link } from 'react-router-dom';
import { connect } from 'react-redux';
import getThreadLink from 'src/helpers/get-thread-link';
import { ThreadListItem } from '../listItems';
import { ThreadProfileCard } from './style';
import type { GetThreadType } from 'shared/graphql/queries/thread/getThread';

type Props = {
  data: {
    thread: GetThreadType,
    error: ?string,
  },
  setName: Function,
  markAsDeleted: Function,
  id: string,
  children: any,
};

class ThreadWithData extends React.Component<Props> {
  componentDidMount() {
    const {
      data: { thread },
      data,
      setName,
      markAsDeleted,
      id,
    } = this.props;

    if (setName && thread) {
      setName(thread.community.name);
    }

    // if the query finished loading but no thread was returned,
    // clear this notification out
    if (data.networkStatus === 7 && !data.thread && markAsDeleted) {
      markAsDeleted(id);
    }
  }

  render() {
    const {
      data: { thread, error },
    } = this.props;
    if (error || !thread) {
      return null;
    }

    return (
      <ThreadProfileCard>
        <Link
          to={{
            pathname: getThreadLink(thread),
            state: {
              modal: true,
            },
          }}
        >
          <ThreadListItem
            contents={thread}
            withDescription={false}
            meta={`${thread.messageCount} message${
              thread.messageCount === 1 ? '' : 's'
            }`}
          />
        </Link>
      </ThreadProfileCard>
    );
  }
}

export default compose(
  connect(),
  withRouter
)(ThreadWithData);