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

fix: minor touchups #80

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions frontend/app/(authenticated)/events/[id]/event-details.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { format } from "date-fns";
import { ClockIcon, LayoutDashboardIcon, NewspaperIcon } from "lucide-react";

import { EventDTO } from "@/client";
Expand All @@ -8,6 +7,7 @@ import {
categoriesToIconsMap,
getCategoryFor,
} from "@/types/categories";
import { parseDate } from "@/utils/date";

interface Props {
event: EventDTO;
Expand Down Expand Up @@ -47,7 +47,7 @@ const EventDetails = ({ event }: Props) => {
Event date
</span>
<span className="col-span-1 md:col-span-8 xl:col-span-9 text-black font-normal">
{format(event.date, "d MMM yyyy")}
{parseDate(event.date)}
</span>
</div>

Expand Down
3 changes: 2 additions & 1 deletion frontend/app/(authenticated)/events/[id]/event-source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
articleSourceToDisplayNameMap,
articleSourceToIconMap,
} from "@/types/events";
import { parseDate } from "@/utils/date";

interface EventSourceProps {
originalSource: ArticleDTO;
Expand Down Expand Up @@ -40,7 +41,7 @@ const EventSource = ({ originalSource }: EventSourceProps) => {
{articleSourceToDisplayNameMap[originalSource.source]}
</span>
<Separator className="h-5" orientation="vertical" />
<span>{originalSource.date}</span>
<span>{parseDate(originalSource.date)}</span>
</div>
</div>
</div>
Expand Down
20 changes: 9 additions & 11 deletions frontend/components/news/news-article.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import Image from "next/image";
import { useRouter } from "next/navigation";
import { ArrowUpRightIcon } from "lucide-react";

import { CategoryDTO, MiniEventDTO } from "@/client";
Expand All @@ -11,10 +12,12 @@ import {
Category,
getCategoryFor,
} from "@/types/categories";
import { parseDate } from "@/utils/date";

const NewsArticle = (props: { newsEvent: MiniEventDTO }) => {
const newsEvent = props.newsEvent;
const newsArticle = newsEvent.original_article;
const router = useRouter();
const [categories, setCategories] = useState<Category[]>([]);
const IMG_HEIGHT = 154;

Expand All @@ -31,20 +34,15 @@ const NewsArticle = (props: { newsEvent: MiniEventDTO }) => {
}
}, [newsEvent]);

const parseDate = (dateString: string) => {
const PLACEHOLDER_DATE = "-";

try {
const date: Date = new Date(dateString);
return date.toDateString();
} catch (error) {
console.log(error);
return PLACEHOLDER_DATE;
}
const onClick = () => {
router.push(`/events/${newsEvent.id}`);
};

return (
<div className="flex flex-col-reverse py-10 lg:flex-row w-auto lg:py-6 xl:py-4 gap-x-16 border-y-[1px] lg:border-y-[0px] hover:bg-muted/70 lg:rounded-md px-4 md:px-8">
<div
className="flex flex-col-reverse py-10 lg:flex-row w-auto lg:py-6 xl:py-4 gap-x-16 border-y-[1px] lg:border-y-[0px] hover:bg-muted/70 lg:rounded-md px-4 md:px-8 cursor-pointer"
onClick={onClick}
>
<div className="flex flex-col w-full lg:w-7/12 2xl:w-9/12 3xl:w-10/12">
<div className="flex w-full justify-between text-sm text-offblack">
<span>
Expand Down
10 changes: 10 additions & 0 deletions frontend/utils/date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { format } from "date-fns";

export const parseDate = (date: string): string => {
const PLACEHOLDER_DATE = "-";
try {
return format(date, "d MMM yyyy");
} catch {
return PLACEHOLDER_DATE;
}
};
Loading