Advertisement
Guest User

Untitled

a guest
Jan 20th, 2024
34
0
62 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. import "../../styles/UpcomingCarousel.scoped.scss";
  2. import { Link } from "react-router-dom";
  3. import { useEffect } from "react";
  4. import ScrollCarousel from "scroll-carousel";
  5. import { anime_data } from "../../data";
  6.  
  7. var top10UpcomingAnime;
  8.  
  9. export const UpcomingCarousel = () => {
  10. useEffect(() => {
  11. let main = document.querySelector(".main");
  12.  
  13. // don't put it in a variable, then it won't work!
  14. //https://asif-jalil.github.io/scroll-carousel-website/#api
  15. new ScrollCarousel(main, {
  16. slideSelector: ".carousel-container",
  17. direction: "rtl", // ltr
  18. speed: 5,
  19. margin: 24,
  20. // autoplay: true,
  21. });
  22. }, []);
  23.  
  24. //convert date to 'Month Year' string..
  25. let convertDate = (start_date) => {
  26. let dateObj = new Date(start_date);
  27.  
  28. let month = dateObj.toLocaleString("en-US", { month: "long" });
  29. let year = dateObj.getFullYear();
  30.  
  31. return `${month} ${year}`;
  32. };
  33.  
  34. // Sort the anime_data array based on start_date in descending order
  35. // this way, we get most recent by start_date, elements. and put them in other list, which shows latest 10 by start_date
  36. const sortedAnimeData = anime_data.sort((a, b) => {
  37. const dateA = new Date(a.start_date);
  38. const dateB = new Date(b.start_date);
  39. return dateB - dateA; // Sort in descending order (from newest to oldest date)
  40. });
  41.  
  42. // this way, we get most recent by start_date, elements. and put them in other list, which shows latest 10 by start_date
  43. top10UpcomingAnime = sortedAnimeData.slice(0, 10);
  44.  
  45. return (
  46. <>
  47. <div className="line"> </div>
  48.  
  49. <div className="main flex flex-col ">
  50. {/* this is just container for showing title and then carousel */}
  51. <div className="small_header ml-4 md:ml-6 lg:ml-10 mt-6 ">
  52. {/* check index.css, for global use, vertical rectangle.. */}
  53.  
  54. <div className="secondary-left-line">
  55. <h3>Top Upcoming animes:</h3>
  56. <p>Season - fall 2023</p>
  57. </div>
  58. </div>
  59. <div className="carousel-container">
  60. {/* container for items*/}
  61.  
  62. <div className="flex flex-row gap-3 justify-center mt-2">
  63. {/* show items (render from object) dynamically render items */}
  64.  
  65. {/*only prop that will be passed is 'anime_id'. because on DetailedPage, it will be fetched again from database for all info. And 'anime_id' because this if for 'upcoming animes'. it can be manga as well .. just say to include it if needed */}
  66.  
  67.  
  68.  
  69.  
  70.  
  71. {top10UpcomingAnime.map((item, index) => (
  72. <Link
  73. to="/detailspage"
  74. state={{ id: item.anime_id, anime: true }}
  75. key={item.anime_id}
  76. >
  77.  
  78.  
  79.  
  80. <div
  81. className="item flex flex-col justify-start items-stretch "
  82. key={index}
  83.  
  84.  
  85. >
  86.  
  87. {/* image */}
  88. {/* to scale it well you need to put in <div> contaiener. remove width and height and put ' object-fit: contain;' and on <div> put 'overflow: hidden;'*/}
  89. <div className="item_div">
  90. <img src={item.image} alt={item.title} />
  91. </div>
  92. <div className="line"> </div>
  93.  
  94. <div className="inner flex flex-col gap-2 justify-start items-start ml-2 mt-2 md:ml-4 md:mt-4">
  95. <h1>{item.title}</h1>
  96. <p>Season {item.seasons}</p>
  97. </div>
  98.  
  99. <p className="release_date md:mt-16 mb-4 mt-4 md:mt-26 mb:mb-8 ml-2 md:ml-4 ">
  100. {convertDate(item.start_date)}{" "}
  101. </p>
  102. </div>
  103. </Link>
  104. ))}
  105. </div>
  106. </div>
  107. </div>
  108. </>
  109. );
  110. };
  111.  
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement