pollo/src/pages/dashboard/index.tsx

103 lines
2.9 KiB
TypeScript
Raw Normal View History

2023-08-12 17:12:42 -06:00
import type { NextPage } from "next";
2023-07-11 17:22:54 -06:00
import Head from "next/head";
import RoomList from "~/components/RoomList";
import Link from "next/link";
2023-07-11 17:22:54 -06:00
import { useEffect, useState } from "react";
import { FaShieldAlt } from "react-icons/fa";
2023-07-29 13:18:14 -06:00
import { GiStarFormation } from "react-icons/gi";
2023-08-12 17:12:42 -06:00
import { useUser } from "@clerk/nextjs";
import { isAdmin, isVIP } from "~/utils/helpers";
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">
<HomePageBody />
</div>
</>
);
};
export default Home;
2023-08-08 22:36:43 -06:00
const HomePageBody = () => {
2023-08-12 17:12:42 -06:00
const { isLoaded, user } = useUser();
const [joinRoomTextBox, setJoinRoomTextBox] = useState<string>("");
const [tabIndex, setTabIndex] = useState<number>();
useEffect(() => {
const tabIndexLocal = localStorage.getItem(`dashboardTabIndex`);
setTabIndex(tabIndexLocal !== null ? Number(tabIndexLocal) : 0);
2023-08-12 17:12:42 -06:00
}, [tabIndex, user]);
2023-08-12 17:12:42 -06:00
return !isLoaded ? (
<div className="flex items-center justify-center">
<span className="loading loading-dots loading-lg"></span>
</div>
) : (
<>
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-08-12 17:12:42 -06:00
Hi, {user?.fullName}!{" "}
{isVIP(user?.publicMetadata) && (
<FaShieldAlt className="inline-block text-primary" />
2023-07-29 13:18:14 -06:00
)}
{isAdmin(user?.publicMetadata) && (
2023-07-29 13:18:14 -06:00
<GiStarFormation className="inline-block text-secondary" />
)}
</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={() => {
setTabIndex(0);
localStorage.setItem("dashboardTabIndex", "0");
2023-07-29 13:18:14 -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={() => {
setTabIndex(1);
localStorage.setItem("dashboardTabIndex", "1");
2023-07-29 13:18:14 -06:00
}}
>
Room List
</a>
</div>
2023-07-29 13:18:14 -06:00
{tabIndex === 0 && (
<>
<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) => {
console.log(event.target.value);
setJoinRoomTextBox(event.target.value);
2023-07-29 13:18:14 -06:00
}}
/>
<Link
2023-07-29 13:18:14 -06:00
href={joinRoomTextBox.length > 0 ? `/room/${joinRoomTextBox}` : "/"}
className="btn btn-secondary"
>
Join Room
</Link>
</>
2023-07-29 13:18:14 -06:00
)}
2023-07-29 13:18:14 -06:00
{tabIndex === 1 && <RoomList />}
</>
);
};