From a620068d0ab671b62c3e07d6d2807b0b0ada2ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=86=E1=85=B5=E1=86=AB?= =?UTF-8?q?=E1=84=80=E1=85=A7=E1=86=BC?= Date: Sun, 17 Dec 2023 17:56:32 +0900 Subject: [PATCH] Feat : fix axios and calendar color generate --- src/api/diaryApis.ts | 3 +- src/components/common/EmotionLabel.tsx | 2 +- src/components/home/Calendar.tsx | 40 ++++++++++++++++++++------ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/api/diaryApis.ts b/src/api/diaryApis.ts index 951fc57..30d0d25 100644 --- a/src/api/diaryApis.ts +++ b/src/api/diaryApis.ts @@ -51,7 +51,8 @@ export const diaryApis = { const response = await instance.get(`/api/diary/list`, { params: { month }, }); - return monthlyDiarySchema.validate(response.data); + // return monthlyDiarySchema.validate(response.data); + return response; }, getDiary: async (diaryId: number) => { const response = await instance.get(`/api/diary/get/${diaryId}`); diff --git a/src/components/common/EmotionLabel.tsx b/src/components/common/EmotionLabel.tsx index 923ddc4..c5710ab 100644 --- a/src/components/common/EmotionLabel.tsx +++ b/src/components/common/EmotionLabel.tsx @@ -32,7 +32,7 @@ const labelByEmotion = { [Emotion.UNFAIR]: '억울한', }; -const colorByEmotion = { +export const colorByEmotion = { [Emotion.COMFORTABLE]: { container: 'rgba(133, 224, 142, 0.20)', indicator: '#85E08E', diff --git a/src/components/home/Calendar.tsx b/src/components/home/Calendar.tsx index 63fd7f1..881c9b1 100644 --- a/src/components/home/Calendar.tsx +++ b/src/components/home/Calendar.tsx @@ -1,5 +1,5 @@ -import dayjs, { Dayjs } from 'dayjs'; -import { useRecoilState, useRecoilValue } from 'recoil'; +import dayjs from 'dayjs'; +import { useRecoilState } from 'recoil'; import { CurrentDateState } from 'store/CurrentDateState'; import weekdayPlugin from 'dayjs/plugin/weekday'; import objectPlugin from 'dayjs/plugin/toObject'; @@ -10,10 +10,12 @@ import { useGetMonthlyDiary } from 'api/hook/useDiary'; import { AddIcon } from 'assets/home'; import { useNavigate } from 'react-router-dom'; import locale from 'dayjs/locale/ko'; +import { Emotion } from 'constants/enum'; +import { colorByEmotion } from 'components/common/EmotionLabel'; export interface MonthlyDiaryRespose { id: number; - emotion: string[]; + emotion: Emotion[]; summary: string; content: string; writingDay: string; @@ -38,6 +40,22 @@ export default function Calendar() { getAllDays(); }, [currentDate]); + const generateEmotionColor = (emotion: Emotion[] | undefined) => { + if (!emotion) return ''; + let emotionResult = ''; + + emotion.forEach((item: Emotion) => { + emotionResult = + emotionResult.length > 0 + ? emotionResult + .concat(', ') + .concat(colorByEmotion[`${item}`].indicator) + : colorByEmotion[`${item}`].indicator; + }); + + return emotionResult; + }; + useEffect(() => { monthly && SetLoggedDate( @@ -96,6 +114,7 @@ export default function Calendar() { }; const renderCells = () => { + if (!loggedDate) return; const rows: any = []; let days: any = []; @@ -108,12 +127,14 @@ export default function Calendar() { }; const checkDiary = () => { - if (loggedDate?.get(d.day)) return 'logged'; + if (loggedDate?.get(d.day)) return true; + else return false; }; days.push( { if (d.isCurrentMonth && !d.isFuture) onClickDate( @@ -124,7 +145,9 @@ export default function Calendar() { }} key={i} > - {d.isCurrentDay && } + + {d.isCurrentDay && !checkDiary() ? : null} + {d.day} ); @@ -175,7 +198,6 @@ const DateNumber = styled.div` const DailyEmotion = styled.div` background-color: #d9d9d9; - /* background: linear-gradient(to bottom, orange 50%, cyan); */ width: 36px; height: 36px; @@ -186,7 +208,7 @@ const DailyEmotion = styled.div` align-items: center; `; -const DayContainer = styled.div` +const DayContainer = styled.div<{ emotionColor?: string }>` flex-direction: column; font-size: 0.875rem; display: flex; @@ -218,7 +240,7 @@ const DayContainer = styled.div` cursor: pointer; & > ${DailyEmotion} { - background: linear-gradient(red, blue); + background: ${(props) => `linear-gradient(${props.emotionColor})`}; } } `;