This repository has been archived by the owner on Feb 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCard.tsx
81 lines (77 loc) · 1.94 KB
/
Card.tsx
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
import * as React from 'react';
import { gql, graphql } from 'react-apollo';
import { Helmet } from 'react-helmet';
import * as remark from 'remark';
import * as html from 'remark-html';
import { Card as ICard } from '../../server/schema';
interface Props {
data: {
card: ICard;
networkStatus: number;
};
match: {
params: {
id: string;
};
};
}
const cardDataFromId = gql`
query getCardById($id: String!) {
card(id: $id) {
id
title
authors {
name
}
created
updates
content
}
}
`;
const config = {
options: ({ match }) => ({ variables: { id: match.params.id } }),
};
@graphql(cardDataFromId, config)
export default class Card extends React.PureComponent<Props, {}> {
render() {
const { card, networkStatus } = this.props.data;
if (networkStatus < 7) {
return <div>Loading...</div>;
}
const lastUpdate = card.updates
? new Date(card.updates[0]).toLocaleDateString('en-US', {
timeZone: 'UTC',
})
: new Date(card.created).toLocaleDateString('en-US', {
timeZone: 'UTC',
});
return (
<article role="article">
<Helmet>
<script type="application/ld+json">{JSON.stringify({ headline: card.title })}</script>
</Helmet>
<h1>{card.title}</h1>
<div className="card">
<div className="card__meta">
<div>
<strong>{card.authors.length > 1 ? 'Authors: ' : 'Author: '}</strong>
{card.authors.map(author => author.name).join(', ')}
</div>
<div>
<strong>Updated:</strong> {lastUpdate}
</div>
</div>
<div
className="card__content"
dangerouslySetInnerHTML={{
__html: remark()
.use(html)
.processSync(card.content).contents,
}}
/>
</div>
</article>
);
}
}