Files
przekroj/pages/index.js
2022-02-17 14:01:07 +01:00

98 lines
2.6 KiB
JavaScript

import Head from "next/head";
import styles from "../styles/Home.module.css";
import Header from "./templates/header";
import Nav from "./templates/nav";
import Content from "./templates/content";
import Footer from "./templates/footer";
import { useState } from "react";
import { useSession, signIn, signOut } from "next-auth/react";
export default function Home() {
const { data: session } = useSession();
const [profil, setProfil] = useState();
const py = (e, profil) => {
e.preventDefault();
fetch("/api/spawn", {
method: "POST",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
},
body: JSON.stringify({ profil: profil }),
}).then((res) => {
console.log("data from api: ", res);
document.getElementById("down").click();
});
};
if (session) {
return (
<div className={styles.container}>
<Head>
<title>Wastpol</title>
<meta name="description" content="Wastpol" />
<link rel="icon" href="/icon.png" />
</Head>
<div className="flex justify-between">
<Nav />
<div className="flex">
<h3 className="px-3 py-2 place-self-end">
Zalogowano jako {session.user.email}
</h3>
<button
onClick={() => signOut()}
className="p-2 bg-slate-200 rounded-md place-self-end"
>
Wyloguj
</button>
</div>
</div>
<main className={styles.main}>
<Header />
<textarea
id="profil"
className="bg-gray-100 h-96 w-96"
onChange={(e) => {
console.log(e.target.value);
setProfil(e.target.value);
}}
></textarea>
<button
onClick={(e) => {
py(e, profil);
}}
>
Generuj
</button>
<a href="test.dxf" download="test.dxf" id="down">
{" "}
</a>
</main>
<Footer />
</div>
);
}
return (
<div className="grid place-items-center h-screen">
<Head>
<title>Wastpol</title>
<meta name="description" content="Wastpol" />
<link rel="icon" href="/icon.png" />
</Head>
<div className="flex justify-center">
<h2 className="p-2">Nie zalogowano</h2>
<br></br>
<button
onClick={() => signIn()}
className="p-2 bg-slate-200 rounded-md"
>
Zaloguj
</button>
</div>
</div>
);
}