From 77b7923044c0023200522fd21a549e7a88900e3d Mon Sep 17 00:00:00 2001 From: Simon Bjerre Date: Sat, 3 Aug 2024 00:34:12 +0200 Subject: [PATCH] optimized date format and loading skeleton --- src/components/Events.jsx | 71 ++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/src/components/Events.jsx b/src/components/Events.jsx index 1b052e7..72f6a77 100644 --- a/src/components/Events.jsx +++ b/src/components/Events.jsx @@ -21,9 +21,15 @@ const Events = () => { fetchData(); }, []); - function dateConverter(date) { - const newDate = new Date(date); - return newDate.toLocaleString('en-uk', { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' }); + function dateConverter(start, end) { + const startDate = new Date(start); + const endDate = new Date(end); + + if (startDate.getDate() == endDate.getDate()) { + return startDate.toLocaleString('en-uk', { weekday: 'long', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' })+" - "+endDate.toLocaleString('en-uk', { hour: 'numeric', minute: 'numeric' }); + } else { + return startDate.toLocaleString('en-uk', { weekday: 'long', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' })+" - "+endDate.toLocaleString('en-uk', { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' }) + } } console.log(dateConverter("2024-08-05 17:00:00")) @@ -31,51 +37,68 @@ const Events = () => { return (
-
- +
+ + {events.length != 0 ? :
} +
-

{events.length != 0 ? events[0].title : ""}

-

{events.length != 0 ? dateConverter(events[0].start_date) : ""} - {events.length != 0 ? dateConverter(events[0].end_date) : ""}

-

{events.length != 0 ? events[0].long_description : ""}

+ +

{events.length != 0 ? events[0].title : ""}

+
+

{events.length != 0 ? dateConverter(events[0].start_date, events[0].end_date) : ""}

+
+

{events.length != 0 ? events[0].long_description : ""}

- + + {events.length != 0 ? :
} +
-

{events.length != 0 ? events[1].title : ""}

-

{events.length != 0 ? dateConverter(events[1].start_date) : ""} - {events.length != 0 ? dateConverter(events[1].end_date) : ""}

-

{events.length != 0 ? events[1].long_description : ""}

+ +

{events.length != 0 ? events[1].title : ""}

+
+

{events.length != 0 ? dateConverter(events[1].start_date, events[1].end_date) : ""}

+
+

{events.length != 0 ? events[1].long_description : ""}

- - - - +