diff --git a/frontend/app/(authenticated)/events/[id]/event-details.tsx b/frontend/app/(authenticated)/events/[id]/event-details.tsx index b2e680f2..94459832 100644 --- a/frontend/app/(authenticated)/events/[id]/event-details.tsx +++ b/frontend/app/(authenticated)/events/[id]/event-details.tsx @@ -1,4 +1,3 @@ -import { format } from "date-fns"; import { ClockIcon, LayoutDashboardIcon, NewspaperIcon } from "lucide-react"; import { EventDTO } from "@/client"; @@ -8,6 +7,7 @@ import { categoriesToIconsMap, getCategoryFor, } from "@/types/categories"; +import { parseDate } from "@/utils/date"; interface Props { event: EventDTO; @@ -47,7 +47,7 @@ const EventDetails = ({ event }: Props) => { Event date - {format(event.date, "d MMM yyyy")} + {parseDate(event.date)} diff --git a/frontend/app/(authenticated)/events/[id]/event-source.tsx b/frontend/app/(authenticated)/events/[id]/event-source.tsx index b4e04a8d..ed9c0d14 100644 --- a/frontend/app/(authenticated)/events/[id]/event-source.tsx +++ b/frontend/app/(authenticated)/events/[id]/event-source.tsx @@ -8,6 +8,7 @@ import { articleSourceToDisplayNameMap, articleSourceToIconMap, } from "@/types/events"; +import { parseDate } from "@/utils/date"; interface EventSourceProps { originalSource: ArticleDTO; @@ -40,7 +41,7 @@ const EventSource = ({ originalSource }: EventSourceProps) => { {articleSourceToDisplayNameMap[originalSource.source]} - {originalSource.date} + {parseDate(originalSource.date)} diff --git a/frontend/components/news/news-article.tsx b/frontend/components/news/news-article.tsx index dabfdad2..0210e774 100644 --- a/frontend/components/news/news-article.tsx +++ b/frontend/components/news/news-article.tsx @@ -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"; @@ -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([]); const IMG_HEIGHT = 154; @@ -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 ( -
+
diff --git a/frontend/utils/date.ts b/frontend/utils/date.ts new file mode 100644 index 00000000..5f50b99c --- /dev/null +++ b/frontend/utils/date.ts @@ -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; + } +};