|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import React from 'react'; |
| 4 | +import Image from 'next/image'; |
| 5 | +import { useState } from 'react'; |
| 6 | +import CircularButton from '../ui/components/circular-button'; |
| 7 | +import DownloadButton from '../ui/components/download-button'; |
| 8 | + |
| 9 | +const D4H_LOGO = '/cards/toolkits/data4health.svg'; |
| 10 | +const C4H_LOGO = '/cards/toolkits/clim4health.svg'; |
| 11 | +const L4H_LOGO = '/cards/toolkits/land4health.svg'; |
| 12 | +const S4H_LOGO = '/cards/toolkits/socio4health.svg'; |
| 13 | +const CU4H_LOGO = '/cards/toolkits/cube4health.svg'; |
| 14 | + |
| 15 | + |
| 16 | +type Section = 'data4health' | 'clim4health' | 'land4health' | 'socio4health' | 'cube4health'; |
| 17 | + |
| 18 | +interface CircularButtonProps { |
| 19 | + icon: React.ElementType | string; |
| 20 | + label: string; |
| 21 | + onClick: () => void; |
| 22 | + isImage?: boolean; |
| 23 | + isActive?: boolean; |
| 24 | + size?: 'sm' | 'md'; |
| 25 | +} |
| 26 | + |
| 27 | + |
| 28 | +function SubButtons({ section }: { section: Section }) { |
| 29 | + const resources: Record<Section, { pdf?: string; related?: Array<{ label: string; href: string; isFile?: boolean; useButton?: boolean }> }> = { |
| 30 | + data4health: { |
| 31 | + pdf: '/training/data4health-training.pdf', |
| 32 | + related: [ |
| 33 | + //{ label: 'Quickstart (download)', href: '/cards/toolkits/data4health-quickstart.zip', isFile: true }, |
| 34 | + //{ label: 'Online docs', href: 'https://example.org/data4health' }, |
| 35 | + ], |
| 36 | + }, |
| 37 | + clim4health: { |
| 38 | + pdf: '/training/clim4health-training.pdf', |
| 39 | + related: [ |
| 40 | + { label: 'Clim4Health training files', href: '/training/clim4health_for_website.zip', isFile: true, useButton: true }, |
| 41 | + ], |
| 42 | + }, |
| 43 | + land4health: { |
| 44 | + pdf: '/cards/toolkits/land4health-installation.pdf', |
| 45 | + related: [ |
| 46 | + { label: 'Land4Health dataset', href: '/cards/toolkits/land4health-dataset.zip', isFile: true }, |
| 47 | + { label: 'Documentation', href: 'https://example.org/land4health' }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + socio4health: { |
| 51 | + pdf: '/cards/toolkits/socio4health-installation.pdf', |
| 52 | + related: [ |
| 53 | + { label: 'Socio4Health notes (download)', href: '/cards/toolkits/socio4health-notes.pdf', isFile: true }, |
| 54 | + { label: 'Website', href: 'https://example.org/socio4health' }, |
| 55 | + ], |
| 56 | + }, |
| 57 | + cube4health: { |
| 58 | + pdf: '/training/cube4health-training.pdf', |
| 59 | + related: [ |
| 60 | + //{ label: 'Cube4Health examples', href: '/cards/toolkits/cube4health-examples.zip', isFile: true }, |
| 61 | + //{ label: 'Repo', href: 'https://example.org/cube4health' }, |
| 62 | + ], |
| 63 | + }, |
| 64 | + }; |
| 65 | + |
| 66 | + const entry = resources[section]; |
| 67 | + |
| 68 | + return ( |
| 69 | + <article className="prose mx-auto mt-8 w-full max-w-4xl"> |
| 70 | + |
| 71 | + {entry?.pdf ? ( |
| 72 | + <div className="mt-6 border rounded overflow-hidden" style={{ height: 720 }}> |
| 73 | + {/* The iframe/embed will show the PDF. If the PDF isn't present, users |
| 74 | + can use the link below to open/download it. */} |
| 75 | + <iframe |
| 76 | + src={entry.pdf} |
| 77 | + title={`${section} installation guide`} |
| 78 | + className="w-full h-full" |
| 79 | + style={{ border: 'none' }} |
| 80 | + /> |
| 81 | + </div> |
| 82 | + ) : ( |
| 83 | + <p className="mt-4 text-sm text-gray-500">No PDF guide available for this toolkit.</p> |
| 84 | + )} |
| 85 | + |
| 86 | + {entry.related && entry.related.length > 0 && ( |
| 87 | + <div className="mt-6"> |
| 88 | + <h3 className="text-lg font-medium">References</h3> |
| 89 | + <div className="mt-3 space-y-3"> |
| 90 | + {entry.related.map((r, i) => ( |
| 91 | + <div key={i} className="my-0"> |
| 92 | + {r.useButton && r.isFile ? ( |
| 93 | + <DownloadButton href={r.href} label={r.label} /> |
| 94 | + ) : ( |
| 95 | + <a |
| 96 | + href={r.href} |
| 97 | + target="_blank" |
| 98 | + rel="noopener noreferrer" |
| 99 | + className="text-purple-700 hover:underline block" |
| 100 | + {...(r.isFile ? { download: '' } : {})} |
| 101 | + > |
| 102 | + {r.label} |
| 103 | + </a> |
| 104 | + )} |
| 105 | + </div> |
| 106 | + ))} |
| 107 | + </div> |
| 108 | + </div> |
| 109 | + )} |
| 110 | + </article> |
| 111 | + ); |
| 112 | +} |
| 113 | + |
| 114 | + |
| 115 | +export default function Page() { |
| 116 | + const [activeSection, setActiveSection] = useState<Section | null>(null); |
| 117 | + // Toggle buttons by editing this map in code. Set true to disable, false to enable. |
| 118 | + const disabledMap: Record<Section, boolean> = { |
| 119 | + data4health: false, |
| 120 | + clim4health: true, |
| 121 | + land4health: true, |
| 122 | + socio4health: true, |
| 123 | + cube4health: true, |
| 124 | + }; |
| 125 | + |
| 126 | + const handleToolkitClick = (section: Section) => { |
| 127 | + if (section === activeSection) { |
| 128 | + setActiveSection(null); |
| 129 | + } else { |
| 130 | + setActiveSection(section); |
| 131 | + } |
| 132 | + }; |
| 133 | + |
| 134 | + return ( |
| 135 | + <div className="container mx-auto px-4"> |
| 136 | + <h1 className="mb-2 mt-6 text-3xl font-semibold md:mt-0">Trainings</h1> |
| 137 | + <p className="text-justify text-l text-gray-500"> |
| 138 | + This section contains the workshop development support materials. |
| 139 | + </p> |
| 140 | + |
| 141 | + <div className="mb-8 mt-6 flex flex-wrap justify-center gap-8"> |
| 142 | + {[ |
| 143 | + { key: 'data4health', logo: D4H_LOGO, label: 'data4Health' }, |
| 144 | + { key: 'clim4health', logo: C4H_LOGO, label: 'clim4health' }, |
| 145 | + { key: 'land4health', logo: L4H_LOGO, label: 'land4health' }, |
| 146 | + { key: 'socio4health', logo: S4H_LOGO, label: 'socio4health' }, |
| 147 | + { key: 'cube4health', logo: CU4H_LOGO, label: 'cube4health' }, |
| 148 | + ].map((tk) => { |
| 149 | + const section = tk.key as Section; |
| 150 | + return ( |
| 151 | + <div key={tk.key} className="flex flex-col items-center"> |
| 152 | + <CircularButton |
| 153 | + icon={tk.logo} |
| 154 | + label={tk.label} |
| 155 | + onClick={() => handleToolkitClick(section)} |
| 156 | + isImage={true} |
| 157 | + isActive={activeSection === section} |
| 158 | + disabled={disabledMap[section]} |
| 159 | + /> |
| 160 | + </div> |
| 161 | + ); |
| 162 | + })} |
| 163 | + </div> |
| 164 | + |
| 165 | + {activeSection && ( |
| 166 | + <SubButtons section={activeSection} /> |
| 167 | + )} |
| 168 | + </div> |
| 169 | + ); |
| 170 | +} |
0 commit comments