File size: 1,942 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
// @flow
import * as React from 'react';
import { connect } from 'react-redux';
import compose from 'recompose/compose';
import { Link } from 'react-router-dom';
import { truncate } from 'src/helpers/utils';
import { UserAvatar } from 'src/components/avatar';
import { convertTimestampToDate } from 'shared/time-formatting';
import type { GetThreadType } from 'shared/graphql/queries/thread/getThread';
import getThreadLink from 'src/helpers/get-thread-link';
import { useAppScroller } from 'src/hooks/useAppScroller';
import ActionsDropdown from './actionsDropdown';
import {
  StickyHeaderContent,
  CommunityHeaderName,
  CommunityHeaderMeta,
  CommunityHeaderSubtitle,
  CommunityHeaderMetaCol,
  StickyHeaderContainer,
  StickyHeaderActionsContainer,
} from '../style';

type Props = {
  thread: GetThreadType,
};

const StickyHeader = (props: Props) => {
  const { thread } = props;
  const { scrollToTop } = useAppScroller();
  const { channel } = thread;

  const createdAt = new Date(thread.createdAt).getTime();
  const timestamp = convertTimestampToDate(createdAt);

  return (
    <StickyHeaderContainer>
      <StickyHeaderContent onClick={scrollToTop}>
        <CommunityHeaderMeta>
          <UserAvatar showHoverProfile username={thread.author.user.username} />
          <CommunityHeaderMetaCol>
            <CommunityHeaderName>
              {truncate(thread.content.title, 80)}
            </CommunityHeaderName>
            <CommunityHeaderSubtitle>
              <Link to={getThreadLink(thread)}>{timestamp}</Link>
            </CommunityHeaderSubtitle>
          </CommunityHeaderMetaCol>
        </CommunityHeaderMeta>
      </StickyHeaderContent>

      {channel.channelPermissions.isMember && (
        <StickyHeaderActionsContainer>
          <ActionsDropdown thread={thread} />
        </StickyHeaderActionsContainer>
      )}
    </StickyHeaderContainer>
  );
};

export default compose(connect())(StickyHeader);