-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathArtistEditorialNewsGrid.tsx
More file actions
322 lines (292 loc) · 9.1 KB
/
ArtistEditorialNewsGrid.tsx
File metadata and controls
322 lines (292 loc) · 9.1 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import {
ActionType,
type ClickedArticleGroup,
ContextModule,
OwnerType,
} from "@artsy/cohesion"
import {
Column,
Image,
Skeleton,
SkeletonBox,
SkeletonText,
Text,
} from "@artsy/palette"
import { GridColumns, ResponsiveBox } from "@artsy/palette"
import {
CellArticleFragmentContainer,
CellArticlePlaceholder,
} from "Components/Cells/CellArticle"
import { EmptyState } from "Components/EmptyState"
import { Masonry } from "Components/Masonry"
import { RouterLink } from "System/Components/RouterLink"
import { useAnalyticsContext } from "System/Hooks/useAnalyticsContext"
import { useSystemContext } from "System/Hooks/useSystemContext"
import { SystemQueryRenderer } from "System/Relay/SystemQueryRenderer"
import { Media } from "Utils/Responsive"
import { extractNodes } from "Utils/extractNodes"
import type { ArtistEditorialNewsGridQuery } from "__generated__/ArtistEditorialNewsGridQuery.graphql"
import type { ArtistEditorialNewsGrid_artist$data } from "__generated__/ArtistEditorialNewsGrid_artist.graphql"
import { take } from "lodash"
import type { FC } from "react"
import { createFragmentContainer, graphql } from "react-relay"
import { useTracking } from "react-tracking"
const ARTICLE_COUNT = 6
interface ArtistEditorialNewsGridProps {
artist: ArtistEditorialNewsGrid_artist$data
// diamond_editorial-section
showEmptyStateWhenNoArticles?: boolean
}
const ArtistEditorialNewsGrid: FC<
React.PropsWithChildren<ArtistEditorialNewsGridProps>
> = ({
artist,
// diamond_editorial-section
showEmptyStateWhenNoArticles = false,
}) => {
const { trackEvent } = useTracking()
const { contextPageOwnerId, contextPageOwnerSlug, contextPageOwnerType } =
useAnalyticsContext()
const articles = extractNodes(artist.articlesConnection)
const viewAllHref = `${artist.href}/articles`
if (articles.length === 0) {
// diamond_editorial-section
if (showEmptyStateWhenNoArticles) {
return (
<EmptyState
title="There are currently no editorial pieces about this artist."
description="Check back soon — we’ll add coverage as it becomes available. In the meantime, browse art world stories and features on Artsy."
action={{
label: "Browse Artsy Editorial",
href: "/articles",
}}
/>
)
}
return null
}
const [firstArticle, ...restOfArticles] = articles
const truncatedRestOfArticles = take(restOfArticles, ARTICLE_COUNT)
const firstImage = firstArticle.thumbnailImage?.large
return (
<GridColumns gridRowGap={4}>
<Column
span={12}
display="flex"
justifyContent="space-between"
alignItems="center"
>
<Text as="h3" variant="lg-display">
Artsy Editorial Featuring {artist.name}
</Text>
<Text
variant="sm-display"
flexShrink={0}
as={RouterLink}
to={viewAllHref}
onClick={() => {
const trackingEvent: ClickedArticleGroup = {
action: ActionType.clickedArticleGroup,
context_module: ContextModule.marketNews,
context_page_owner_type: contextPageOwnerType!,
context_page_owner_id: contextPageOwnerId,
context_page_owner_slug: contextPageOwnerSlug,
destination_page_owner_type: OwnerType.articles,
type: "viewAll",
}
trackEvent(trackingEvent)
}}
>
View All
</Text>
</Column>
<Column span={[12, 6]} mb={[4, 0]}>
<RouterLink
key={firstArticle.internalID}
to={firstArticle.href}
display="block"
textDecoration="none"
onClick={() => {
const trackingEvent: ClickedArticleGroup = {
action: ActionType.clickedArticleGroup,
context_module: ContextModule.marketNews,
context_page_owner_type: contextPageOwnerType!,
context_page_owner_id: contextPageOwnerId,
context_page_owner_slug: contextPageOwnerSlug,
destination_page_owner_type: OwnerType.article,
type: "thumbnail",
}
trackEvent(trackingEvent)
}}
>
{firstImage && (
<ResponsiveBox
aspectWidth={firstImage.width}
aspectHeight={firstImage.height}
maxWidth="100%"
bg="mono10"
>
<Image
src={firstImage.src}
srcSet={firstImage.srcSet}
width="100%"
height="100%"
lazyLoad
/>
</ResponsiveBox>
)}
<Text variant="xs" fontWeight="bold" mt={1}>
{firstArticle.vertical}
</Text>
<Text variant="xl" mt={0.5}>
{firstArticle.title}
</Text>
<Text variant="lg-display" mt={1}>
By {firstArticle.byline}
</Text>
<Text variant="lg-display" color="mono60" mt={0.5}>
{firstArticle.publishedAt}
</Text>
</RouterLink>
</Column>
<Column span={[12, 6]}>
<Masonry columnCount={2}>
{truncatedRestOfArticles.map(article => {
return (
<CellArticleFragmentContainer
key={article.internalID}
article={article}
mode="GRID"
mb={4}
onClick={() => {
const trackingEvent: ClickedArticleGroup = {
action: ActionType.clickedArticleGroup,
context_module: ContextModule.marketNews,
context_page_owner_type: contextPageOwnerType!,
context_page_owner_id: contextPageOwnerId,
context_page_owner_slug: contextPageOwnerSlug,
destination_page_owner_type: OwnerType.article,
type: "thumbnail",
}
trackEvent(trackingEvent)
}}
/>
)
})}
</Masonry>
</Column>
</GridColumns>
)
}
export const ArtistEditorialNewsGridFragmentContainer = createFragmentContainer(
ArtistEditorialNewsGrid,
{
artist: graphql`
fragment ArtistEditorialNewsGrid_artist on Artist {
internalID
name
slug
href
articlesConnection(first: 6, sort: PUBLISHED_AT_DESC) {
edges {
node {
...CellArticle_article
internalID
href
byline
slug
title
publishedAt(format: "MMM D, YYYY")
vertical
thumbnailTitle
thumbnailImage {
large: cropped(width: 670, height: 720) {
width
height
src
srcSet
}
}
}
}
}
}
`,
},
)
const PLACEHOLDER = (
<Skeleton>
<GridColumns>
<Column span={[12, 6]} mb={[4, 0]}>
<Media greaterThan="xs">
<ResponsiveBox aspectWidth={670} aspectHeight={720} maxWidth="100%">
<SkeletonBox width="100%" height="100%" />
</ResponsiveBox>
<SkeletonText variant="xs" fontWeight="bold" mt={1}>
Art Fairs
</SkeletonText>
<SkeletonText variant="xl" mt={0.5}>
Essential Tips for Collecting Work by Anni and Josef Albers
</SkeletonText>
<SkeletonText variant="lg-display" mt={1}>
By Artsy Editorial
</SkeletonText>
<SkeletonText variant="lg-display" mt={0.5}>
Jan 1, 2000
</SkeletonText>
</Media>
</Column>
<Column span={[12, 6]}>
<Masonry columnCount={2}>
{[...new Array(ARTICLE_COUNT)].map((_, i) => {
return <CellArticlePlaceholder key={i} mode="GRID" mb={4} />
})}
</Masonry>
</Column>
</GridColumns>
</Skeleton>
)
export const ArtistEditorialNewsGridQueryRenderer: FC<
React.PropsWithChildren<{
id: string
// diamond_editorial-section
showEmptyStateWhenNoArticles?: boolean
}>
> = ({
id,
// diamond_editorial-section
showEmptyStateWhenNoArticles = false,
}) => {
const { relayEnvironment } = useSystemContext()
return (
<SystemQueryRenderer<ArtistEditorialNewsGridQuery>
lazyLoad
environment={relayEnvironment}
variables={{ id }}
placeholder={PLACEHOLDER}
query={graphql`
query ArtistEditorialNewsGridQuery($id: String!) {
artist(id: $id) {
...ArtistEditorialNewsGrid_artist
}
}
`}
render={({ error, props }) => {
if (error) {
console.error(error)
return null
}
if (!props || !props.artist) {
return PLACEHOLDER
}
return (
<ArtistEditorialNewsGridFragmentContainer
artist={props.artist}
// diamond_editorial-section
showEmptyStateWhenNoArticles={showEmptyStateWhenNoArticles}
/>
)
}}
/>
)
}