From c132ad4314a2cbf680a3a2086230813a5438d10e Mon Sep 17 00:00:00 2001 From: yougyung Date: Thu, 26 Sep 2024 22:39:59 +0900 Subject: [PATCH] fix: change number to constant --- .../result-category-detail-info.tsx | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/ui/result/result-category-detail/result-category-detail-info.tsx b/app/ui/result/result-category-detail/result-category-detail-info.tsx index ca17b43..a4d7829 100644 --- a/app/ui/result/result-category-detail/result-category-detail-info.tsx +++ b/app/ui/result/result-category-detail/result-category-detail-info.tsx @@ -9,11 +9,15 @@ import { import { ResultCategoryKey } from '../result-category-detail-content/result-category-detail-content.stories'; import { RESULT_CATEGORY } from '@/app/utils/key/result-category.key'; +const CHAPEL_TOTAL_CREDIT = 2.0; +const CHAPEL_TOTAL_COUNT = 4; +const CHAPEL_CREDIT = CHAPEL_TOTAL_CREDIT / CHAPEL_TOTAL_COUNT; + const CHAPEL_LECTURE_INFO: LectureInfoResponse = { id: 0, lectureCode: 'KMA02101', name: '채플', - credit: 0.5, + credit: CHAPEL_CREDIT, }; function addChapelToCommonCulture( @@ -21,18 +25,18 @@ function addChapelToCommonCulture( chapel?: CreditResponse, ): ResultCategoryDetailLecturesResponse[] { if (!chapel) return info; - const takenChapel = chapel.takenCredit / 0.5; - const haveToChapel = Math.max(0, 4 - takenChapel); + const takenChapelCount = chapel.takenCredit / CHAPEL_CREDIT; + const haveToChapelCount = Math.max(0, CHAPEL_TOTAL_COUNT - takenChapelCount); return [ ...info, { categoryName: '채플', - completed: takenChapel * 0.5 >= 2.0, - totalCredit: 2.0, - takenCredit: takenChapel * 0.5, - haveToLectures: Array(haveToChapel).fill(CHAPEL_LECTURE_INFO), - takenLectures: Array(takenChapel).fill(CHAPEL_LECTURE_INFO), + completed: takenChapelCount >= CHAPEL_TOTAL_COUNT, + totalCredit: CHAPEL_TOTAL_CREDIT, + takenCredit: chapel.takenCredit, + haveToLectures: Array(haveToChapelCount).fill(CHAPEL_LECTURE_INFO), + takenLectures: Array(takenChapelCount).fill(CHAPEL_LECTURE_INFO), }, ]; } @@ -41,7 +45,7 @@ export default function ResultCategoryDetailInfo({ category }: { category: Resul const { data: categoryInfo } = useFetchResultCategoryDetailInfo(category); const { data: categories } = useFetchCredits(); - const chapel = categories.find((category) => category.category === 'CHAPEL'); + const chapel = categories.find(({ category }) => category === 'CHAPEL'); const isCommonCulture = category === RESULT_CATEGORY.COMMON_CULTURE; const detailCategory = isCommonCulture ? addChapelToCommonCulture(categoryInfo.detailCategory, chapel)