diff --git a/components/OrganizedContent.tsx b/components/OrganizedContent.tsx index aa1a94c1..0bc80c42 100644 --- a/components/OrganizedContent.tsx +++ b/components/OrganizedContent.tsx @@ -1,106 +1,140 @@ -import React, { ReactNode, ComponentType } from "react"; -import styles from "./OrganizedContent.module.css"; - -export interface LinkProps { - children: string | ReactNode | (string | ReactNode)[] - url: string -} - -type Link = ComponentType - - -interface Heading { - name: string; - url: string; -} - -interface Props { - headings: Heading[]; - currentIndex: number; - link: Link - children: ReactNode; -} - -export const OrganizedContent: React.FC = ({ - headings, - currentIndex, - children, - link: Link, -}) => { - const isReadAll = headings[currentIndex].name === "Read All" - const prevHeading = currentIndex > 0 && headings[currentIndex - 1].name !== "Read All" ? headings[currentIndex - 1] : undefined; - const nextHeading = - currentIndex < headings.length - 1 && !isReadAll ? headings[currentIndex + 1] : undefined; - - return ( -
-
- {headings.map((heading, index) => ( -
-
- {heading.name} -
-
-
- ))} -
- -
- {!isReadAll && -

{headings[currentIndex].name}

} - {children} -
- {prevHeading && ( -
- -
- - - -
-
Previous
-
{prevHeading.name}
-
-
- -
- )} -
- {nextHeading && ( -
- -
-
-
Next
-
{nextHeading.name}
-
- - - -
- -
- )} -
-
-
- ); -}; +import React, { ReactNode, ComponentType } from "react"; +import styles from "./OrganizedContent.module.css"; + +export interface LinkProps { + children: string | ReactNode | (string | ReactNode)[]; + url: string; +} + +type Link = ComponentType; + +interface Heading { + name: string; + url: string; + content: ReactNode; +} + +interface Props { + headings: Heading[]; + currentIndex: number; + link: Link; + children: ReactNode; +} + +export const OrganizedContent: React.FC = ({ + headings, + currentIndex, + children, + link: Link, +}) => { + const isReadAll = headings[currentIndex].name === "Read All"; + const prevHeading = + currentIndex > 0 && headings[currentIndex - 1].name !== "Read All" + ? headings[currentIndex - 1] + : undefined; + const nextHeading = + currentIndex < headings.length - 1 && !isReadAll + ? headings[currentIndex + 1] + : undefined; + + return ( +
+
+ {headings.map((heading, index) => ( +
+
+ {heading.name} +
+
+
+ ))} +
+ +
+ {!isReadAll ? ( +

+ {headings[currentIndex].name} +

+ ) : ( +
+ {headings + .filter( + (heading: { name: string }) => heading.name !== "Read All" + ) + .map((heading) => ( +
+

{heading.name}

+ {heading.content} +
+ ))} +
+ )} + {children} +
+ {prevHeading && ( +
+ +
+ + + +
+
Previous
+
+ {prevHeading.name} +
+
+
+ +
+ )} +
+ {nextHeading && ( +
+ +
+
+
+ Next +
+
+ {nextHeading.name} +
+
+ + + +
+ +
+ )} +
+
+
+ ); +}; diff --git a/components/playground.tsx b/components/playground.tsx index e1cc9b63..91eab1f4 100644 --- a/components/playground.tsx +++ b/components/playground.tsx @@ -116,7 +116,6 @@ export function OrganizedContentDemo() { { name: "Consequences of Unacceptable Behavior", url: "d", - key: "d", content:
CODEY
, }, ]; @@ -124,8 +123,7 @@ export function OrganizedContentDemo() { const readAllSection = { name: "Read All", url: "readall", - key: "readall", - content:
CODEY FAN CLUB
, + content:
, }; sections = [readAllSection, ...sections];