From b365d89a11adf40d37b78292f121b890e960d0e8 Mon Sep 17 00:00:00 2001 From: Factiven Date: Thu, 13 Apr 2023 16:03:57 +0700 Subject: update 2nd --- pages/index.js | 281 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 155 insertions(+), 126 deletions(-) (limited to 'pages/index.js') diff --git a/pages/index.js b/pages/index.js index 7c26f0b..d75cb0f 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,4 +1,3 @@ -import { MdChevronLeft, MdChevronRight } from "react-icons/md"; import { aniListData } from "../lib/AniList"; import React, { useState, useEffect } from "react"; import ReactHtmlParser from "kt-react-html-parser"; @@ -9,12 +8,90 @@ import Image from "next/image"; import Content from "../components/hero/content"; import { useRouter } from "next/router"; -export default function Home({ detail, populars, topDesc }) { +import { useSession, signIn } from "next-auth/react"; + +export function Navigasi() { + const { data: session, status } = useSession(); + + const router = useRouter(); + + const handleFormSubmission = (inputValue) => { + router.push(`/search?hasil=${encodeURIComponent(inputValue)}`); + }; + + const handleKeyDown = async (event) => { + if (event.key === "Enter") { + event.preventDefault(); + const inputValue = event.target.value; + handleFormSubmission(inputValue); + } + }; + return ( + <> + {/* NAVBAR PC */} +
+
+
+ + moopa + +
    + +
  • AniList Index
  • + + +
  • Manga
  • + +
  • Anime
  • + {status === "loading" &&
  • Loading...
  • } + {!session && ( +
  • + +
  • + )} + {session && ( +
  • + {/*
    imagine
    */} + My List +
  • + )} +
+
+
+
+ + + + +
+
+
+
+ + ); +} + +export default function Home({ detail, populars }) { + const { data: session, status } = useSession(); const [isVisible, setIsVisible] = useState(false); const [recently, setRecently] = useState(null); - const popular = populars.data; + const popular = populars?.data; const data = detail.data[0]; - const router = useRouter(); + + const greeting = getGreeting(); const handleShowClick = () => { setIsVisible(true); @@ -34,32 +111,6 @@ export default function Home({ detail, populars, topDesc }) { fetchData(); }, []); - function handleRemove() { - localStorage.removeItem("recentWatch"); - setRecently(null); - } - - const slideLeft = () => { - var slider = document.getElementById("recentslider"); - slider.scrollLeft = slider.scrollLeft - 500; - }; - const slideRight = () => { - var slider = document.getElementById("recentslider"); - slider.scrollLeft = slider.scrollLeft + 500; - }; - - const handleFormSubmission = (inputValue) => { - router.push(`/search?hasil=${encodeURIComponent(inputValue)}`); - }; - - const handleKeyDown = async (event) => { - if (event.key === "Enter") { - event.preventDefault(); - const inputValue = event.target.value; - handleFormSubmission(inputValue); - } - }; - return ( <> @@ -80,6 +131,8 @@ export default function Home({ detail, populars, topDesc }) { /> + + {/* NAVBAR */}
{!isVisible && ( + )} {isVisible && (
@@ -227,47 +311,17 @@ export default function Home({ detail, populars, topDesc }) { )}
-
-
-
-
-

- moopa -

-
    - -
  • AniList Index
  • - - -
  • Manga
  • - -
  • Anime
  • -
-
-
-
- - - - -
-
-
-
+
+ {/* PC / TABLET */} -
-
+
+
-

+

{data.title.english || data.title.romaji || data.title.native}

-
+
{ReactHtmlParser(data.description)}
@@ -277,84 +331,48 @@ export default function Home({ detail, populars, topDesc }) { legacyBehavior className="flex" > - + START WATCHING
-
-
+
+
{data.title.english
+ {session && ( +
+
+ {greeting}, {session?.user.name} +
+
+ )} + {/* Mobile */} -
+
{recently && ( -
-
-

- Recently Watched -

-
handleRemove()} - > - Clear all -
-
-
- -
- {recently.map((anime, index) => { - const url = encodeURIComponent(anime.title); - - return ( - - {anime.title - - ); - })} -
- -
-
+ )} {detail && ( @@ -390,16 +408,27 @@ export async function getServerSideProps({ req, res }) { page: 1, }); const genreDetail = await aniListData({ sort: "TYPE", page: 1 }); - const newTrend = await trendingDetail.props; - const trends = newTrend.data[0]; - const topDesc = trends.description.slice(0, 350) + "..."; return { props: { - topDesc: topDesc, genre: genreDetail.props, detail: trendingDetail.props, populars: popularDetail.props, }, }; } + +function getGreeting() { + const time = new Date().getHours(); + let greeting = ""; + + if (time >= 5 && time < 12) { + greeting = "Good morning"; + } else if (time >= 12 && time < 18) { + greeting = "Good afternoon"; + } else { + greeting = "Good evening"; + } + + return greeting; +} -- cgit v1.2.3