File size: 2,706 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// @flow
import * as React from 'react';
import { Link } from 'react-router-dom';
import Badge from 'src/components/badges';
import { UserAvatar, CommunityAvatar } from 'src/components/avatar';
import type { CommunityInfoType } from 'shared/graphql/fragments/community/communityInfo';
import ChannelComponent from './channel';
import {
  Wrapper,
  Col,
  Row,
  Heading,
  Meta,
  Description,
  ActionContainer,
} from './style';

type CommunityProps = {
  community: CommunityInfoType,
  showDescription?: boolean,
  showMeta?: boolean,
  meta?: any,
  children?: any,
  showHoverProfile?: boolean,
};

export class CommunityListItem extends React.Component<CommunityProps> {
  render() {
    const { community, showDescription, children } = this.props;

    return (
      <Wrapper>
        <Row>
          <CommunityAvatar
            community={community}
            size={32}
            showHoverProfile={false}
            isClickable={false}
          />
          <Col style={{ marginLeft: '12px' }}>
            <Heading>{community.name}</Heading>
          </Col>
          <ActionContainer className={'action'}>{children}</ActionContainer>
        </Row>
        {showDescription && <Description>{community.description}</Description>}
      </Wrapper>
    );
  }
}

type CardProps = {
  isClickable?: boolean,
  contents: any,
  meta?: string,
  children?: any,
};

export const ThreadListItem = (props: CardProps): React$Element<any> => {
  return (
    <Wrapper isClickable={props.isClickable}>
      <Row>
        <Col>
          <Heading>{props.contents.content.title}</Heading>
          <Meta>{props.meta}</Meta>
        </Col>
      </Row>
    </Wrapper>
  );
};

export const UserListItem = ({
  user,
  children,
  hideRep = false,
}: Object): React$Element<any> => {
  const role =
    user.contextPermissions && user.contextPermissions.isOwner
      ? 'Admin'
      : user.contextPermissions && user.contextPermissions.isModerator
      ? 'Moderator'
      : null;

  return (
    <Wrapper border>
      <Row>
        <UserAvatar user={user} size={40} />
        <Col
          style={{
            marginLeft: '16px',
            display: 'flex',
            justifyContent: 'center',
            flexDirection: 'column',
          }}
        >
          <Heading>
            {user.username ? (
              <Link to={`/users/${user.username}`}>{user.name}</Link>
            ) : (
              <span>{user.name}</span>
            )}
            {role && <Badge type={role} />}
          </Heading>
        </Col>
        <ActionContainer className={'action'}>{children}</ActionContainer>
      </Row>
    </Wrapper>
  );
};

export const ChannelListItem = ChannelComponent;