diff options
| author | Factiven <[email protected]> | 2023-07-17 01:22:19 +0000 |
|---|---|---|
| committer | Factiven <[email protected]> | 2023-07-17 01:22:19 +0000 |
| commit | cfc62a497afe132601f6400f0956b5a97775eb54 (patch) | |
| tree | 0eab20ffe81d29a0ea87822dbd7073614935aa73 | |
| parent | Update README.md (diff) | |
| download | moopa-cfc62a497afe132601f6400f0956b5a97775eb54.tar.xz moopa-cfc62a497afe132601f6400f0956b5a97775eb54.zip | |
added fallback if no API key provided
| -rw-r--r-- | components/home/schedule.js | 166 | ||||
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | pages/en/index.js | 15 | ||||
| -rw-r--r-- | pages/en/manga/[id].js | 8 | ||||
| -rw-r--r-- | pages/en/manga/read/[...params].js | 5 |
5 files changed, 110 insertions, 86 deletions
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 }) { </div> </div> </div> - <div className="w-full bg-tersier rounded-b overflow-hidden"> - <div - ref={scrollRef} - className="flex overflow-x-scroll snap snap-x snap-proximity scrollbar-hide" - onScroll={handleScroll} - > - {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 && ( + <div className="w-full bg-tersier rounded-b overflow-hidden"> + <div + ref={scrollRef} + className="flex overflow-x-scroll snap snap-x snap-proximity scrollbar-hide" + onScroll={handleScroll} + > + {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 ( - <div - key={index} - className="snap-start flex-shrink-0 h-[240px] overflow-y-scroll scrollbar-thin scrollbar-thumb-secondary scrollbar-thumb-rounded w-full" - style={{ scrollbarGutter: "stable" }} - > - <div className="flex flex-col gap-2 px-2 pt-2"> - {uniqueArray.map((i, index) => { - const currentTime = Date.now(); - const hasAired = i.airingAt < currentTime; + return ( + <div + key={index} + className="snap-start flex-shrink-0 h-[240px] overflow-y-scroll scrollbar-thin scrollbar-thumb-secondary scrollbar-thumb-rounded w-full" + style={{ scrollbarGutter: "stable" }} + > + <div className="flex flex-col gap-2 px-2 pt-2"> + {uniqueArray.map((i, index) => { + const currentTime = Date.now(); + const hasAired = i.airingAt < currentTime; - return ( - <Link - key={`${i.id}-${index}`} - href={`/en/anime/${i.id}`} - className={`${ - hasAired ? "opacity-40" : "" - } h-full w-full flex items-center p-2 flex-shrink-0 hover:bg-secondary cursor-pointer`} - > - <div className="shrink-0"> - <Image - src={i.coverImage} - alt="coverSchedule" - width={300} - height={300} - className="w-10 h-10 object-cover rounded" - /> - </div> - <div className="flex items-center justify-between w-full"> - <div className="font-karla px-2"> - <h1 className="font-semibold text-sm line-clamp-1"> - {i.title.romaji} - </h1> - <p className="font-semibold text-xs text-gray-400"> - {convertUnixToTime(i.airingAt)} - Episode{" "} - {i.airingEpisode} - </p> + return ( + <Link + key={`${i.id}-${index}`} + href={`/en/anime/${i.id}`} + className={`${ + hasAired ? "opacity-40" : "" + } h-full w-full flex items-center p-2 flex-shrink-0 hover:bg-secondary cursor-pointer`} + > + <div className="shrink-0"> + <Image + src={i.coverImage} + alt="coverSchedule" + width={300} + height={300} + className="w-10 h-10 object-cover rounded" + /> </div> - <div> - <PlayIcon className="w-6 h-6 text-gray-300" /> + <div className="flex items-center justify-between w-full"> + <div className="font-karla px-2"> + <h1 className="font-semibold text-sm line-clamp-1"> + {i.title.romaji} + </h1> + <p className="font-semibold text-xs text-gray-400"> + {convertUnixToTime(i.airingAt)} - Episode{" "} + {i.airingEpisode} + </p> + </div> + <div> + <PlayIcon className="w-6 h-6 text-gray-300" /> + </div> </div> - </div> - </Link> - ); - })} + </Link> + ); + })} + </div> </div> - </div> - ); - })} - </div> - <div className="flex items-center bg-tersier justify-between font-karla p-2 border-t border-secondary/40"> - <button - type="button" - className="bg-secondary px-2 py-1 rounded" - onClick={scrollLeft} - > - <BackwardIcon className="w-5 h-5" /> - </button> - <div className="font-bold uppercase">{activeSection}</div> - <button - type="button" - className="bg-secondary px-2 py-1 rounded" - onClick={scrollRight} - > - <ForwardIcon className="w-5 h-5" /> - </button> + ); + })} + </div> + <div className="flex items-center bg-tersier justify-between font-karla p-2 border-t border-secondary/40"> + <button + type="button" + className="bg-secondary px-2 py-1 rounded" + onClick={scrollLeft} + > + <BackwardIcon className="w-5 h-5" /> + </button> + <div className="font-bold uppercase">{activeSection}</div> + <button + type="button" + className="bg-secondary px-2 py-1 rounded" + onClick={scrollRight} + > + <ForwardIcon className="w-5 h-5" /> + </button> + </div> </div> - </div> + )} </div> </div> ); diff --git a/package.json b/package.json index 246994f..e42b5a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moopa", - "version": "3.6.4", + "version": "3.6.5", "private": true, "founder": "Factiven", "scripts": { diff --git a/pages/en/index.js b/pages/en/index.js index d13f182..17650c3 100644 --- a/pages/en/index.js +++ b/pages/en/index.js @@ -44,7 +44,6 @@ export default function Home({ const { media: release } = useAniList(sessions); const [anime, setAnime] = useState([]); - let scheduleData = null; const update = () => { setAnime((prevAnime) => prevAnime.slice(1)); @@ -487,7 +486,7 @@ export default function Home({ )} {/* Schedule */} - {anime.length > 0 && schedules && ( + {anime.length > 0 && ( <motion.div // Add motion.div to each child component key="schedule" initial={{ y: 20, opacity: 0 }} @@ -558,8 +557,16 @@ export async function getServerSideProps(context) { const genreDetail = await aniListData({ sort: "TYPE", page: 1 }); const apikey = process.env.API_KEY; - const res = await fetch(`https://api.anify.tv/schedule?apikey=${apikey}`); - const schedules = await res.json(); + + let schedules = []; + if (apikey) { + const res = await fetch(`https://api.anify.tv/schedule?apikey=${apikey}`); + if (res.error) { + schedules = []; + } else { + schedules = await res.json(); + } + } const upComing = await getUpcomingAnime(); diff --git a/pages/en/manga/[id].js b/pages/en/manga/[id].js index 5e46599..eb53a93 100644 --- a/pages/en/manga/[id].js +++ b/pages/en/manga/[id].js @@ -159,7 +159,13 @@ export async function getServerSideProps(context) { `https://api.anify.tv/chapters/${id}?apikey=${key}` ); const data2 = await res2.json(); - chapter = data2; + if (data2.error) { + return { + notFound: true + } + } else { + chapter = data2; + } } return { diff --git a/pages/en/manga/read/[...params].js b/pages/en/manga/read/[...params].js index 0c6372d..dbabb3d 100644 --- a/pages/en/manga/read/[...params].js +++ b/pages/en/manga/read/[...params].js @@ -251,6 +251,11 @@ export async function getServerSideProps(context) { ); const data = await res.json(); + if (data.error) { + return { + notFound: true + } + } return { props: { |