Skip to content

Commit

Permalink
fix: 個別の回答表示ページで、複数選択できる質問が複数の質問として表示されるのを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Jun 23, 2024
1 parent 6c35634 commit b89eaa1
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,27 @@ const AnswerDetails = (props: {
answers: GetAnswerResponse;
questions: GetQuestionsResponse;
}) => {
console.log(props.answers, props.questions);
type AnswerWithQuestionInfo = {
questionTitle: string;
answers: string[];
};

// NOTE: TypeScript の Set 型は順番を維持する
// ref: https://zenn.dev/notfounds/scraps/d8a0e4b99ddc38
const answerWithQeustionInfo = Array.from(
new Set(props.answers.answers.map((answer) => answer.question_id))
).map((questionId) => {
const answerWithQuestionInfo: AnswerWithQuestionInfo = {
questionTitle:
props.questions.find((question) => question.id == questionId)?.title ||
'',
answers: props.answers.answers
.filter((answer) => answer.question_id == questionId)
.map((answer) => answer.answer),
};

return answerWithQuestionInfo;
});

return (
<Grid container spacing={2}>
Expand All @@ -25,18 +45,14 @@ const AnswerDetails = (props: {
<Typography sx={{ fontWeight: 'bold' }}>回答日時</Typography>
{formatString(props.answers.timestamp)}
</Grid>
{props.answers.answers.map((answer, index) => (
{answerWithQeustionInfo.map((answer, index) => (
<Grid item xs={12} key={index}>
<Grid container spacing={2}>
<Grid item xs={12} sx={{ fontWeight: 'bold' }}>
{
props.questions.find(
(question) => question.id == answer.question_id
)?.title
}
{answer.questionTitle}
</Grid>
<Grid item xs={12}>
{answer.answer}
{answer.answers.join(', ')}
</Grid>
</Grid>
</Grid>
Expand Down

0 comments on commit b89eaa1

Please sign in to comment.