|
| 1 | +import { Typography, Card, CardContent, Stack, Chip } from "@mui/material"; |
| 2 | +import { Colors } from "design/theme"; |
| 3 | +import React from "react"; |
| 4 | +import { Link } from "react-router-dom"; |
| 5 | +import RoutesEnum from "types/routes.enum"; |
| 6 | + |
| 7 | +interface SubjectCardProps { |
| 8 | + dbname: string; |
| 9 | + dsname: string; |
| 10 | + age: string; |
| 11 | + subj: string; |
| 12 | + parsedJson: { |
| 13 | + key: string[]; |
| 14 | + value: { |
| 15 | + modalities?: string[]; |
| 16 | + tasks?: string[]; |
| 17 | + sessions?: string[]; |
| 18 | + types?: string[]; |
| 19 | + }; |
| 20 | + }; |
| 21 | + index: number; |
| 22 | +} |
| 23 | + |
| 24 | +const SubjectCard: React.FC<SubjectCardProps> = ({ |
| 25 | + dbname, |
| 26 | + dsname, |
| 27 | + age, |
| 28 | + subj, |
| 29 | + parsedJson, |
| 30 | + index, |
| 31 | +}) => { |
| 32 | + const { modalities, tasks, sessions, types } = parsedJson.value; |
| 33 | + const subjectLink = `${RoutesEnum.DATABASES}/${dbname}/${dsname}`; |
| 34 | + |
| 35 | + // get the gender of subject |
| 36 | + const genderCode = parsedJson?.key?.[1]; |
| 37 | + let genderDisplay = "Unknown"; |
| 38 | + |
| 39 | + if (genderCode) { |
| 40 | + if (genderCode === "000F") genderDisplay = "Female"; |
| 41 | + else if (genderCode === "000M") genderDisplay = "Male"; |
| 42 | + } |
| 43 | + |
| 44 | + // cover age string to readable format |
| 45 | + let ageDisplay = "N/A"; |
| 46 | + if (age) { |
| 47 | + const ageNum = parseInt(age, 10) / 100; |
| 48 | + if (Number.isInteger(ageNum)) { |
| 49 | + ageDisplay = `${ageNum} years`; |
| 50 | + } else { |
| 51 | + ageDisplay = `${ageNum.toFixed(1)} years`; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + return ( |
| 56 | + <Card sx={{ mb: 3, position: "relative" }}> |
| 57 | + <CardContent> |
| 58 | + {/* Card Number in Top Right */} |
| 59 | + <Typography |
| 60 | + variant="subtitle2" |
| 61 | + sx={{ |
| 62 | + position: "absolute", |
| 63 | + bottom: 8, |
| 64 | + right: 12, |
| 65 | + fontWeight: 600, |
| 66 | + color: Colors.darkPurple, |
| 67 | + }} |
| 68 | + > |
| 69 | + #{index + 1} |
| 70 | + </Typography> |
| 71 | + |
| 72 | + <Typography |
| 73 | + variant="h6" |
| 74 | + sx={{ |
| 75 | + fontWeight: 600, |
| 76 | + color: Colors.darkPurple, |
| 77 | + textDecoration: "none", |
| 78 | + ":hover": { textDecoration: "underline" }, |
| 79 | + }} |
| 80 | + component={Link} |
| 81 | + to={subjectLink} |
| 82 | + target="_blank" |
| 83 | + > |
| 84 | + Database: {dbname} | Dataset Number: {dsname} |
| 85 | + </Typography> |
| 86 | + |
| 87 | + <Typography variant="body2" color="text.secondary" gutterBottom> |
| 88 | + Subject: {subj} | Age: {ageDisplay} |
| 89 | + | Gender: {genderDisplay} |
| 90 | + </Typography> |
| 91 | + |
| 92 | + <Stack spacing={2} margin={1}> |
| 93 | + <Stack direction="row" spacing={1} flexWrap="wrap" gap={1}> |
| 94 | + <Typography variant="body2" mt={1}> |
| 95 | + <strong>Modalities:</strong> |
| 96 | + </Typography> |
| 97 | + {modalities?.map((mod, idx) => ( |
| 98 | + <Chip |
| 99 | + key={idx} |
| 100 | + label={mod} |
| 101 | + variant="outlined" |
| 102 | + sx={{ |
| 103 | + color: Colors.darkPurple, |
| 104 | + border: `1px solid ${Colors.darkPurple}`, |
| 105 | + fontWeight: "bold", |
| 106 | + }} |
| 107 | + /> |
| 108 | + ))} |
| 109 | + </Stack> |
| 110 | + |
| 111 | + <Stack direction="row" spacing={1} flexWrap="wrap" gap={1}> |
| 112 | + <Typography variant="body2" mt={1}> |
| 113 | + <strong>Tasks:</strong> |
| 114 | + </Typography> |
| 115 | + {tasks?.map((task, idx) => ( |
| 116 | + <Chip |
| 117 | + key={`task-${idx}`} |
| 118 | + label={task} |
| 119 | + variant="outlined" |
| 120 | + sx={{ |
| 121 | + color: Colors.darkPurple, |
| 122 | + border: `1px solid ${Colors.darkPurple}`, |
| 123 | + fontWeight: "bold", |
| 124 | + }} |
| 125 | + /> |
| 126 | + ))} |
| 127 | + </Stack> |
| 128 | + <Stack direction="row" spacing={1} flexWrap="wrap" gap={1}> |
| 129 | + <Typography variant="body2" mt={1}> |
| 130 | + <strong>Sessions:</strong> {sessions?.length} |
| 131 | + </Typography> |
| 132 | + </Stack> |
| 133 | + <Stack direction="row" spacing={1} flexWrap="wrap" gap={1}> |
| 134 | + {types?.length && ( |
| 135 | + <Typography variant="body2" mt={1}> |
| 136 | + <strong>Types:</strong> {types.join(", ")} |
| 137 | + </Typography> |
| 138 | + )} |
| 139 | + </Stack> |
| 140 | + </Stack> |
| 141 | + </CardContent> |
| 142 | + </Card> |
| 143 | + ); |
| 144 | +}; |
| 145 | + |
| 146 | +export default SubjectCard; |
0 commit comments