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; } interface ChildProps { headings: Heading[]; currentIndex: number; link: Link; } export const OrganizedContent: React.FC = ({ headings, currentIndex, children, link: Link, }) => { const isReadAll = headings[currentIndex].name === "Read All"; const isMobile = false; const readAllContent = headings .filter((heading: { name: string }) => heading.name !== "Read All") .map((heading) => (

{heading.name}

{heading.content}
)); if (isMobile) { return (
{isReadAll ? (
{readAllContent}
) : (

{headings[currentIndex].name}

)} {children}
); } else { return (
); } }; const Nav: React.FC = ({ headings, currentIndex, link: Link }) => { return (
{headings.map((heading, index) => (
{index === currentIndex && ( )} {heading.name}
))}
); }; const Footer: React.FC = ({ headings, currentIndex, 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 (
{prevHeading && (
Previous
{prevHeading.name}
)}
{nextHeading && (
Next
{nextHeading.name}
)}
); };