diff --git a/actions/GameSystems/create.ts b/actions/GameSystems/create.ts deleted file mode 100644 index 72235c9..0000000 --- a/actions/GameSystems/create.ts +++ /dev/null @@ -1,23 +0,0 @@ -"use server"; - -import { auth } from "@/auth"; -import { prisma } from "@/prisma/prismaClient"; -import { isEmailVerified } from "@/util/isEmailVerified"; - -export const createGameSystem = async (name: string) => { - const session = await auth(); - if (!session?.user?.id) return null; - - if (!isEmailVerified(session.user.id)) return null; - - const { id } = await prisma.gameSystem.create({ - data: { - name, - authorId: session.user.id, - }, - select: { - id: true, - }, - }); - return id; -}; diff --git a/actions/GameSystems/deleteAll.ts b/actions/GameSystems/deleteAll.ts deleted file mode 100644 index c486aa6..0000000 --- a/actions/GameSystems/deleteAll.ts +++ /dev/null @@ -1,7 +0,0 @@ -"use server"; -import { prisma } from "@/prisma/prismaClient"; - -// DEV TOOL ONLY -export async function deleteAllGameSystems() { - await prisma.gameSystem.deleteMany(); -} diff --git a/actions/auth/index.ts b/actions/auth/index.ts index 4a19677..b971e38 100644 --- a/actions/auth/index.ts +++ b/actions/auth/index.ts @@ -1,5 +1,5 @@ "use server"; -import { signIn, signOut } from "@/auth"; +import { auth, signIn, signOut } from "@/auth"; export const signInWithDiscord = async () => { await signIn("discord"); @@ -10,3 +10,5 @@ export const signInWithCreds = async (formData: FormData) => { }; export const signOutOfApp = () => signOut(); + +export const getSession = async () => await auth(); diff --git a/app/game-systems/[id]/page.tsx b/app/game-systems/[id]/page.tsx index 7b71c2a..6d59dfc 100644 --- a/app/game-systems/[id]/page.tsx +++ b/app/game-systems/[id]/page.tsx @@ -1,3 +1,6 @@ +// import { setCurrentGameSystem } from "@/actions/GameSystems/client"; +import { setCurrentGameSystem } from "@/actions/GameSystems/client"; +import { auth } from "@/auth"; import { prisma } from "@/prisma/prismaClient"; import Link from "next/link"; @@ -32,6 +35,10 @@ export default async function GameSystem({ // }, }); + const session = await auth(); + + session?.user?.id && (await setCurrentGameSystem(session.user.id, id)); + return ( <>
diff --git a/app/game-systems/client.tsx b/app/game-systems/client.tsx index 81b625a..b727fc8 100644 --- a/app/game-systems/client.tsx +++ b/app/game-systems/client.tsx @@ -1,6 +1,6 @@ "use client"; -import { deleteAllGameSystems } from "@/actions/GameSystems/deleteAll"; +import { deleteAllGameSystems } from "@/actions/GameSystems/devactions"; import { DevTool } from "@/components/devtools/DevTool"; import { useRouter } from "next/navigation"; import { FC, PropsWithChildren } from "react"; diff --git a/app/game-systems/create.tsx b/app/game-systems/create.tsx index bcbbfb7..cf274e0 100644 --- a/app/game-systems/create.tsx +++ b/app/game-systems/create.tsx @@ -1,5 +1,5 @@ "use client"; -import { createGameSystem } from "@/actions/GameSystems/create"; +import { createGameSystem } from "@/actions/GameSystems"; import { useToast } from "@/components/toast"; import { redirect } from "next/navigation"; diff --git a/app/game-systems/page.tsx b/app/game-systems/page.tsx index 1d90f58..0f83198 100644 --- a/app/game-systems/page.tsx +++ b/app/game-systems/page.tsx @@ -2,8 +2,12 @@ import { prisma } from "@/prisma/prismaClient"; import CreateGameSystem from "./create"; import { GameSystemsClient } from "./client"; import Link from "next/link"; +import { setCurrentGameSystem } from "@/actions/GameSystems/client"; +import { auth } from "@/auth"; export default async function GameSystems() { + const session = await auth(); + session?.user?.id && (await setCurrentGameSystem(session.user.id)); const existingGameSystems = await prisma.gameSystem.findMany({ orderBy: { created: "asc", diff --git a/app/layout.tsx b/app/layout.tsx index c54e81d..366c014 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,13 +1,6 @@ import type { Metadata } from "next"; import { Roboto } from "next/font/google"; import "./globals.css"; -import { - BookOpenIcon, - CircleStackIcon, - Cog8ToothIcon, - PuzzlePieceIcon, - QuestionMarkCircleIcon, -} from "@heroicons/react/24/solid"; import Link from "next/link"; import { DevToolboxContextProvider } from "@/components/devtools/context"; import { RecoilRootClient } from "@/components/recoilRoot"; @@ -15,6 +8,10 @@ import { JotaiProvider } from "@/components/jotaiProvider"; import { Toaster } from "@/components/toast"; import { SessionProvider } from "next-auth/react"; import { User } from "@/components/user/index"; +import { getCurrentGameSystem } from "@/actions/GameSystems"; +import { Nav } from "@/components/nav"; +import { SSE } from "@/components/sse"; +import { auth } from "@/auth"; const roboto = Roboto({ subsets: ["latin"], weight: "400" }); @@ -23,38 +20,12 @@ export const metadata: Metadata = { description: "Rules and tools for tabletop games!", }; -export default function RootLayout({ +export default async function RootLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { - const navItems = [ - { - to: "/game-systems", - icon: PuzzlePieceIcon, - text: "Game Systems", - }, - { - to: "/schemas", - icon: CircleStackIcon, - text: "Schemas", - }, - { - to: "/publications", - icon: BookOpenIcon, - text: "Publications", - }, - { - to: "/settings", - icon: Cog8ToothIcon, - text: "Settings", - }, - { - to: "/help", - icon: QuestionMarkCircleIcon, - text: "How do?", - }, - ]; + const currentGame = await getCurrentGameSystem(); return ( @@ -65,19 +36,7 @@ export default function RootLayout({

Tabletop Commander

- +