diff --git a/components/SelectMode.tsx b/components/SelectMode.tsx index 11fe74a..956b042 100644 --- a/components/SelectMode.tsx +++ b/components/SelectMode.tsx @@ -1,7 +1,7 @@ "use client"; import { Mode } from "@prisma/client"; -import { useContext, useState } from "react"; +import { useContext } from "react"; import { ErrorContext } from "./App"; import { useSWRConfig } from "swr"; @@ -9,23 +9,20 @@ export default function SelectMode({ mode }: { mode: Mode }) { const modes = Object.values(Mode); const { setError } = useContext(ErrorContext); const { mutate } = useSWRConfig(); - const [isLoading, setLoading] = useState( - Object.fromEntries(Object.values(Mode).map((m) => [m, false])), - ); - async function onClick(e: Mode) { - setLoading((prev) => ({ ...prev, [e]: true })); + async function onChange(e: any) { + if (mode === e.target.value) { + return; + } const res = await fetch("/api/party", { method: "PATCH", headers: { "Content-type": "application/json", }, - body: JSON.stringify({ mode: e }), + body: JSON.stringify({ mode: e.target.value }), }); - setLoading((prev) => ({ ...prev, [e]: false })); - if (!res.ok) { setError(await res.json()); return; @@ -35,42 +32,16 @@ export default function SelectMode({ mode }: { mode: Mode }) { } return ( -
+
Mode: -
-
- {mode} - - - -
-
    - {modes.map((e) => ( -
  • - -
  • - ))} -
-
+
); }