diff options
| author | Factiven <[email protected]> | 2023-04-17 16:17:45 +0700 |
|---|---|---|
| committer | Factiven <[email protected]> | 2023-04-17 16:17:45 +0700 |
| commit | 9a9e892a1f43a61188cfd08ef1faaf5100d0a41a (patch) | |
| tree | 005b6b4e5b786139b266847b6548770f9de6bca3 /components | |
| parent | Update [user].js (diff) | |
| download | moopa-9a9e892a1f43a61188cfd08ef1faaf5100d0a41a.tar.xz moopa-9a9e892a1f43a61188cfd08ef1faaf5100d0a41a.zip | |
4th fixes
Diffstat (limited to 'components')
| -rw-r--r-- | components/hero/content.js | 4 | ||||
| -rw-r--r-- | components/videoPlayer.js | 50 |
2 files changed, 6 insertions, 48 deletions
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 ( <div> <h1 className="px-5 font-karla text-[20px] font-bold">{section}</h1> @@ -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 ( <div key={anime.id} diff --git a/components/videoPlayer.js b/components/videoPlayer.js index c0d551d..efd354a 100644 --- a/components/videoPlayer.js +++ b/components/videoPlayer.js @@ -69,7 +69,8 @@ export default function VideoPlayer({ style={{ width: "100%", height: "100%", margin: "0 auto 0" }} getInstance={(art) => { 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 }); }); }} /> |