diff --git a/src/app/ask/page.tsx b/src/app/ask/page.tsx
index c87e12d..02d8371 100644
--- a/src/app/ask/page.tsx
+++ b/src/app/ask/page.tsx
@@ -4,7 +4,7 @@
* @author Naomi Carrigan
*/
"use client";
-import { useState, type ChangeEvent, type JSX } from "react";
+import { useEffect, useState, type ChangeEvent, type JSX } from "react";
import { Rule } from "../../components/rule";
type Category = "question" | "compliment" | "confess" | "never";
@@ -49,6 +49,12 @@ const DescriptionMap: Record = {
question: "Do you have a question for Naomi? Ask it here!",
};
+interface DataRecord {
+ category: Category;
+ question: string;
+ answer: string;
+}
+
/**
* Renders the /ask page.
* @returns A React Component.
@@ -58,6 +64,20 @@ const Ask = (): JSX.Element => {
const [ question, setQuestion ] = useState("");
const [ submitted, setSubmitted ] = useState(false);
const [ errored, setErrored ] = useState(false);
+ const [ history, setHistory ] = useState>([]);
+
+ useEffect(() => {
+ fetch("https://anon.nhcarrigan.com/recent").then(async(response) => {
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
+ const result = await response.json() as Array;
+ setHistory(result);
+ }).
+ catch((error: unknown) => {
+ // eslint-disable-next-line no-console
+ console.error(error);
+ setHistory([]);
+ });
+ }, []);
const handleCategoryChange = (
event: ChangeEvent,
@@ -82,13 +102,14 @@ const Ask = (): JSX.Element => {
"Content-Type": "application/json",
},
method: "POST",
- }).then((response) => {
- if (response.ok) {
- setSubmitted(true);
- } else {
- setErrored(true);
- }
}).
+ then((response) => {
+ if (response.ok) {
+ setSubmitted(true);
+ } else {
+ setErrored(true);
+ }
+ }).
catch(() => {
setErrored(true);
});
@@ -105,63 +126,87 @@ const Ask = (): JSX.Element => {
{`!`}
- {!submitted && !errored &&
- {TitleMap[category]}
- {DescriptionMap[category]}
-
- }
- { submitted
+ {!submitted && !errored
+ &&
+ {TitleMap[category]}
+ {DescriptionMap[category]}
+
+
+ }
+ {submitted
?
{`Question Submitted!`}
{`Your question has been submitted! Please wait for approval and response.`}
: null}
- { errored
+ {errored
?
{`Submission Error`}
{`An error occurred while submitting your question. Please try again later.`}
: null}
+
+ {`Prior Questions`}
+ {`Here are the most recently answered questions - if you want to see the full history, join our Discord!`}
+ {history.length > 0
+ ? history.map((record) => {
+ return (
+
+ {record.question}
+ {record.answer}
+
+ );
+ })
+ : {`No questions have been answered yet!`}
+ }
);
};