tai-JY / src /components /NodeContent /NodeContent.jsx
youngtsai's picture
init
c3ad400
import React from 'react';
import {
Card,
CardContent,
Typography,
Link,
Divider,
List,
ListItem,
ListItemText,
Radio,
RadioGroup,
FormControlLabel
} from '@mui/material';
function NodeContent({ node }) {
if (!node) return null;
return (
<Card>
<CardContent>
<Typography variant="h5" gutterBottom>
{node.title}
</Typography>
<Divider />
{/* 內容區 */}
<Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
內容
</Typography>
<div dangerouslySetInnerHTML={{ __html: node.content }} />
{/* 資源連結 */}
{node.resources && (
<>
<Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
延伸資源
</Typography>
<List>
{node.resources.map((resource, index) => (
<ListItem key={index}>
<ListItemText>
<Link href={resource.url} target="_blank" rel="noopener noreferrer">
{resource.type}: {resource.url}
</Link>
</ListItemText>
</ListItem>
))}
</List>
</>
)}
{/* AI 對話記錄 */}
{node.aiChats && (
<>
<Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
AI 對話記錄
</Typography>
<List>
{node.aiChats.map((chat, index) => (
<ListItem key={index}>
<ListItemText
primary={<strong>Q: {chat.question}</strong>}
secondary={`A: ${chat.answer}`}
/>
</ListItem>
))}
</List>
</>
)}
{/* 練習區 */}
{node.exercises && (
<>
<Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
練習題
</Typography>
{node.exercises.map((exercise) => (
<div key={exercise.id}>
<Typography variant="subtitle1" gutterBottom>
{exercise.question}
</Typography>
{exercise.type === 'multiple_choice' && (
<RadioGroup name={exercise.id}>
{exercise.options.map((option, index) => (
<FormControlLabel
key={index}
value={index.toString()}
control={<Radio />}
label={option}
/>
))}
</RadioGroup>
)}
</div>
))}
</>
)}
</CardContent>
</Card>
);
}
export default NodeContent;