From cfc62a497afe132601f6400f0956b5a97775eb54 Mon Sep 17 00:00:00 2001 From: Factiven Date: Mon, 17 Jul 2023 01:22:19 +0000 Subject: added fallback if no API key provided --- components/home/schedule.js | 166 +++++++++++++++++++++++--------------------- 1 file changed, 86 insertions(+), 80 deletions(-) (limited to 'components') diff --git a/components/home/schedule.js b/components/home/schedule.js index 35414d2..d62f00a 100644 --- a/components/home/schedule.js +++ b/components/home/schedule.js @@ -18,16 +18,20 @@ export default function Schedule({ data, scheduleData, time }) { const scrollRef = useRef(null); useEffect(() => { - const index = Object.keys(scheduleData).indexOf(activeSection + "Schedule"); - if (scrollRef.current) { - scrollRef.current.scrollLeft = scrollRef.current.clientWidth * index; + if (scheduleData) { + const index = Object?.keys(scheduleData).indexOf( + activeSection + "Schedule" + ); + if (scrollRef.current) { + scrollRef.current.scrollLeft = scrollRef.current.clientWidth * index; + } } }, [activeSection, scheduleData]); const handleScroll = (e) => { const { scrollLeft, clientWidth } = e.target; const index = Math.floor(scrollLeft / clientWidth); - let day = Object.keys(scheduleData)[index]; + let day = Object?.keys(scheduleData)[index]; day = day.replace("Schedule", ""); setActiveSection(day); }; @@ -128,88 +132,90 @@ export default function Schedule({ data, scheduleData, time }) { -
-
- {Object.entries(scheduleData).map(([section, data], index) => { - const uniqueArray = data.reduce((accumulator, current) => { - if (!accumulator.find((item) => item.id === current.id)) { - accumulator.push(current); - } - return accumulator; - }, []); + {scheduleData.length > 0 && ( +
+
+ {Object.entries(scheduleData).map(([section, data], index) => { + const uniqueArray = data.reduce((accumulator, current) => { + if (!accumulator.find((item) => item.id === current.id)) { + accumulator.push(current); + } + return accumulator; + }, []); - return ( -
-
- {uniqueArray.map((i, index) => { - const currentTime = Date.now(); - const hasAired = i.airingAt < currentTime; + return ( +
+
+ {uniqueArray.map((i, index) => { + const currentTime = Date.now(); + const hasAired = i.airingAt < currentTime; - return ( - -
- coverSchedule -
-
-
-

- {i.title.romaji} -

-

- {convertUnixToTime(i.airingAt)} - Episode{" "} - {i.airingEpisode} -

+ return ( + +
+ coverSchedule
-
- +
+
+

+ {i.title.romaji} +

+

+ {convertUnixToTime(i.airingAt)} - Episode{" "} + {i.airingEpisode} +

+
+
+ +
-
- - ); - })} + + ); + })} +
-
- ); - })} -
-
- -
{activeSection}
- + ); + })} +
+
+ +
{activeSection}
+ +
-
+ )}
); -- cgit v1.2.3