Skip to content

Commit

Permalink
#205 refactor: 상태 변수명 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
namdaeun committed Aug 4, 2024
1 parent 0c22187 commit 050f880
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
17 changes: 11 additions & 6 deletions src/page/archiving/index/ArchivingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useDate } from '@/page/archiving/index/hook/common/useDate';
import { Block } from '@/page/archiving/index/type/blockType';
import { alignBlocks, createTimeBlock } from '@/page/archiving/index/util/block';

import { useState } from 'react';
import { useMemo, useState } from 'react';

import Add from '@/common/asset/svg/add_btn.svg?react';
import Button from '@/common/component/Button/Button';
Expand Down Expand Up @@ -56,15 +56,20 @@ const ArchivingPage = () => {

const sideBarRef = useOutsideClick(handleClose, 'TimeBlock');

const { currentYear, selectedMonthType, setSelectedMonthType, handlePrevYear, handleNextYear, endDay } = useDate();
const { currentYear, selectedMonthString, setSelectedMonthString, handlePrevYear, handleNextYear, endDay } =
useDate();

const selectedMonth = parseInt(selectedMonthType.split('월')[0]);
const selectedMonth = parseInt(selectedMonthString.split('월')[0]);

const { data } = useGetTimeBlockQuery(+teamId, 'executive', currentYear, selectedMonth);

const [selectedBlock, setSelectedBlock] = useState<Block>();
// eslint-disable-next-line react-hooks/exhaustive-deps
const timeBlocks: Block[] = data?.timeBlocks || [];
const blockFloors = alignBlocks(timeBlocks, endDay, selectedMonthType, currentYear);
const blockFloors = useMemo(
() => alignBlocks(timeBlocks, endDay, selectedMonthString, currentYear),
[currentYear, endDay, selectedMonthString, timeBlocks]
);

// 블록 생성 모달 관련 코드
const { isOpen, openModal, closeModal, setCurrentContent, currentContent } = useModal();
Expand All @@ -84,8 +89,8 @@ const ArchivingPage = () => {
<YearHeader handlePrevYear={handlePrevYear} handleNextYear={handleNextYear} currentYear={currentYear} />
<Flex css={contentStyle}>
<MonthHeader
currentMonth={selectedMonthType}
onMonthClick={(month) => setSelectedMonthType(month)}
currentMonth={selectedMonthString}
onMonthClick={setSelectedMonthString}
selectedBlock={selectedBlock}
/>
<div id="block_area" css={daySectionStyle}>
Expand Down
4 changes: 2 additions & 2 deletions src/page/archiving/index/component/DaySection/DaySection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const DottedDayLine = () => {
};

const DaySection = memo(({ endDay }: DaySectionProps) => {
const { currentDate, currentYear, selectedMonthType } = useDate();
const { currentDate, currentYear, selectedMonthString } = useDate();

return (
<>
Expand All @@ -46,7 +46,7 @@ const DaySection = memo(({ endDay }: DaySectionProps) => {
const isToday =
day + 1 === currentDate.getDate() &&
currentYear === currentDate.getFullYear() &&
selectedMonthType === `${currentDate.getMonth() + 1}월`;
selectedMonthString === `${currentDate.getMonth() + 1}월`;

return (
<Flex css={dayStyle(isEven, isToday)}>
Expand Down
10 changes: 6 additions & 4 deletions src/page/archiving/index/hook/common/useDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ export const useDate = () => {
const currentDate = new Date();

const [currentYear, setCurrentYear] = useState(currentDate.getFullYear());
const [selectedMonthType, setSelectedMonthType] = useState<MonthType>(`${currentDate.getMonth() + 1}월` as MonthType);
const [selectedMonthString, setSelectedMonthString] = useState<MonthType>(
`${currentDate.getMonth() + 1}월` as MonthType
);

const dateOfMonth = getMonthDate(selectedMonthType, currentYear);
const dateOfMonth = getMonthDate(selectedMonthString, currentYear);
const endDay = endOfMonth(dateOfMonth);

const handlePrevYear = () => {
Expand All @@ -24,8 +26,8 @@ export const useDate = () => {
return {
currentDate,
currentYear,
selectedMonthType,
setSelectedMonthType,
selectedMonthString,
setSelectedMonthString,
handlePrevYear,
handleNextYear,
dateOfMonth,
Expand Down

0 comments on commit 050f880

Please sign in to comment.