-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathhome.tsx
More file actions
144 lines (130 loc) · 4.84 KB
/
Copy pathhome.tsx
File metadata and controls
144 lines (130 loc) · 4.84 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
'use client';
import { useTranslations } from 'next-intl';
import { ThematicsBlock, ImagesCarousel, ResultsCard, NewsSmallBlock, TalksBlock, Title, TitleProps, HeroBlock } from '@/components';
import { HomepageData } from './page';
import Image from 'next/image'
type HomepageProps = {
data: HomepageData;
}
export default function Homepage({ data }: HomepageProps) {
const t = useTranslations('home');
const heroData = {
image: data.hero?.image?.url,
imageCredit: data.hero?.image?.caption ?? null,
title: {
level: 1 as TitleProps['level'],
variant: "big" as TitleProps['variant'],
children: data.hero?.title || '',
colors: 'text-white bg-building',
className: "drop-shadow-3 drop-shadow-black before:-z-1",
rotation: -3.47,
},
subtitle: {
level: 2 as TitleProps['level'],
variant: "medium" as TitleProps['variant'],
children: data.hero?.subtitle || '',
colors: 'text-black bg-white',
className: "drop-shadow-1 drop-shadow-black before:-z-1",
rotation: -3.47,
},
talk: data.hero?.talk || '',
};
const projects = data.featured_projects?.map(project => ({
id: (project.id ?? "" ).toString(),
src: project.thumbnail?.url || '',
credit: project.thumbnail?.caption ?? null,
title: project.title || '',
alt: project.title || '',
description: project.short_description || '',
ctaText: t('projects.ctaText'),
ctaHref: `projects/${project.slug}`,
})).filter(project => project.src && project.title) ?? [];
const results = data.results?.map((result) => ({
id: result.id?.toString() || '',
number: result.kpi?.stat || '',
text: result.kpi?.description,
linkTarget: result.cta?.link,
linkLabel: result.cta?.text,
})) ?? [];
const events = data.events?.map((event) => ({
id: event.id,
title: event.name || '',
date: new Date(event.date || '').toLocaleString(undefined, { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric' }),
image: event.image?.url,
imageCredit: event.image?.caption ?? null,
tag: [t('events.tag')],
link: event.link || '',
})).filter(event => event.title && event.link) ?? [];
const resources = data.resources?.map((resource) => {
const isBlog = !!resource.blog;
return {
id: resource.id,
type: isBlog ? 'article' : 'press_release',
author: isBlog ? ( (resource.blog?.author as { name: string })?.name || t('resources.defaultAuthor')) : (resource.press_release as { media_name: string })?.media_name || '',
talk: isBlog ? (resource.blog as { title: string })?.title || '' : (resource.press_release as { title: string })?.title || '',
image: isBlog ? resource.blog?.thumbnail?.url || '' : resource.press_release?.thumbnail?.url || '',
imageCredit: isBlog ? (resource.blog?.thumbnail?.caption ?? null) : (resource.press_release?.thumbnail?.caption ?? null),
ctaText: isBlog ? t('resources.articleCtaText') : t('resources.pressCtaText'),
ctaLink: isBlog ? `/articles/${resource.blog?.slug || ''}` : (resource.press_release as { article_link: string })?.article_link || '',
}
}) ?? [];
const thematics = data.thematics?.map(thematic => ({
title: {
children: thematic.name || '',
props: {
colors: `text-black bg-${thematic.color}`,
className: "drop-shadow-3 drop-shadow-black before:-z-1",
rotation: -2.58,
}
},
id: thematic.id?.toString() || '',
talk: thematic.short_description || '',
talkOffset: 10,
image: thematic.thumbnail?.url || '',
imageCredit: thematic.thumbnail?.caption ?? null,
ctaText: thematic.cta_text,
ctaLink: thematic.cta_link,
})).filter(thematic => thematic.talk) ?? [];
return (
<>
<HeroBlock
{...heroData}
title={{ ...heroData.title, children: t('hero.title') }}
subtitle={{ ...heroData.subtitle, children: t('hero.subtitle') }}
/>
<div className="container flex flex-row mt-lg mb-sm">
<Image
src="/icons/dot-purple.svg"
width={35}
height={35}
alt=""
/>
<Title level={2} className='ml-2' variant="medium">
{data.project_carousel_title!}
</Title>
</div>
{projects.length > 0 && <ImagesCarousel className="mb-lg" titleLevel={2} images={projects} />}
<ThematicsBlock
title={data.thematics_section_title!}
isHome
thematics={thematics.map(t => ({ ...t, id: t.id?.toString() || '' }))}
className="my-lg"
/>
<TalksBlock
isHome
title={data.resources_section_title!}
talks={resources}
/>
<ResultsCard
title={data.results_section_title!}
className="my-lg md:px-40"
results={results}
/>
<NewsSmallBlock
title={t('news.title')}
blocks={events}
className='my-lg'
/>
</>
);
}