-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathArtistsIndex.tsx
More file actions
184 lines (165 loc) · 5.54 KB
/
ArtistsIndex.tsx
File metadata and controls
184 lines (165 loc) · 5.54 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
import {
Box,
Breadcrumbs,
Column,
GridColumns,
Join,
Shelf,
Spacer,
Text,
} from "@artsy/palette"
import { ArtistsCarouselCellFragmentContainer } from "Apps/Artists/Components/ArtistsCarouselCell"
import { ArtistsIndexMeta } from "Apps/Artists/Components/ArtistsIndexMeta"
import { ArtistsLetterNav } from "Apps/Artists/Components/ArtistsLetterNav"
import { CellArtistFragmentContainer } from "Components/Cells/CellArtist"
import { RouterLink } from "System/Components/RouterLink"
import { Media } from "Utils/Responsive"
import { getENV } from "Utils/getENV"
import type { ArtistsIndex_featuredArtists$data } from "__generated__/ArtistsIndex_featuredArtists.graphql"
import type { ArtistsIndex_featuredGenes$data } from "__generated__/ArtistsIndex_featuredGenes.graphql"
import compact from "lodash/compact"
import type * as React from "react"
import { createFragmentContainer, graphql } from "react-relay"
interface ArtistsIndexProps {
featuredArtists: ArtistsIndex_featuredArtists$data | null
featuredGenes: ArtistsIndex_featuredGenes$data | null
}
export const ArtistsIndex: React.FC<
React.PropsWithChildren<ArtistsIndexProps>
> = ({ featuredArtists, featuredGenes }) => {
const [featuredArtistsSet] = featuredArtists ?? []
const [featuredGenesSet] = featuredGenes ?? []
const headline = featuredArtistsSet?.name ?? "Artists"
const artists = compact(featuredArtistsSet?.artists) ?? []
const genes = compact(featuredGenesSet?.genes) ?? []
const isMobile = getENV("IS_MOBILE")
return (
<>
<ArtistsIndexMeta />
<Spacer y={4} />
<Join separator={<Spacer y={6} />}>
<GridColumns gridRowGap={[2, 0]}>
<Column span={6}>
<Text as="h1" variant="xl" mb={1}>
{headline}
</Text>
<Breadcrumbs>
<RouterLink to="">Browse over 100,000 artists</RouterLink>
</Breadcrumbs>
</Column>
<Column span={6}>
<ArtistsLetterNav />
</Column>
</GridColumns>
{artists.length > 0 && (
<Media greaterThan="xs">
<Shelf>
{artists.map((featuredLink, index) => {
if (!featuredLink?.internalID) return <></>
return (
<ArtistsCarouselCellFragmentContainer
key={featuredLink.internalID}
featuredLink={featuredLink}
index={index}
// Improves LCP for above the fold content
lazyLoad={isMobile ? true : false}
/>
)
})}
</Shelf>
</Media>
)}
{genes.length > 0 && (
<Join separator={<Spacer y={6} />}>
{genes.map((gene, geneIndex) => {
if (
!gene ||
!gene.trendingArtists ||
gene.trendingArtists.length === 0
) {
return null
}
return (
<Box key={gene.name ?? geneIndex}>
<Box display="flex" justifyContent="space-between">
<RouterLink
to={gene.href}
textDecoration="none"
display="block"
>
<Text variant="lg-display" as="h2" lineClamp={2}>
{gene.name}
</Text>
</RouterLink>
<Spacer x={2} />
<RouterLink
to={gene.href}
textDecoration="none"
display="block"
>
<Text variant="sm-display" color="mono60">
View
</Text>
</RouterLink>
</Box>
<Spacer y={2} />
<GridColumns gridRowGap={4}>
{gene.trendingArtists.map((artist, artistsIndex) => {
if (!artist) return null
return (
<Column key={artist.internalID} span={[12, 6, 3, 3]}>
<CellArtistFragmentContainer
mode="GRID"
artist={artist}
// LCP above the fold optimization for mobile
lazyLoad={
isMobile && geneIndex === 0 && artistsIndex === 0
? false
: true
}
/>
</Column>
)
})}
</GridColumns>
</Box>
)
})}
</Join>
)}
</Join>
</>
)
}
export const ArtistsIndexFragmentContainer = createFragmentContainer(
ArtistsIndex,
{
featuredArtists: graphql`
fragment ArtistsIndex_featuredArtists on OrderedSet @relay(plural: true) {
name
artists: items {
... on FeaturedLink {
internalID
}
...ArtistsCarouselCell_featuredLink
}
}
`,
featuredGenes: graphql`
fragment ArtistsIndex_featuredGenes on OrderedSet @relay(plural: true) {
name
genes: items {
... on Gene {
internalID
name
href
trendingArtists(sample: 4) {
...CellArtist_artist
internalID
}
}
}
}
`,
},
)