File size: 1,786 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
// @flow
import React from 'react';
import { Link } from 'react-router-dom';
import type { Props } from './';
import compose from 'recompose/compose';
import { Loading } from 'src/components/loading';
import { Container, LinkWrapper, AvatarWrapper, Column } from './style';
import Activity from 'src/components/inboxThread/activity';
import { ThreadTitle } from 'src/components/inboxThread/style';
import { UserAvatar } from 'src/components/avatar';
import { withCurrentUser } from 'src/components/withCurrentUser';
import getThreadLink from 'src/helpers/get-thread-link';

class Attachment extends React.Component<Props> {
  render() {
    const { data, currentUser, id } = this.props;
    const { thread, loading, error } = data;

    if (loading)
      return (
        <div className="attachment-container">
          <Container style={{ padding: '16px 12px' }}>
            <Loading />
          </Container>
        </div>
      );

    if (error || !thread)
      return (
        <Link to={`/thread/${id}`}>https://spectrum.chat/thread/{id}</Link>
      );

    return (
      <div className="attachment-container">
        <Container data-cy="thread-attachment">
          <LinkWrapper
            onClick={e => e.stopPropagation()}
            to={{ pathname: getThreadLink(thread), state: { modal: true } }}
          />
          <AvatarWrapper>
            <UserAvatar user={thread.author.user} size={32} />
          </AvatarWrapper>
          <Column>
            <ThreadTitle>{thread.content.title}</ThreadTitle>
            <Activity
              currentUser={currentUser}
              thread={thread}
              active={false}
            />
          </Column>
        </Container>
      </div>
    );
  }
}

export default compose(withCurrentUser)(Attachment);