From 9a9e892a1f43a61188cfd08ef1faaf5100d0a41a Mon Sep 17 00:00:00 2001 From: Factiven Date: Mon, 17 Apr 2023 16:17:45 +0700 Subject: 4th fixes --- components/hero/content.js | 4 ++-- components/videoPlayer.js | 50 ++++------------------------------------------ 2 files changed, 6 insertions(+), 48 deletions(-) (limited to 'components') diff --git a/components/hero/content.js b/components/hero/content.js index 348e1ab..1a45860 100644 --- a/components/hero/content.js +++ b/components/hero/content.js @@ -27,7 +27,7 @@ export default function Content({ ids, section, data }) { // console.log({ left: scrollLeft, right: scrollRight }); const array = data; - let filteredData = array.filter((item) => item.status !== "Unknown"); + let filteredData = array?.filter((item) => item.status !== "Unknown"); return (

{section}

@@ -44,7 +44,7 @@ export default function Content({ ids, section, data }) { className="scroll flex h-full w-full items-center select-none overflow-x-scroll scroll-smooth whitespace-nowrap overflow-y-hidden scrollbar-hide lg:gap-8 gap-5 p-10 z-30 " onScroll={handleScroll} > - {filteredData.map((anime) => { + {filteredData?.map((anime) => { return (
{ art.on("ready", () => { - const seekTime = seek; + const seek = art.storage.get(id); + const seekTime = seek?.time || 0; const duration = art.duration; const percentage = seekTime / duration; @@ -78,7 +79,7 @@ export default function VideoPlayer({ art.currentTime = 0; console.log("Video restarted from the beginning"); } else { - art.currentTime = seek; + art.currentTime = seek.time; } }); @@ -101,50 +102,7 @@ export default function VideoPlayer({ }); art.on("destroy", async () => { - if (!session) return; - const lastPlayed = { - id: id, - time: art.currentTime, - }; - const res = await fetch("/api/watched-episode", { - method: "POST", - body: JSON.stringify({ - username: session?.user.name, - id: aniId, - newData: lastPlayed, - }), - headers: { - "Content-Type": "application/json", - }, - }); - - // console.log(res.status); - - const title = titles; - const prevDataStr = localStorage.getItem("lastPlayed") || "[]"; - const prevData = JSON.parse(prevDataStr); - let titleExists = false; - - prevData.forEach((item) => { - if (item.title === title) { - const foundIndex = item.data.findIndex((e) => e.id === id); - if (foundIndex !== -1) { - item.data[foundIndex] = lastPlayed; - } else { - item.data.push(lastPlayed); - } - titleExists = true; - } - }); - - if (!titleExists) { - prevData.push({ - title: title, - data: [lastPlayed], - }); - } - - localStorage.setItem("lastPlayed", JSON.stringify(prevData)); + art.storage.set(id, { time: art.currentTime }); }); }} /> -- cgit v1.2.3