aboutsummaryrefslogtreecommitdiff
path: root/pages/testing.js
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-04-17 14:29:11 +0700
committerFactiven <[email protected]>2023-04-17 14:29:11 +0700
commit89aac9ff49b696e77019e70ed5f9d91e4a112072 (patch)
tree48bae9c98cb4cb61ef561fbf3b45040ce9820c38 /pages/testing.js
parent2nd fixes (diff)
downloadmoopa-89aac9ff49b696e77019e70ed5f9d91e4a112072.tar.xz
moopa-89aac9ff49b696e77019e70ed5f9d91e4a112072.zip
3rd fixes
Diffstat (limited to 'pages/testing.js')
-rw-r--r--pages/testing.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/pages/testing.js b/pages/testing.js
new file mode 100644
index 0000000..63d5e96
--- /dev/null
+++ b/pages/testing.js
@@ -0,0 +1,92 @@
+import { signIn, signOut, useSession } from "next-auth/react";
+import { getServerSession } from "next-auth/next";
+import { authOptions } from "./api/auth/[...nextauth]";
+const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "http://localhost:3000";
+
+export default function Testing({ sesi, data, progress, statusWatch }) {
+ const { data: session, status } = useSession();
+ // console.log(session.user.id);
+ async function handleUpdate() {
+ // const data = ;
+ const res = await fetch("/api/update-user", {
+ method: "POST",
+ body: JSON.stringify({
+ name: session?.user.name,
+ newData: {
+ recentWatch: {
+ id: parseInt(9280220),
+ title: {
+ romaji: "something title here",
+ },
+ description:
+ "lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quod.",
+ coverImage: {
+ extraLarge: "this should be an image url",
+ },
+ episode: {
+ id: "first-id-yeah",
+ time: 12344,
+ },
+ },
+ },
+ }),
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+ // const data = await res.json(); // parse the response body as JSON
+ // console.log(data.dat.id);
+ console.log(res.status);
+ }
+
+ console.log(statusWatch);
+ return (
+ <div>
+ <button onClick={() => handleUpdate()}>Click for update</button>
+ {!session && (
+ <button onClick={() => signIn("AniListProvider")}>LOGIN</button>
+ )}
+ {session && <button onClick={() => signOut()}>LOGOUT</button>}
+ </div>
+ );
+}
+
+export async function getServerSideProps(context) {
+ const session = await getServerSession(context.req, context.res, authOptions);
+
+ const res = await fetch(`${baseUrl}/api/get-media`, {
+ method: "POST",
+ body: JSON.stringify({
+ username: session?.user.name,
+ }),
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+
+ const prog = await res.json();
+
+ const gat = prog.lists.map((item) => item.entries);
+ const git = gat.map((item) => item.find((item) => item.media.id === 130003));
+ const gut = git.find((item) => item?.media.id === 130003);
+
+ let progress = null;
+ let statusWatch = "CURRENT";
+
+ if (gut?.status === "COMPLETED") {
+ statusWatch = "REPEATING";
+ }
+
+ if (gut) {
+ progress = gut?.progress;
+ }
+
+ return {
+ props: {
+ sesi: session,
+ data: gut || null,
+ progress: progress,
+ statusWatch: statusWatch,
+ },
+ };
+}