-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from kaupunginnaiset/feat/add-event-listing
Add event card
- Loading branch information
Showing
8 changed files
with
203 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import Image from "next/image"; | ||
import format from "date-fns/format"; | ||
import styles from "../../../styles/Home.module.css"; | ||
import { isSameDay } from "date-fns"; | ||
|
||
interface Event { | ||
title: string; | ||
category?: string[]; | ||
location: string; | ||
img?: string; | ||
altText?: string; | ||
startTime: string; | ||
endTime?: string | null; | ||
wholeDay?: boolean; | ||
} | ||
|
||
interface EventCardProps { | ||
event: Event; | ||
} | ||
|
||
interface TimeProps { | ||
startDateTime: string; | ||
endDateTime?: string | null; | ||
wholeDay?: boolean; | ||
} | ||
|
||
interface CategoryProps { | ||
category: string; | ||
} | ||
|
||
const dayFormatString = "d.L.yyyy"; | ||
const dayFormatStringWithoutYear = "d.L."; | ||
const timeFormatString = "HH:mm"; | ||
|
||
const Time = ({ startDateTime, endDateTime, wholeDay }: TimeProps) => { | ||
const startTimeDate = new Date(startDateTime); | ||
const endTimeDate = endDateTime ? new Date(endDateTime) : null; | ||
const startTime = format(startTimeDate, timeFormatString); | ||
const endTime = endTimeDate ? format(endTimeDate, timeFormatString) : null; | ||
|
||
const shouldShowEndDate = endTimeDate && !isSameDay(startTimeDate, endTimeDate); | ||
|
||
return ( | ||
<div className={styles.times}> | ||
<time dateTime={format(startTimeDate, "yyyy-LL-dd")}> | ||
{shouldShowEndDate ? format(startTimeDate, dayFormatStringWithoutYear) : format(startTimeDate, dayFormatString)} | ||
</time> | ||
{shouldShowEndDate ? ( | ||
<> | ||
-<time dateTime={format(endTimeDate, "yyyy-LL-dd")}>{format(endTimeDate, dayFormatString)}</time> | ||
</> | ||
) : ( | ||
"" | ||
)}{" "} | ||
{!wholeDay ? ( | ||
<> | ||
<time dateTime={startTime}>{startTime}</time> | ||
{endTime ? ( | ||
<> | ||
-<time dateTime={endTime}>{endTime}</time> | ||
</> | ||
) : ( | ||
"" | ||
)} | ||
</> | ||
) : ( | ||
"" | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
const Category = ({ category }: CategoryProps) => { | ||
return <span className={styles.category}>{category}</span>; | ||
}; | ||
|
||
export const EventCard = ({ event }: EventCardProps) => { | ||
return ( | ||
<div className={styles["event-card"]}> | ||
<div className={styles["image-container"]}> | ||
<Image src="https://picsum.photos/200" alt="" width={200} height={200} /> | ||
</div> | ||
<Time startDateTime={event.startTime} endDateTime={event.endTime} wholeDay={event.wholeDay} /> | ||
<h2>{event.title}</h2> | ||
<address>{event.location}</address> | ||
<div className={styles.categories}> | ||
{event.category?.map(category => ( | ||
<Category key={`${category}-${event.startTime}`} category={category} /> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import styles from "../../../styles/Home.module.css"; | ||
|
||
import data from "../../../data"; | ||
import { EventCard } from "./EventCard"; | ||
|
||
export const Frontpage = () => { | ||
return ( | ||
<> | ||
<h1 className={styles.title}>Tapahtumat</h1> | ||
<div className={styles.events}> | ||
{data.map(item => ( | ||
<EventCard key={item.id} event={item} /> | ||
))} | ||
</div> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
basePath: "", | ||
reactStrictMode: true | ||
reactStrictMode: true, | ||
images: { | ||
domains: ["picsum.photos"] | ||
} | ||
}; | ||
|
||
module.exports = nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,81 @@ | ||
.container { | ||
padding: 0 2rem; | ||
} | ||
|
||
.events { | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
align-items: center; | ||
margin: auto 2rem; | ||
} | ||
|
||
.event-card { | ||
max-width: 30rem; | ||
width: 100%; | ||
margin: 0; | ||
margin-bottom: 4rem; | ||
display: grid; | ||
align-items: start; | ||
row-gap: 0.25rem; | ||
column-gap: 0.5rem; | ||
justify-content: start; | ||
grid-template-areas: | ||
"img time" | ||
"img title" | ||
"img location" | ||
"img categories"; | ||
} | ||
|
||
.times { | ||
grid-area: time; | ||
font-size: 1rem; | ||
} | ||
|
||
.event-card > h2 { | ||
margin: 0; | ||
grid-area: title; | ||
font-size: 1.4rem; | ||
word-break: break-word; | ||
} | ||
|
||
.image-container { | ||
grid-area: img; | ||
max-width: 10rem; | ||
min-width: 8rem; | ||
} | ||
|
||
.event-card > address { | ||
grid-area: location; | ||
} | ||
|
||
.categories { | ||
grid-area: categories; | ||
display: flex; | ||
flex-flow: row wrap; | ||
} | ||
|
||
.category { | ||
font-weight: bold; | ||
color: #fff; | ||
background-color: var(--c-pride-blue); | ||
padding: 0.25rem; | ||
margin: 0.25rem 0.25rem 0.25rem 0; | ||
} | ||
|
||
@media screen and (max-width: 600px) { | ||
.event-card { | ||
grid-template-columns: 1fr; | ||
grid-template-areas: | ||
"img" | ||
"time" | ||
"title" | ||
"location" | ||
"categories"; | ||
} | ||
|
||
.image-container { | ||
width: 100%; | ||
justify-self: center; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters