2023-05-31 21:53:19 -06:00
|
|
|
import type { GetServerSideProps, NextPage } from "next";
|
|
|
|
import { useSession } from "next-auth/react";
|
2023-07-11 17:22:54 -06:00
|
|
|
import Head from "next/head";
|
2023-05-31 21:49:25 -06:00
|
|
|
|
|
|
|
import RoomList from "~/components/RoomList";
|
|
|
|
|
|
|
|
import Link from "next/link";
|
2023-07-11 17:22:54 -06:00
|
|
|
import { useEffect, useState } from "react";
|
2023-05-31 21:49:25 -06:00
|
|
|
import { FaShieldAlt } from "react-icons/fa";
|
|
|
|
import { getServerAuthSession } from "~/server/auth";
|
2023-07-29 13:18:14 -06:00
|
|
|
import { GiStarFormation } from "react-icons/gi";
|
2023-05-31 21:49:25 -06:00
|
|
|
|
|
|
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
|
|
|
const session = await getServerAuthSession(ctx);
|
|
|
|
|
|
|
|
// Redirect to login if not signed in
|
|
|
|
if (!session) {
|
|
|
|
return {
|
|
|
|
redirect: {
|
|
|
|
destination: `/api/auth/signin?callbackUrl=${ctx.resolvedUrl}`,
|
|
|
|
permanent: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return session if logged in
|
|
|
|
return {
|
|
|
|
props: { session },
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const Home: NextPage = () => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Head>
|
|
|
|
<title>Sprint Padawan</title>
|
|
|
|
<meta name="description" content="Plan. Sprint. Repeat." />
|
|
|
|
</Head>
|
2023-06-05 16:56:28 -06:00
|
|
|
<div className="flex flex-col text-center items-center justify-center px-4 py-16 gap-4">
|
2023-05-31 21:49:25 -06:00
|
|
|
<HomePageBody />
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Home;
|
|
|
|
|
2023-08-08 22:36:43 -06:00
|
|
|
const HomePageBody = () => {
|
2023-05-31 21:49:25 -06:00
|
|
|
const { data: sessionData } = useSession();
|
|
|
|
const [joinRoomTextBox, setJoinRoomTextBox] = useState<string>("");
|
2023-06-05 12:37:10 -06:00
|
|
|
const [tabIndex, setTabIndex] = useState<number>();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const tabIndexLocal = localStorage.getItem(`dashboardTabIndex`);
|
|
|
|
setTabIndex(tabIndexLocal !== null ? Number(tabIndexLocal) : 0);
|
|
|
|
}, [tabIndex, sessionData]);
|
2023-05-31 21:49:25 -06:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-06-05 16:56:28 -06:00
|
|
|
<h1 className="flex flex-row flex-wrap text-center justify-center items-center gap-1 text-4xl font-bold mx-auto">
|
2023-07-29 13:18:14 -06:00
|
|
|
Hi, {sessionData?.user.name}!{" "}
|
2023-07-29 21:38:59 -06:00
|
|
|
{sessionData?.user.isAdmin && (
|
2023-05-31 21:49:25 -06:00
|
|
|
<FaShieldAlt className="inline-block text-primary" />
|
2023-07-29 13:18:14 -06:00
|
|
|
)}
|
2023-07-29 21:38:59 -06:00
|
|
|
{sessionData?.user.isVIP && (
|
2023-07-29 13:18:14 -06:00
|
|
|
<GiStarFormation className="inline-block text-secondary" />
|
|
|
|
)}
|
2023-05-31 21:49:25 -06:00
|
|
|
</h1>
|
|
|
|
<div className="tabs tabs-boxed border-2 border-cyan-500 mb-4">
|
|
|
|
<a
|
|
|
|
className={
|
|
|
|
tabIndex === 0 ? "tab no-underline tab-active" : "tab no-underline"
|
|
|
|
}
|
2023-07-29 13:18:14 -06:00
|
|
|
onClick={() => {
|
2023-06-05 12:37:10 -06:00
|
|
|
setTabIndex(0);
|
|
|
|
localStorage.setItem("dashboardTabIndex", "0");
|
2023-07-29 13:18:14 -06:00
|
|
|
}}
|
2023-05-31 21:49:25 -06:00
|
|
|
>
|
|
|
|
Join a Room
|
|
|
|
</a>
|
|
|
|
<a
|
|
|
|
className={
|
|
|
|
tabIndex === 1 ? "tab no-underline tab-active" : "tab no-underline"
|
|
|
|
}
|
2023-07-29 13:18:14 -06:00
|
|
|
onClick={() => {
|
2023-06-05 12:37:10 -06:00
|
|
|
setTabIndex(1);
|
|
|
|
localStorage.setItem("dashboardTabIndex", "1");
|
2023-07-29 13:18:14 -06:00
|
|
|
}}
|
2023-05-31 21:49:25 -06:00
|
|
|
>
|
|
|
|
Room List
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
|
2023-07-29 13:18:14 -06:00
|
|
|
{tabIndex === 0 && (
|
2023-05-31 21:49:25 -06:00
|
|
|
<>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="Enter Room ID"
|
|
|
|
className="input input-bordered input-primary mb-4"
|
2023-07-29 13:18:14 -06:00
|
|
|
onChange={(event) => {
|
2023-05-31 21:49:25 -06:00
|
|
|
console.log(event.target.value);
|
|
|
|
setJoinRoomTextBox(event.target.value);
|
2023-07-29 13:18:14 -06:00
|
|
|
}}
|
2023-05-31 21:49:25 -06:00
|
|
|
/>
|
|
|
|
<Link
|
2023-07-29 13:18:14 -06:00
|
|
|
href={joinRoomTextBox.length > 0 ? `/room/${joinRoomTextBox}` : "/"}
|
2023-05-31 21:49:25 -06:00
|
|
|
className="btn btn-secondary"
|
|
|
|
>
|
|
|
|
Join Room
|
|
|
|
</Link>
|
|
|
|
</>
|
2023-07-29 13:18:14 -06:00
|
|
|
)}
|
2023-05-31 21:49:25 -06:00
|
|
|
|
2023-07-29 13:18:14 -06:00
|
|
|
{tabIndex === 1 && <RoomList />}
|
2023-05-31 21:49:25 -06:00
|
|
|
</>
|
|
|
|
);
|
2023-06-14 12:59:20 -06:00
|
|
|
};
|