Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Events Page #122

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions app/[locale]/events/components/EventList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"use client";

import Link from "next/link";
import { ExternalLink } from "lucide-react";
import { Button } from "@/components/ui/button";
import { useState } from "react";

import { Card, CardContent } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
import eventsData from "@/data/events.json";
import { cn } from "@/lib/utils";

interface Event {
title: string;
location: string;
date: Date;
link: string;
}

const events: Event[] = eventsData.map((event) => ({
...event,
date: new Date(`${event.date}T12:00:00Z`),
}));

function CalendarIcon({ date, className }: { date: Date; className?: string }) {
return (
<div
className={cn(
"relative flex flex-col items-center justify-center w-12 h-12 rounded border bg-background",
className
)}
>
<div className="text-[0.65rem] font-medium text-muted-foreground">
{date.toLocaleString("default", { month: "short" })}
</div>
<div className="font-bold text-xl leading-none">{date.getDate()}</div>
</div>
);
}
Comment on lines +25 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract this to its own file? It helps keep separation of concerns and allows it to be reused. If you don't want it to be reused, you can keep it in the same directory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may re-work this tomorrow following the conversation with Wale in Mattermost earlier. But yes, I agree that this could be used elsewhere in the future so it would make sense to separate it into its own component. Will do!


export default function Component() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename Component to EventList so we don't cause confusion during debugging and stack traces?

Suggested change
export default function Component() {
export default function EventList() {

const [displayCount, setDisplayCount] = useState(10);

const sortedEvents = [...events].sort(
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()
);

const visibleEvents = sortedEvents.slice(0, displayCount);

const groupedEvents = visibleEvents.reduce(
(groups, event) => {
const monthYear = event.date.toLocaleString("default", {
month: "long",
year: "numeric",
});
if (!groups[monthYear]) {
groups[monthYear] = [];
}
groups[monthYear].push(event);
return groups;
},
{} as Record<string, Event[]>
);

return (
<div className="p-4 md:p-6">
<div className="grid gap-8 w-full max-w-2xl mx-auto">
{Object.entries(groupedEvents).map(([monthYear, monthEvents]) => (
<div
key={monthYear}
className="grid gap-4"
>
<div className="flex items-center w-full">
<div className="w-36 font-semibold text-lg text-muted-foreground whitespace-nowrap">
{monthYear}
</div>
<Separator className="flex-1" />
</div>
<div className="grid gap-4">
{monthEvents.map((event, index) => (
<Link
key={index}
href={event.link}
>
Comment on lines +81 to +84
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use passHref here so we don't have an extra DOM element.

Suggested change
<Link
key={index}
href={event.link}
>
<Link
key={index}
href={event.link}
passHref
>

<Card className="overflow-hidden transition-colors hover:bg-muted/50 group">
<CardContent className="p-0">
<div className="flex gap-4 p-6 items-center justify-between">
<div className="flex gap-4 items-center">
<CalendarIcon date={event.date} />
<div className="space-y-0.5">
<h3 className="font-semibold leading-tight">
{event.title}
</h3>
<span className="text-sm text-muted-foreground">
{event.location}
</span>
</div>
</div>
<ExternalLink className="w-4 h-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity" />
</div>
</CardContent>
</Card>
</Link>
))}
</div>
</div>
))}

{displayCount < events.length && (
<Button
variant="outline"
className="w-full mt-4"
onClick={() => setDisplayCount((prev) => prev + 10)}
>
Load More
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we translating this? If so, it can be passed in as a prop. If not, then you can close this review comment.

</Button>
)}
</div>
</div>
);
}
31 changes: 31 additions & 0 deletions app/[locale]/events/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { getTranslations } from "next-intl/server";
import EventList from "./components/EventList";

export async function generateMetadata() {
const t = await getTranslations("events");

return {
title: `${t("title")} - Rocky Linux`,
description: t("description"),
};
}

export default async function EventsPage() {
const t = await getTranslations("events");

return (
<div className="py-24 sm:py-32">
<div className="mx-auto max-w-7xl px-6 lg:px-8">
<div className="text-center">
<h2 className="text-3xl font-bold font-display tracking-tight sm:text-4xl">
{t("title")}
</h2>
<p className="mt-2 text-lg leading-8">{t("description")}</p>
</div>
<div className="mt-10 sm:mt-16">
<EventList />
</div>
</div>
</div>
);
}
13 changes: 13 additions & 0 deletions app/[locale]/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,16 @@
.prose :where(code):not(:where([class~="not-prose"] *))::after {
content: "" !important;
}

/*
---break---
*/

@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
}
}
28 changes: 28 additions & 0 deletions components/ui/separator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use client";

import * as React from "react";
import * as SeparatorPrimitive from "@radix-ui/react-separator";

import { cn } from "@/lib/utils";

function Separator({
className,
orientation = "horizontal",
decorative = true,
...props
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
return (
<SeparatorPrimitive.Root
data-slot="separator-root"
decorative={decorative}
orientation={orientation}
className={cn(
"bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
className
)}
{...props}
/>
);
}

export { Separator };
8 changes: 8 additions & 0 deletions data/events.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"title": "Community Wallpaper Contest",
"location": "forums.rockylinux.org",
"date": "2025-03-03",
"link": "https://forums.rockylinux.org/t/rocky-linux-10-wallpaper-contest/17501"
}
]
4 changes: 4 additions & 0 deletions messages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,9 @@
"description": "Join our <link1>Mattermost chat</link1> and introduce yourself in the <link2>~Documentation</link2> channel. Make sure to review the contributing guide available on our <link3>README</link3>."
}
}
},
"events": {
"title": "Events",
"description": "We host and attend a variety of events throughout each year. We invite you to join us at one of our events to learn more about the project and meet other members of the community."
}
}
4 changes: 4 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,9 @@
"description": "Join our <link1>Mattermost chat</link1> and introduce yourself in the <link2>~Documentation</link2> channel. Make sure to review the contributing guide available on our <link3>README</link3>."
}
}
},
"events": {
"title": "Events",
"description": "We host and attend a variety of events throughout each year. We invite you to join us at one of our events to learn more about the project and meet other members of the community."
}
}
Loading
Loading