aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhongheng Liu <z.liu@outlook.com.gr>2024-12-23 13:09:11 +0200
committerZhongheng Liu <z.liu@outlook.com.gr>2024-12-23 13:09:11 +0200
commitdda678ed57bc69d7f6167a1e17dc9e6a2ce07789 (patch)
treed3c315d7a0e5d8961870e41174996520b19ba7d5
parent6d124c10b111b9d376269b7d6bea81c95b8a12f4 (diff)
downloadproteinpedia-next-main.tar.gz
proteinpedia-next-main.tar.bz2
proteinpedia-next-main.zip
chore: misc formattingHEADmain
-rw-r--r--src/app/admin/page.tsx6
-rw-r--r--src/app/components/Page.tsx177
2 files changed, 92 insertions, 91 deletions
diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx
index 55672ef..68bdfb5 100644
--- a/src/app/admin/page.tsx
+++ b/src/app/admin/page.tsx
@@ -16,9 +16,9 @@ export default function AdminPage() {
(document.getElementById("admin-password") as HTMLInputElement).value,
}),
});
- const requestBody = await dataRaw.json() as AdminLoginResponse;
- if (requestBody.success) {
- location.assign(`/api/backend?auth=${requestBody.authKey}`);
+ const responseBody = await dataRaw.json() as AdminLoginResponse;
+ if (responseBody.success) {
+ location.assign(`/api/backend?auth=${responseBody.authKey}`);
} else alert("ERROR[1001] Authentication failure");
};
return (
diff --git a/src/app/components/Page.tsx b/src/app/components/Page.tsx
index 4f1b48f..066ae98 100644
--- a/src/app/components/Page.tsx
+++ b/src/app/components/Page.tsx
@@ -1,102 +1,103 @@
"use client";
import "./Page.css";
import {
- PageData,
- PageContentType,
- SectionContent,
- TextContent,
+ PageContentType,
+ PageData,
+ SectionContent,
+ TextContent,
} from "../types/pageTypes";
import { redirect } from "next/navigation";
import { useEffect, useState } from "react";
const Page = ({ pageKey }: { pageKey: string }): JSX.Element => {
- const [pageData, setPageData] = useState<PageData>();
- const scanSection = (section: SectionContent, depth: number) => {
- if (section.type == PageContentType.Text) {
- console.log("Triggering TextContent logic...");
+ const [pageData, setPageData] = useState<PageData>();
+ const scanSection = (section: SectionContent, depth: number) => {
+ if (section.type == PageContentType.Text) {
+ console.log("Triggering TextContent logic...");
- const texts: JSX.Element[] = [];
- (section.content as TextContent[]).forEach((textContent) => {
- console.log(<p>{textContent.content}</p>);
+ const texts: JSX.Element[] = [];
+ (section.content as TextContent[]).forEach((textContent) => {
+ console.log(<p>{textContent.content}</p>);
- texts.push(<p>{textContent.content}</p>);
- });
- return <>{texts}</>;
- } else if (section.type == PageContentType.Section) {
- console.log("Triggering SectionContent logic...");
+ texts.push(<p>{textContent.content}</p>);
+ });
+ return <>{texts}</>;
+ } else if (section.type == PageContentType.Section) {
+ console.log("Triggering SectionContent logic...");
- const elements: JSX.Element[] = [];
- section.content.forEach((section, index) => {
- if (section.type == PageContentType.Text) {
- elements.push(
- <p key={`${depth}*${index}`}>
- {(section as TextContent).content}
- </p>
- );
- } else if (section.type == PageContentType.Section) {
- elements.push(
- scanSection(section as SectionContent, depth + 1)
- );
- }
- });
- return (
- <section>
- <p className={`heading heading-${depth}`}>
- {section.heading}
- </p>
- {elements}
- </section>
- );
- } else {
- throw new Error("pageType not defined!");
- }
- };
- if (pageKey != "amino_acids") {
+ const elements: JSX.Element[] = [];
+ section.content.forEach((section, index) => {
+ if (section.type == PageContentType.Text) {
+ elements.push(
+ <p key={`${depth}*${index}`}>
+ {(section as TextContent).content}
+ </p>,
+ );
+ } else if (section.type == PageContentType.Section) {
+ elements.push(
+ scanSection(section as SectionContent, depth + 1),
+ );
+ }
+ });
+ return (
+ <section>
+ <p className={`heading heading-${depth}`}>
+ {section.heading}
+ </p>
+ {elements}
+ </section>
+ );
+ } else {
+ throw new Error("pageType not defined!");
+ }
+ };
+ /*if (pageKey != "amino_acids") {
redirect("/error/404");
- }
- useEffect(() => {
- fetch(`/api/pages?key=${pageKey}`)
- .then((value) => {
- return value.json();
- })
- .then((response) => {
- if (response.success === false) {
- console.log("not found");
- } else {
- setPageData(response.document);
- }
- });
- }, []);
- const components: JSX.Element[] = [];
- pageData?.content.forEach((content, index) => {
- if (content.type === PageContentType.Text) {
- components.push(
- <p key={index}>{(content as TextContent).content}</p>
- );
- } else {
- components.push(scanSection(content as SectionContent, 0));
- }
- });
- const element =
- pageData && components ? (
- <>
- <p className="page-title">{pageData.title}</p>
- {components}
- <hr></hr>
- <p className="footnote">{pageData.footnotes}</p>
- <p className="copyright">
- Copyright &copy; 2024-2025 Proteinpedia Foundation
- </p>
- </>
- ) : (
- <>
- <div className="d-flex justify-content-center vh-100">
- <div className="spinner-border" role="status">
- <span className="visually-hidden">Loading...</span>
- </div>
- </div>
- </>
- );
- return <div className="page">{element}</div>;
+ } */
+ useEffect(() => {
+ fetch(`/api/pages?key=${pageKey}`)
+ .then((value) => {
+ return value.json();
+ })
+ .then((response) => {
+ if (response.success === false) {
+ console.log("not found");
+ } else {
+ setPageData(response.document);
+ }
+ });
+ }, []);
+ const components: JSX.Element[] = [];
+ pageData?.content.forEach((content, index) => {
+ if (content.type === PageContentType.Text) {
+ components.push(
+ <p key={index}>{(content as TextContent).content}</p>,
+ );
+ } else {
+ components.push(scanSection(content as SectionContent, 0));
+ }
+ });
+ const element = pageData && components
+ ? (
+ <>
+ <p className="page-title">{pageData.title}</p>
+ {components}
+ <hr></hr>
+ <p className="footnote">{pageData.footnotes}</p>
+ <p className="copyright">
+ Copyright &copy; 2024-2025 Proteinpedia Foundation
+ </p>
+ </>
+ )
+ : (
+ <>
+ <div className="d-flex justify-content-center vh-100">
+ <div className="spinner-border" role="status">
+ <span className="visually-hidden">Loading...</span>
+ </div>
+ </div>
+ </>
+ );
+ return <div className="page">{element}</div>;
};
export default Page;