diff --git a/src/app/ask/page.tsx b/src/app/ask/page.tsx new file mode 100644 index 0000000..c87e12d --- /dev/null +++ b/src/app/ask/page.tsx @@ -0,0 +1,169 @@ +/** + * @copyright nhcarrigan + * @license Naomi's Public License + * @author Naomi Carrigan + */ +"use client"; +import { useState, type ChangeEvent, type JSX } from "react"; +import { Rule } from "../../components/rule"; + +type Category = "question" | "compliment" | "confess" | "never"; + +const ColourMap: Record + = { + compliment: { + background: "#a6f1c6", + foreground: "#0f9d58", + }, + confess: { + background: "#f7c6d2", + foreground: "#b03060", + }, + never: { + background: "#f7e6c6", + foreground: "#b8860b", + }, + question: { + background: "#a6e6fc", + foreground: "#03779e", + }, + }; + +const TitleMap: Record = { + compliment: "Pay Naomi a Compliment", + confess: "Confess Your Sins to Naomi", + never: "Never Have I Ever?", + question: "Ask Naomi a Question", +}; + +const DescriptionMap: Record = { + compliment: + // eslint-disable-next-line stylistic/max-len + "Have you wanted to tell Naomi she's cute, but you've been too shy? Here's your chance!", + confess: + // eslint-disable-next-line stylistic/max-len + "Is there something weighing on your mind that you can't tell anyone else? Confess it here!", + never: + // eslint-disable-next-line stylistic/max-len + "What do you think Naomi has done that you haven't? Let's play a game of Never Have I Ever!", + question: "Do you have a question for Naomi? Ask it here!", +}; + +/** + * Renders the /ask page. + * @returns A React Component. + */ +const Ask = (): JSX.Element => { + const [ category, setCategory ] = useState("question"); + const [ question, setQuestion ] = useState(""); + const [ submitted, setSubmitted ] = useState(false); + const [ errored, setErrored ] = useState(false); + + const handleCategoryChange = ( + event: ChangeEvent, + ): void => { + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions + setCategory(event.target.value as Category); + }; + + const handleQuestionUpdate = ( + event: ChangeEvent, + ): void => { + setQuestion(event.target.value); + }; + + const submitForm = (): void => { + fetch("https://anon.nhcarrigan.com/api", { + body: JSON.stringify({ + category, + question, + }), + headers: { + "Content-Type": "application/json", + }, + method: "POST", + }).then((response) => { + if (response.ok) { + setSubmitted(true); + } else { + setErrored(true); + } + }). + catch(() => { + setErrored(true); + }); + }; + return ( +
+

{`Ask Me Anything!`}

+

+ {`This page allows you to anonymously ask any question you might wish! Once approved and answered, your question and our response will be visible in our `} + {`Discord`} + {`!`} +

+ + {!submitted && !errored &&
+

{TitleMap[category]}

+

{DescriptionMap[category]}

+
+ +