корректно выводятся карточки ответов на вопросы

This commit is contained in:
Nastya 2024-04-08 02:16:25 +03:00
parent fb223056b9
commit f188bcee2d

@ -206,20 +206,13 @@ export const Answers: FC<AnswersProps> = ({ data }) => {
() =>
data === null
? []
: Object.keys(data ?? {})
.map((key) =>
Object.entries(data[key]).map(([title, percent]) => ({
title,
percent,
key,
})),
)
.flat(),
: Object.entries(data ?? {}),
[data],
);
console.log(answers);
console.log(page);
console.log("data", data);
console.log("answers", answers);
console.log("page", page);
if (!data) {
return (
<Typography textAlign="center" m="10px 0">
@ -275,10 +268,7 @@ export const Answers: FC<AnswersProps> = ({ data }) => {
>
Заголовок вопроса.{" "}
{
answers.slice(
ANSWERS_PER_PAGE * (page - 1),
ANSWERS_PER_PAGE * page,
)[0]?.key
answers[page-1][0]
}
</Typography>
<ButtonBase>
@ -288,13 +278,14 @@ export const Answers: FC<AnswersProps> = ({ data }) => {
<NextIcon />
</ButtonBase>
</Box>
{answers
.slice(ANSWERS_PER_PAGE * (page - 1), ANSWERS_PER_PAGE * page)
.map(({ title, percent }, index) => (
{
Object.entries(answers[page-1][1])
.map((element, index) => (
<Answer
key={index}
title={title}
percent={percent}
title={element[0]}
percent={element[1]}
highlight={!index}
/>
))}
@ -302,7 +293,7 @@ export const Answers: FC<AnswersProps> = ({ data }) => {
<Pagination
page={page}
setPage={setPage}
pagesAmount={Math.ceil(answers.length / ANSWERS_PER_PAGE)}
pagesAmount={answers.length}
/>
</Box>
);