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}
)}
); };