pollo/src/app/dashboard/page.tsx

98 lines
2.7 KiB
TypeScript
Raw Normal View History

2023-08-27 23:57:17 -06:00
"use client";
2023-08-31 00:14:20 -06:00
import RoomList from "@/app/_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";
2023-08-31 00:14:20 -06:00
import { isAdmin, isVIP } from "@/utils/helpers";
2023-08-28 12:33:06 -06:00
export const dynamic = "force-dynamic";
2023-08-29 18:14:54 -06:00
const Home = () => {
return (
2023-08-29 18:14:54 -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}!{" "}
2023-08-14 12:56:22 -06:00
{isAdmin(user?.publicMetadata) && (
<FaShieldAlt className="inline-block text-primary" />
2023-07-29 13:18:14 -06:00
)}
2023-08-14 12:56:22 -06:00
{isVIP(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 />}
</>
);
};