aboutsummaryrefslogtreecommitdiff
path: root/components/manga/chapters.js
blob: 7997a737fd7d6e5bfaf18a27c689ca6c2eafc993 (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
import axios from "axios";
import Link from "next/link";
import React, { useEffect, useState } from "react";

export default function Content({ ids, providers }) {
  const [data, setData] = useState([]);
  const [isLoading, setIsLoading] = useState(true);
  const [error, setError] = useState(null);

  async function fetchData() {
    setIsLoading(true);
    try {
      const res = await axios.get(
        `https://api.eucrypt.my.id/meta/anilist-manga/info/${ids}?provider=${providers}`
      );
      const data = res.data;
      setData(data);
      setError(null); // Reset error state if data is successfully fetched
    } catch (error) {
      setError(error);
    }

    setIsLoading(false);
  }
  useEffect(() => {
    fetchData();
  }, [providers]);
  useEffect(() => {
    // console.log("Data changed:", data);
  }, [data]);

  if (error) {
    // Handle 404 Not Found error
    return <div>Chapters Not Available</div>;
  }
  //   console.log(isLoading);
  return (
    <>
      <div className="flex h-[540px] flex-col gap-5 overflow-y-scroll">
        {isLoading ? (
          <p>Loading...</p>
        ) : data.chapters?.length > 0 ? (
          data.chapters?.map((chapter, index) => {
            return (
              <div key={index}>
                <Link
                  href={`/manga/chapter/[chapter]`}
                  as={`/manga/chapter/read?id=${chapter.id}&provider=${providers}`}
                >
                  Chapters {index + 1}
                </Link>
              </div>
            );
          })
        ) : (
          <p>No Chapters Available</p>
        )}
      </div>
    </>
  );
}