|
| 1 | +import React, { useState } from "react"; |
| 2 | +import { Container, Row, Col } from "react-bootstrap"; |
| 3 | +import { |
| 4 | + AiOutlineDown, |
| 5 | + AiOutlineUp, |
| 6 | + AiOutlineLaptop, |
| 7 | + AiOutlineGithub, |
| 8 | + AiOutlineProject, |
| 9 | + AiOutlineCode, |
| 10 | + AiOutlineDatabase, |
| 11 | + AiOutlineCluster, |
| 12 | + AiOutlineRobot, |
| 13 | + AiOutlineApi, |
| 14 | + AiOutlineBug, |
| 15 | +} from "react-icons/ai"; |
| 16 | + |
| 17 | +const FAQ = () => { |
| 18 | + const [activeIndex, setActiveIndex] = useState(null); |
| 19 | + |
| 20 | + // Helper function to render text with custom link text |
| 21 | + const renderTextWithLinks = (text) => { |
| 22 | + const linkRegex = /\[([^\]]+)\]\((https?:\/\/[^\s]+)\)/g; |
| 23 | + const parts = []; |
| 24 | + let lastIndex = 0; |
| 25 | + let match; |
| 26 | + |
| 27 | + while ((match = linkRegex.exec(text)) !== null) { |
| 28 | + const [fullMatch, linkText, linkUrl] = match; |
| 29 | + parts.push(text.slice(lastIndex, match.index)); // Add preceding text |
| 30 | + parts.push( |
| 31 | + <a |
| 32 | + key={match.index} |
| 33 | + href={linkUrl} |
| 34 | + target="_blank" |
| 35 | + rel="noopener noreferrer" |
| 36 | + className="faq-link" |
| 37 | + onClick={(e) => e.stopPropagation()} |
| 38 | + > |
| 39 | + {linkText} |
| 40 | + </a> |
| 41 | + ); |
| 42 | + lastIndex = match.index + fullMatch.length; |
| 43 | + } |
| 44 | + parts.push(text.slice(lastIndex)); // Add remaining text |
| 45 | + |
| 46 | + return parts; |
| 47 | + }; |
| 48 | + |
| 49 | + const renderAnswer = (answer, icons) => { |
| 50 | + if (Array.isArray(answer)) { |
| 51 | + return ( |
| 52 | + <ul style={{ listStyleType: "none", paddingLeft: 0 }}> |
| 53 | + {answer.map((point, index) => ( |
| 54 | + <li |
| 55 | + key={index} |
| 56 | + style={{ display: "flex", alignItems: "center", margin: "0.5rem 0" }} |
| 57 | + > |
| 58 | + {/* Icon aligned with the specific point */} |
| 59 | + <span style={{ marginRight: "0.5rem" }}>{icons[index]}</span> |
| 60 | + <span>{renderTextWithLinks(point)}</span> |
| 61 | + </li> |
| 62 | + ))} |
| 63 | + </ul> |
| 64 | + ); |
| 65 | + } |
| 66 | + return renderTextWithLinks(answer); |
| 67 | + }; |
| 68 | + |
| 69 | + const faqData = [ |
| 70 | + { |
| 71 | + question: "Installation and Setup", |
| 72 | + answer: [ |
| 73 | + "[Set up a brainhack friendly computing environment](https://school-brainhack.github.io/modules/installation/)", |
| 74 | + "[An introduction to the terminal (Bash)](https://school-brainhack.github.io/modules/introduction_to_terminal/)", |
| 75 | + ], |
| 76 | + icons: [<AiOutlineLaptop />, <AiOutlineCode />], |
| 77 | + }, |
| 78 | + { |
| 79 | + question: "Version Control Systems", |
| 80 | + answer: [ |
| 81 | + "[Using Git and Github](https://school-brainhack.github.io/modules/git_github/)", |
| 82 | + "[Docker](https://school-brainhack.github.io/modules/containers/)", |
| 83 | + "[Standards for Project Management and Organization](https://school-brainhack.github.io/modules/project_management/)" |
| 84 | + ], |
| 85 | + icons: [<AiOutlineGithub />, <AiOutlineCode />, <AiOutlineProject />], |
| 86 | + }, |
| 87 | + |
| 88 | + { |
| 89 | + question: "Introduction to Python for Data Analysis", |
| 90 | + answer: [ |
| 91 | + "[Writing Scripts in Python](https://school-brainhack.github.io/modules/python_scripts/)", |
| 92 | + "[Python for Data Analysis](https://school-brainhack.github.io/modules/python_data_analysis/)", |
| 93 | + "[Data visualization in Python](https://school-brainhack.github.io/modules/python_visualization/)", |
| 94 | + ], |
| 95 | + icons: [<AiOutlineCode />, <AiOutlineDatabase />, <AiOutlineApi />], |
| 96 | + }, |
| 97 | + { |
| 98 | + question: "Data", |
| 99 | + answer: [ |
| 100 | + "[Open Data](https://school-brainhack.github.io/modules/open_data/)", |
| 101 | + "[Neuroimaging Data and File Structures in Python](https://school-brainhack.github.io/modules/nibabel/)", |
| 102 | + "[Research Data Management with Datalad](https://school-brainhack.github.io/modules/datalad/)", |
| 103 | + "[Brain Imaging Data Structures](https://school-brainhack.github.io/modules/bids/)", |
| 104 | + ], |
| 105 | + icons: [<AiOutlineDatabase />, <AiOutlineCluster />, <AiOutlineProject />, <AiOutlineCluster />], |
| 106 | + }, |
| 107 | + { |
| 108 | + question: "Neuroimaging Basics and Key Concepts", |
| 109 | + answer: [ |
| 110 | + "[fMRI parcellation](https://school-brainhack.github.io/modules/fmri_parcellation/)", |
| 111 | + "[fMRI connectivity](https://school-brainhack.github.io/modules/fmri_connectivity/)", |
| 112 | + ], |
| 113 | + icons: [<AiOutlineCluster />, <AiOutlineApi />], |
| 114 | + }, |
| 115 | + { |
| 116 | + question: "Machine Learning for Neuroimaging", |
| 117 | + answer: [ |
| 118 | + "[Machine Learning Basics](https://school-brainhack.github.io/modules/machine_learning_basics/)", |
| 119 | + "[Machine Learning Applications](https://school-brainhack.github.io/modules/machine_learning_neuroimaging/)", |
| 120 | + ], |
| 121 | + icons: [<AiOutlineRobot />, <AiOutlineRobot />], |
| 122 | + }, |
| 123 | + { |
| 124 | + question: "Deep Learning for Neuroimaging", |
| 125 | + answer: [ |
| 126 | + "[Deep Learning Basics](https://school-brainhack.github.io/modules/deep_learning_intro/)", |
| 127 | + "[Deep Learning Applications](https://school-brainhack.github.io/modules/dl_for_neuroimaging/)", |
| 128 | + ], |
| 129 | + icons: [<AiOutlineRobot />, <AiOutlineApi />], |
| 130 | + }, |
| 131 | + { |
| 132 | + question: "Advanced Programming", |
| 133 | + answer: [ |
| 134 | + "[Software Testing and Continuous Integration](https://school-brainhack.github.io/modules/testing/)", |
| 135 | + ], |
| 136 | + icons: [<AiOutlineBug />], |
| 137 | + }, |
| 138 | + ]; |
| 139 | + |
| 140 | + const toggleAccordion = (index) => { |
| 141 | + setActiveIndex(activeIndex === index ? null : index); |
| 142 | + }; |
| 143 | + |
| 144 | + return ( |
| 145 | + <section> |
| 146 | + <Container fluid className="faq-section" id="faq"> |
| 147 | + <Container> |
| 148 | + <h1 className="page-heading"> |
| 149 | + BrainHack <strong className="purple">Global</strong> |
| 150 | + </h1> |
| 151 | + <Row className="justify-content-center"> |
| 152 | + <Col md={10} className="faq-content"> |
| 153 | + {faqData.map((item, index) => ( |
| 154 | + <div |
| 155 | + key={index} |
| 156 | + className={`faq-item ${activeIndex === index ? "active" : ""}`} |
| 157 | + onClick={() => toggleAccordion(index)} |
| 158 | + > |
| 159 | + <div className="faq-question"> |
| 160 | + <span>{item.question}</span> |
| 161 | + {activeIndex === index ? ( |
| 162 | + <AiOutlineUp className="faq-icon" /> |
| 163 | + ) : ( |
| 164 | + <AiOutlineDown className="faq-icon" /> |
| 165 | + )} |
| 166 | + </div> |
| 167 | + <div |
| 168 | + className={`faq-answer ${activeIndex === index ? "show" : ""}`} |
| 169 | + > |
| 170 | + {renderAnswer(item.answer, item.icons)} |
| 171 | + </div> |
| 172 | + </div> |
| 173 | + ))} |
| 174 | + </Col> |
| 175 | + </Row> |
| 176 | + </Container> |
| 177 | + </Container> |
| 178 | + </section> |
| 179 | + ); |
| 180 | +}; |
| 181 | + |
| 182 | +export default FAQ; |
0 commit comments