aboutsummaryrefslogtreecommitdiff
path: root/pages/index.js
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-04-13 18:24:09 +0700
committerFactiven <[email protected]>2023-04-13 18:24:09 +0700
commitc3d8c482531a767ee2e635b93eb0d6cd075247e8 (patch)
tree9d87de7586046755d64f86e93a776b6f4e725982 /pages/index.js
parentUpdate postcss.config.js (diff)
downloadmoopa-c3d8c482531a767ee2e635b93eb0d6cd075247e8.tar.xz
moopa-c3d8c482531a767ee2e635b93eb0d6cd075247e8.zip
Update 3rd
Diffstat (limited to 'pages/index.js')
-rw-r--r--pages/index.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/pages/index.js b/pages/index.js
index d75cb0f..871e63b 100644
--- a/pages/index.js
+++ b/pages/index.js
@@ -88,6 +88,7 @@ export default function Home({ detail, populars }) {
const { data: session, status } = useSession();
const [isVisible, setIsVisible] = useState(false);
const [recently, setRecently] = useState(null);
+ const [user, setUser] = useState(null);
const popular = populars?.data;
const data = detail.data[0];
@@ -102,14 +103,23 @@ export default function Home({ detail, populars }) {
};
useEffect(() => {
+ async function userData() {
+ if (!session) return;
+ const res = await fetch(`/api/get-user?userName=${session?.user.name}`);
+ const data = await res.json();
+ setUser(data);
+ }
function fetchData() {
const recent = JSON.parse(localStorage.getItem("recentWatch"));
if (recent) {
setRecently(recent);
}
}
+ userData();
fetchData();
- }, []);
+ }, [session]);
+
+ // console.log(user?.recentWatch.reverse());
return (
<>
@@ -344,7 +354,7 @@ export default function Home({ detail, populars }) {
<Image
draggable={false}
src={data.coverImage?.extraLarge || data.image}
- alt={data.title.english || data.title.romaji}
+ alt={`alt for ${data.title.english || data.title.romaji}`}
width={460}
height={662}
priority
@@ -367,11 +377,11 @@ export default function Home({ detail, populars }) {
<div className="md:mt-16 mt-12 flex flex-col items-center">
<div className="w-screen flex-none lg:w-[87%]">
- {recently && (
+ {session && user?.recentWatch && (
<Content
ids="recentlyWatched"
section="Recently Watched"
- data={recently}
+ data={user.recentWatch.reverse()}
/>
)}