This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.tsx
80 lines (69 loc) · 1.91 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
import {
type GetStaticPaths,
type GetStaticProps,
type InferGetStaticPropsType
} from 'next'
import { useRouter } from 'next/router'
import { BreadcrumbJsonLd } from 'next-seo'
import React from 'react'
import Clan, { ClanMeta } from '~components/Clan'
import PageContainer, { LoadingPageContainer } from '~components/PageContainer'
import { possessive } from '~helpers/grammar'
import { canonicalUrl } from '~helpers/urls'
import { getClan } from '~libs/api'
const ClanPage: React.FC = ({
id,
status,
name,
motto,
description,
avatar,
leaderboard
}: InferGetStaticPropsType<typeof getStaticProps>) => {
const { isFallback } = useRouter()
if (isFallback) return <LoadingPageContainer />
const { kicker, url } = ClanMeta[status]
const meta = {
canonical: canonicalUrl(url(id)),
title: [name, kicker].join(' | '),
description: [possessive(name), description].join(' ')
}
return (
<PageContainer meta={meta}>
<BreadcrumbJsonLd
itemListElements={[
{ position: 1, name: kicker, item: canonicalUrl(url()) },
{ position: 2, name, item: meta.canonical }
]}
/>
<Clan
id={id}
status={status}
name={name}
motto={motto}
description={description}
avatar={avatar}
leaderboard={leaderboard}
/>
</PageContainer>
)
}
export const getStaticProps: GetStaticProps = async ({ params }) => {
const status = params?.status || null
const clanId = params?.clanId.toString()
const clan = await getClan(parseInt(clanId))
// TODO: Handle 404
// if (!clan) {
// return { notFound: true }
// }
return { props: { ...clan, status }, revalidate: 60 }
}
export const getStaticPaths: GetStaticPaths = async () => {
// TODO: Only load top clans
const clans = []
const paths = clans.map(clanId => ({
params: { clanId }
}))
return { paths, fallback: true }
}
export default ClanPage