Skip to content

Commit 67540e0

Browse files
Merge pull request #43 from detroitledger/jm-org-news
Add news to org page
2 parents a7a1e7b + 281fb46 commit 67540e0

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

src/components/OrgNewsArticles.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,48 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import moment from 'moment';
4-
import { Grid, Row, Col } from 'react-bootstrap';
4+
import { Row, Col } from 'react-bootstrap';
55

6-
const OrgNewsArticles = ({ newses }) => {
6+
const OrgNewsArticles = ({ newses, limit }) => {
77
if (!newses || newses.length === 0) return null;
88

99
return (
10-
<Grid>
11-
<h4>News</h4>
10+
<div className="news">
11+
<h2>News</h2>
1212
<Row
1313
style={{
14-
overflowX: 'hidden',
15-
overflowY: 'scroll',
16-
maxHeight: '300px',
1714
display: 'flex',
1815
flexWrap: 'wrap',
1916
}}
2017
>
21-
{newses.map((news, i) => (
18+
{newses.slice(0,limit).map((news) => (
2219
<Col
2320
xs={12}
2421
sm={4}
2522
md={3}
26-
key={i}
23+
key={news.uuid}
2724
style={{
2825
display: 'flex',
2926
flexDirection: 'column',
3027
}}
3128
>
32-
<h5>
29+
<h4>
3330
<a href={news.link} rel="nofollow">
3431
{news.title}
3532
</a>
36-
</h5>
33+
</h4>
3734
<time>
38-
{moment(news.date, 'ddd, DD MMM YYYY HH:mm:ss ZZ').format(
35+
{moment(news.date).format(
3936
'MMM D, YYYY'
4037
)}
4138
</time>
4239
<p className="newsdesc">
43-
{news.desc.substring(0, 90).replace(/\w+$/, '…')}
40+
{news.description.substring(0, 90).replace(/\w+$/, '…')}
4441
</p>
4542
</Col>
4643
))}
4744
</Row>
48-
</Grid>
45+
</div>
4946
);
5047
};
5148

src/containers/Organizations.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ const GET_ORGANIZATION = gql`
6060
uuid
6161
name
6262
}
63+
news {
64+
uuid
65+
title
66+
date
67+
description
68+
link
69+
}
6370
}
6471
}
6572
`;
@@ -98,12 +105,16 @@ const Organization = () => {
98105
// We default to funded if there are any
99106
const [grantSide, setGrantSide] = useState(false);
100107

108+
// Show up to 4 news articles by default
109+
const defaultNewsLimit = 4
110+
const [newsLimit, setNewsLimit] = useState(defaultNewsLimit);
111+
101112
if (loading) return 'Loading...';
102113
if (error) return `Error! ${error}`;
103114

104115
if (!data.organization) return `Oof!`;
105116

106-
const { name, description, ein, nteeOrganizationTypes } = data.organization;
117+
const { name, description, ein, nteeOrganizationTypes, news } = data.organization;
107118

108119
const {
109120
grantsFunded,
@@ -132,7 +143,13 @@ const Organization = () => {
132143
</Col>
133144
</Row>
134145

135-
<OrgNewsArticles newses={/*organization.ledgerNewsArticles*/ []} />
146+
{news && <OrgNewsArticles newses={news} limit={newsLimit} />}
147+
{news.length > defaultNewsLimit ?
148+
<button onClick={(news) => setNewsLimit(newsLimit === defaultNewsLimit ? news.length : defaultNewsLimit)}>
149+
{newsLimit === defaultNewsLimit ? `Show more news` : `Show less news`}
150+
</button>
151+
: ``}
152+
136153
{forms990 && <OrgFinances forms990={forms990} />}
137154

138155
<h2>Grant Data</h2>

0 commit comments

Comments
 (0)