Skip to content

Commit

Permalink
받은 피드백 최신순 정렬 (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyesungoh authored Aug 15, 2023
1 parent fe896d8 commit 2f099e0
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/pages/feedback/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,33 @@ export default function FeedbackList() {

const renderReceivedFeedbackCards = () => {
const now = new Date();
const feedbackList = [];
for (const year in feedbacksByYearAndMonth) {
for (const month in feedbacksByYearAndMonth[year]) {
const feedbacks = feedbacksByYearAndMonth[year][month];
const feedbackItems = feedbacks.map((feedback: Feedback) => {
return (
<ReceivedFeedbackCard key={feedback.feedback_id} feedback={feedback} onClickFeedback={onClickFeedback} />
);
});
const feedbackList: ReactElement[] = [];

if (!feedbacksByYearAndMonth) return null;

const reversedYears = Object.keys(feedbacksByYearAndMonth).sort((a, b) => Number(b) - Number(a));

reversedYears.forEach((year) => {
const reversedMonths = Object.keys(feedbacksByYearAndMonth[year]).sort((a, b) => Number(b) - Number(a));

reversedMonths.forEach((month) => {
const reversedFeedbacks = [...feedbacksByYearAndMonth[year][month]].sort(
(a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime(),
);
const feedbackElements = reversedFeedbacks.map((feedback) => (
<ReceivedFeedbackCard key={feedback.feedback_id} feedback={feedback} onClickFeedback={onClickFeedback} />
));

feedbackList.push(
<div key={`${year}-${month}`}>
<span css={monthTitleCss}>
{now.getFullYear() === Number(year) ? `${month}월` : `${year}${month}월`}
</span>
<section css={monthFeedbackListCss}>{feedbackItems}</section>
<section css={monthFeedbackListCss}>{feedbackElements}</section>
</div>,
);
}
}
});
});

return feedbackList;
};
Expand Down

0 comments on commit 2f099e0

Please sign in to comment.