aboutsummaryrefslogtreecommitdiff
path: root/src/app/anime/continueWatching/page.jsx
blob: 8951f4a9f3eef71c3d7c50bac599ff19d9282b2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"use client";

import React, { useState, useEffect } from "react";
import NextImage from "next/image";
import { CarFooter, Image, Link } from "@nextui-org/react";

const ContinueWatching = () => {
	const [localItems, setLocalItems] = useState(null);

	useEffect(() => {
		const newData = get_local();
		setLocalItems(newData);
	}, []); // Empty dependency array means this effect runs only once after the initial render

	function get_local() {
		try {
			const data = localStorage.getItem("data");
			return JSON.parse(data);
		} catch (error) {
			console.log("error", error);
			return false;
		}
	}

	return (
		<main className="pt-12">
			<p className="text-sky-400 text-2xl uppercase">Continue Watching</p>
			{localItems && (
				<div className="flex flex-col m-auto lg:w-[95%] ">
					{localItems.watchHis &&
						localItems.watchHis.map((item, index) => (
							<Link
								href={`/${item.type}/${item.id}`}
								key={index}
								color="foreground"
								className="mt-4 bg-gray-300 p-2 dark:bg-[#1f1f1f] rounded-lg"
							>
								<div className="flex items-center justify-between w-full">
									<div>
										<p className="font-bold text-xl lg:text-2xl w-3/5">
											{item.name}
										</p>
										<p>Episode: {item.episode}</p>
									</div>
									<Image
										as={NextImage}
										isZoomed
										isBlurred
										shadow="lg"
										src={item.image}
										width={180}
										height={300}
										alt="Continue anime poster"
										className="h-52 w-auto lg:h-64 lg:w-52"
										priority
									/>
								</div>
							</Link>
						))}
				</div>
			)}
		</main>
	);
};

export default ContinueWatching;