File size: 3,127 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
112
113
114
115
116
117
118
119
120
121
// @flow
import React, { useState, useEffect } from 'react';
import compose from 'recompose/compose';
import { connect } from 'react-redux';
import type { Dispatch } from 'redux';
import { withRouter, type Location } from 'react-router-dom';
import type { UserInfoType } from 'shared/graphql/fragments/user/userInfo';
import type { CommunityInfoType } from 'shared/graphql/fragments/community/communityInfo';
import generateMetaInfo from 'shared/generate-meta-info';
import { withCurrentUser } from 'src/components/withCurrentUser';
import Head from 'src/components/head';
import { CommunityAvatar } from 'src/components/avatar';
import { setTitlebarProps } from 'src/actions/titlebar';
import { CommunityFeeds } from '../components/communityFeeds';
import {
  ViewGrid,
  SecondaryPrimaryColumnGrid,
  PrimaryColumn,
  SecondaryColumn,
} from 'src/components/layout';
import Sidebar from 'src/components/communitySidebar';
import { FullScreenRedirectView } from 'src/views/viewHelpers/fullScreenRedirect';

type Props = {
  community: CommunityInfoType,
  currentUser: ?UserInfoType,
  dispatch: Dispatch<Object>,
  location: Location,
};

const Component = (props: Props) => {
  const { community, dispatch, location } = props;

  const [metaInfo, setMetaInfo] = useState(
    generateMetaInfo({
      type: 'community',
      data: {
        name: community.name,
        description: community.description,
      },
    })
  );

  useEffect(() => {
    setMetaInfo(
      generateMetaInfo({
        type: 'community',
        data: {
          name: `${community.name} community`,
          description: community.description,
        },
      })
    );
    dispatch(
      setTitlebarProps({
        title: community.name,
        titleIcon: (
          <CommunityAvatar
            isClickable={false}
            community={community}
            size={24}
          />
        ),
      })
    );
  }, [community.id]);

  useEffect(() => {
    dispatch(
      setTitlebarProps({
        title: community.name,
        titleIcon: (
          <CommunityAvatar
            isClickable={false}
            community={community}
            size={24}
          />
        ),
      })
    );
  }, [location]);

  const { title, description } = metaInfo;

  if (community.redirect && community.website) {
    return <FullScreenRedirectView community={community} />;
  }

  return (
    <React.Fragment>
      <Head
        title={title}
        description={description}
        image={community.profilePhoto}
      >
        {community.redirect && community.noindex && (
          <meta name="robots" content="noindex, nofollow" />
        )}
      </Head>

      <ViewGrid data-cy="community-view">
        <SecondaryPrimaryColumnGrid>
          <SecondaryColumn>
            <Sidebar community={community} />
          </SecondaryColumn>

          <PrimaryColumn>
            <CommunityFeeds community={community} />
          </PrimaryColumn>
        </SecondaryPrimaryColumnGrid>
      </ViewGrid>
    </React.Fragment>
  );
};

export const SignedIn = compose(
  withCurrentUser,
  withRouter,
  connect()
)(Component);