/
index.tsx
325 lines (309 loc) · 11.1 KB
/
index.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
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
323
324
325
import { useState } from 'react'
import Link from 'next/link'
import clsx from 'clsx'
import { Page } from 'web/components/layout/page'
import { Col } from 'web/components/layout/col'
import { useSaveReferral } from 'web/hooks/use-save-referral'
import { Row } from 'web/components/layout/row'
import { TestimonialsPanel } from 'web/components/testimonials-panel'
import { firebaseLogin } from 'web/lib/firebase/users'
import { Button } from 'web/components/buttons/button'
import { redirectIfLoggedIn } from 'web/lib/firebase/server-auth'
import { AboutPrivacyTerms } from 'web/components/privacy-terms'
import { useRedirectIfSignedIn } from 'web/hooks/use-redirect-if-signed-in'
import { ManifoldLogo } from 'web/components/nav/manifold-logo'
import { LogoSEO } from 'web/components/LogoSEO'
import { MobileAppsQRCodeDialog } from 'web/components/buttons/mobile-apps-qr-code-button'
import { useSaveCampaign } from 'web/hooks/use-save-campaign'
import { FeedContractCard } from 'web/components/contract/feed-contract-card'
import { Contract } from 'common/contract'
import { db } from 'web/lib/supabase/db'
import { HIDE_FROM_NEW_USER_SLUGS } from 'common/envs/constants'
import { useUser } from 'web/hooks/use-user'
import { some } from 'd3-array'
import { getContract } from 'web/lib/supabase/contracts'
import { useABTest } from 'web/hooks/use-ab-test'
import { Typewriter } from 'web/components/home/typewriter'
import { PillButton } from 'web/components/buttons/pill-button'
import { Carousel } from 'web/components/widgets/carousel'
import { removeEmojis } from 'common/topics'
import { filterDefined } from 'common/util/array'
export const getServerSideProps = redirectIfLoggedIn('/home', async (_) => {
const { data } = await db
.from('contracts')
.select('data')
.not(
'outcome_type',
'in',
`(${['STONK', 'BOUNTIED_QUESTION', 'POLL'].join(',')})`
)
.order('importance_score', { ascending: false })
.limit(100)
const contracts = (data ?? []).map((d) => d.data) as Contract[]
const prezContract = await getContract('ikSUiiNS8MwAI75RwEJf')
const filteredContracts = contracts.filter(
(c) =>
!c.groupSlugs?.some((slug) =>
HIDE_FROM_NEW_USER_SLUGS.includes(slug as any)
)
)
const hasCommonGroupSlug = (contract: Contract, groupSlugsSet: string[]) =>
some(contract.groupSlugs ?? [], (slug) => groupSlugsSet.includes(slug))
const addedGroupSlugs: string[] = ['us-politics']
const uniqueContracts: Contract[] = filterDefined([prezContract])
filteredContracts.forEach((contract) => {
if (!hasCommonGroupSlug(contract, addedGroupSlugs)) {
uniqueContracts.push(contract)
addedGroupSlugs.push(...(contract.groupSlugs ?? []))
}
})
const topicSlugs = [
'us-politics',
'technology-default',
'ai',
'entertainment',
'sports-default',
'science-default',
]
const topicSlugToContracts: Record<string, Contract[]> = {}
topicSlugs.forEach((slug) => {
topicSlugToContracts[slug] = filteredContracts
.filter((c) => (c.groupSlugs ?? []).includes(slug))
.slice(0, 7)
})
const { data: topicData } = await db
.from('groups')
.select('name,slug')
.in('slug', topicSlugs)
// Order topics by topicSlugs order
const topics = (topicData ?? []).sort(
(a, b) => topicSlugs.indexOf(a.slug) - topicSlugs.indexOf(b.slug)
)
return {
props: {
trendingContracts: uniqueContracts.slice(0, 7),
topicSlugToContracts,
topics,
},
}
})
export default function LandingPage(props: {
trendingContracts: Contract[]
topicSlugToContracts: Record<string, Contract[]>
topics: { name: string; slug: string }[]
}) {
const { trendingContracts, topicSlugToContracts, topics } = props
const user = useUser()
useSaveReferral(user)
useSaveCampaign()
useRedirectIfSignedIn()
const [selectedTopicSlug, setSelectedTopicSlug] = useState<string>()
const [isModalOpen, setIsModalOpen] = useState(false)
const contracts = selectedTopicSlug
? topicSlugToContracts[selectedTopicSlug] ?? []
: trendingContracts
const abTestVariant = useABTest('signed out home page variations v0', [
'know the future',
'real-world impact',
'wisdom of the crowds',
'bet',
'bet-typewriter',
])
return (
<Page trackPageView={'signed out home page'} hideSidebar>
<Col className="mx-auto mb-8 w-full gap-8 px-4">
<Col className="gap-4">
<Row className="items-center justify-between">
<ManifoldLogo />
<LogoSEO />
<Row className="items-center gap-2">
<Link href="/about">
<Button color="gray-white" size="xs">
About
</Button>
</Link>
<Link href="/browse">
<Button
color="gray-white"
size="xs"
className="hidden whitespace-nowrap lg:flex"
>
Browse
</Button>
</Link>
<Link href="/politics" className="hidden lg:flex">
<Button
color="gray-white"
size="xs"
className="whitespace-nowrap"
>
US Politics
</Button>
</Link>
<Button
color="gray-white"
size="xs"
onClick={() => setIsModalOpen(true)}
className="hidden whitespace-nowrap lg:flex"
>
Get app
</Button>
<Button
color="gray-white"
size="xs"
onClick={firebaseLogin}
className="whitespace-nowrap"
>
Sign in
</Button>
<Button
color="indigo"
size="xs"
onClick={firebaseLogin}
className="hidden whitespace-nowrap lg:flex"
>
Sign up
</Button>
<MobileAppsQRCodeDialog
isModalOpen={isModalOpen}
setIsModalOpen={setIsModalOpen}
/>
</Row>
</Row>
<Row className="justify-between rounded-lg ">
<Col className="w-full gap-2 sm:max-w-lg">
{abTestVariant === 'know the future' && (
<>
<h1 className="mb-4 text-4xl">Know the future</h1>
<h1 className="text-lg">
Harness wisdom of the crowds to predict politics, pandemics,
tech breakthroughs & more with
<span className={'ml-1 underline'}>play money</span>.
</h1>
<h1 className="text-lg">
Forecasting for everything that matters.
</h1>
</>
)}
{abTestVariant === 'real-world impact' && (
<>
<h1 className="mb-4 text-4xl">
Play-money betting.
<br />
Real-world impact.
</h1>
<h1 className="text-lg">
Harness humanity's collective intelligence to make smarter
decisions through forecasting.
</h1>
<h1 className="text-lg">
Join a global community betting on a better world.
</h1>
</>
)}
{abTestVariant === 'wisdom of the crowds' && (
<>
<h1 className="mb-4 text-4xl">
Harness the wisdom of the crowds
</h1>
<h1 className="text-lg">
<span className={'underline'}>Play-money</span> betting.{' '}
<span className={'underline'}>Real-world</span> decisions.
</h1>
<h1 className="text-lg">
Shape the world with accurate forecasts for better
decision-making.
</h1>
</>
)}
{abTestVariant === 'bet' && (
<>
<h1 className="mb-4 text-4xl">Bet on politics & more</h1>
<h1 className="text-lg">
Play-money markets. Real-world accuracy.
</h1>
<h1 className="text-lg">
Compete with your friends by betting on politics, tech,
sports, and more. It's play money and free to play.
</h1>
</>
)}
{abTestVariant === 'bet-typewriter' && (
<>
<h1 className="mb-4 text-4xl">
Bet on the next:{' '}
<Row>
<Typewriter
words={[
'election',
'tech breakthrough',
'game',
'bachelor',
]}
/>
</Row>
</h1>
<h1 className="text-lg">
Play-money betting. Real-world accuracy.
</h1>
<h1 className="text-lg">
Forecast events in politics, policy, technology, sports &
beyond.
</h1>
</>
)}
<Button
color="gradient"
size="2xl"
className="mt-8"
onClick={firebaseLogin}
>
{abTestVariant === 'know the future'
? 'See the forecasts'
: abTestVariant === 'real-world impact'
? 'Forecast the future'
: 'Start predicting'}
</Button>
</Col>
<Col className="mx-auto hidden h-full sm:flex">
<img
src="welcome/manipurple.png"
width={220}
alt={'manifold logo'}
className="my-auto"
/>
</Col>
</Row>
</Col>
<Col>
<Row className={'mb-3 text-xl'}>🔥 Trending Topics</Row>
<Carousel labelsParentClassName={'gap-2'} className="mx-1">
{topics.map((topic) => (
<PillButton
key={topic.slug}
onSelect={() =>
setSelectedTopicSlug(
selectedTopicSlug === topic.slug ? undefined : topic.slug
)
}
selected={selectedTopicSlug === topic.slug}
>
{removeEmojis(topic.name)}
</PillButton>
))}
</Carousel>
</Col>
<Col className={clsx('w-full gap-4 self-center')}>
{contracts.map((contract) => (
<FeedContractCard
key={contract.id + selectedTopicSlug}
contract={contract}
/>
))}
</Col>
<TestimonialsPanel />
<AboutPrivacyTerms />
</Col>
</Page>
)
}