import { ChevronLeftIcon, PlayIcon } from "@heroicons/react/24/solid"; import Image from "next/image"; import Link from "next/link"; import { useEffect, useState } from "react"; import Skeleton from "react-loading-skeleton"; import Footer from "@/components/shared/footer"; import { getServerSession } from "next-auth"; import { authOptions } from "../../api/auth/[...nextauth]"; import { ChevronRightIcon } from "@heroicons/react/24/outline"; import { useRouter } from "next/router"; import HistoryOptions from "@/components/home/content/historyOptions"; import Head from "next/head"; import MobileNav from "@/components/shared/MobileNav"; import { toast } from "sonner"; export default function PopularAnime({ sessions }) { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [remove, setRemoved] = useState(); const router = useRouter(); useEffect(() => { setLoading(true); const fetchData = async () => { let data; if (sessions?.user?.name) { data = await fetch( `/api/user/profile?name=${sessions?.user?.name}` ).then((res) => { if (!res.ok) { switch (res.status) { case 404: { return console.log("user not found"); } case 500: { return console.log("server error"); } } } return res.json(); }); } if (!data) { const dat = JSON.parse(localStorage.getItem("artplayer_settings")); if (dat) { const arr = Object.keys(dat).map((key) => dat[key]); setData(arr); setLoading(false); } } else { setData(data?.WatchListEpisode); setLoading(false); } }; fetchData(); }, [sessions?.user?.name, remove]); const removeItem = async (id, aniId) => { if (sessions?.user?.name) { // remove from database const res = await fetch(`/api/user/update/episode`, { method: "DELETE", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ name: sessions?.user?.name, id, aniId, }), }); const data = await res.json(); if (id) { // remove from local storage const artplayerSettings = JSON.parse(localStorage.getItem("artplayer_settings")) || {}; if (artplayerSettings[id]) { delete artplayerSettings[id]; localStorage.setItem( "artplayer_settings", JSON.stringify(artplayerSettings) ); } } if (aniId) { const currentData = JSON.parse(localStorage.getItem("artplayer_settings")) || {}; const updatedData = {}; for (const key in currentData) { const item = currentData[key]; if (item.aniId !== aniId) { updatedData[key] = item; } } localStorage.setItem("artplayer_settings", JSON.stringify(updatedData)); } // update client setRemoved(id || aniId); if (data?.message === "Episode deleted") { toast.success("Episode removed from history", { position: "bottom-right", }); } } else { if (id) { // remove from local storage const artplayerSettings = JSON.parse(localStorage.getItem("artplayer_settings")) || {}; if (artplayerSettings[id]) { delete artplayerSettings[id]; localStorage.setItem( "artplayer_settings", JSON.stringify(artplayerSettings) ); } setRemoved(id); } if (aniId) { const currentData = JSON.parse(localStorage.getItem("artplayer_settings")) || {}; // Create a new object to store the updated data const updatedData = {}; // Iterate through the current data and copy items with different aniId to the updated object for (const key in currentData) { const item = currentData[key]; if (item.aniId !== aniId) { updatedData[key] = item; } } // Update localStorage with the filtered data localStorage.setItem("artplayer_settings", JSON.stringify(updatedData)); setRemoved(aniId); } } }; return ( <> Moopa - Recently Watched Episodes

Recently Watched

{data ?.filter((i) => i?.watchId) .map((i) => { const time = i.timeWatched; const duration = i.duration; let prog = (time / duration) * 100; if (prog > 90) prog = 100; return (
{i?.nextId && ( )}

{i?.title || i.anititle}

{i?.image && ( Episode Thumbnail )} {/*

{i.title}

*/}

{i.aniTitle} {" "} | Episode {i.episode}

); })} {loading && ( <> {[1, 2, 4, 5, 6, 7, 8].map((item) => (
))} )}