Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] 연도가 다른 타임 블록 배치 #210

Merged
merged 21 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b649cbc
#205 fix: 연도 걸치는 타임 블록 배치 완료
namdaeun Aug 3, 2024
e78b1e9
#205 chore: 필요 없는 코드 제거
namdaeun Aug 3, 2024
f74d84f
#205 feat: 연도 바꾸면 1월부터 보이게 구현
namdaeun Aug 3, 2024
15d720e
#205 feat: 연도/월 바뀔 때마다 스크롤 시작 위치 왼쪽으로 초기화
namdaeun Aug 3, 2024
df4baf4
#205 fix: date-fns devDependency만 남기기
namdaeun Aug 4, 2024
8447d7b
#205 fix: ref 사용해서 스크롤 처리
namdaeun Aug 4, 2024
e0abd1f
#205 chore: 사용하지 않는 dependency 제거
namdaeun Aug 4, 2024
8dfecce
#205 chore: cd 해결
namdaeun Aug 4, 2024
05fd288
#205 chore: date-fns dev로 재설치
namdaeun Aug 4, 2024
a1546f1
#205 refactor: 커스텀 훅과 상태관리 코드 모아놓기
namdaeun Aug 5, 2024
8ab9f90
#205 chore: 필요없는 코드 제거
namdaeun Aug 5, 2024
1f5f4df
#205 style: Flex 컴포넌트 tag 추가
namdaeun Aug 5, 2024
9f87289
#205 feat: 컴포넌트 초기 렌더링 시, teamId 바뀔 때만 달 헤더 현재 달로 초기화
namdaeun Aug 5, 2024
e9fea31
#205 fix: set함수 if문 안에 배치
namdaeun Aug 5, 2024
cae3003
#205 feat: 커스텀 훅 인자 옵셔널로 수정
namdaeun Aug 5, 2024
89f24fa
#205 fix: 마운트 됐을 때 set함수 실행
namdaeun Aug 5, 2024
acdd4c9
#205 fix: teamId가 바뀔 때마다 set함수 초기화
namdaeun Aug 5, 2024
0984121
#205 docs: merge develop
namdaeun Aug 7, 2024
7a59d81
#205 chore: lint에러 해결 & 핸들러 함수 분리
namdaeun Aug 7, 2024
b009245
#205 refactor: 코드 순서 변경
namdaeun Aug 7, 2024
2b7a79c
Merge branch 'develop' into fix/archiving/#205-fix-timeblock-period
namdaeun Aug 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@tanstack/react-query": "^5.49.2",
"@tanstack/react-query-devtools": "^5.49.2",
"axios": "^1.7.2",
"date-fns": "^3.6.0",
"mime": "^4.0.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 35 additions & 23 deletions src/page/archiving/index/ArchivingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import YearHeader from '@/page/archiving/index/component/YearHeader/YearHeader';
import { useGetTimeBlockQuery } from '@/page/archiving/index/hook/api/useGetTimeBlockQuery';
import { useDate } from '@/page/archiving/index/hook/common/useDate';
import { Block } from '@/page/archiving/index/type/blockType';
import { MonthType } from '@/page/archiving/index/type/monthType';
import { alignBlocks, createTimeBlock } from '@/page/archiving/index/util/block';

import { useState } from 'react';
import { useEffect, useRef, useState } from 'react';

import AddIc from '@/common/asset/svg/add_btn.svg?react';
import Button from '@/common/component/Button/Button';
Expand All @@ -24,13 +25,39 @@ import { useTeamStore } from '@/shared/store/team';

const ArchivingPage = () => {
const [selectedId, setSelectedId] = useState('total');
const [selectedBlock, setSelectedBlock] = useState<Block>();
const isMounted = useRef(false);
const daySectionRef = useRef<HTMLDivElement>(null);

const { teamId } = useTeamStore();

const { currentDate, currentYear, selectedMonth, setSelectedMonth, handlePrevYear, handleNextYear, endDay } =
useDate(daySectionRef);

// 블록 생성 모달 관련 코드
const { isOpen, openModal, closeModal, setCurrentContent, currentContent } = useModal();

const handleClose = () => {
selectedBlock && setSelectedBlock(undefined);
};

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

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

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

const timeBlocks: Block[] = data?.timeBlocks || [];
const blockFloors = alignBlocks(timeBlocks, endDay, selectedMonth, currentYear);

useEffect(() => {
if (!isMounted.current) {
isMounted.current = true;
return;
}
setSelectedMonth(`${currentDate.getMonth() + 1}월` as MonthType);
}, [teamId]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return이 아닌, current 값을 true로 바꾸고 조건문 안에서 setter를 실행해야 올바른 동작인 것 같습니다 ! 마운트되었다면 실행이 안돼야 하니까요 !

마운트까지 고려하셔서 useEffect를 적용하신거 너무 보기 좋네요 :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 수정하겠습니다 !! 감사합니당


const handleSelectedId = (id: string) => {
setSelectedId(id);
};
Expand All @@ -48,22 +75,6 @@ const ArchivingPage = () => {
setSelectedId('selected');
};

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

const { currentDate, currentYear, selectedMonth, setSelectedMonth, handlePrevYear, handleNextYear, endDay } =
useDate();

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

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

const [selectedBlock, setSelectedBlock] = useState<Block>();
const timeBlocks: Block[] = data?.timeBlocks || [];
const blockFloors = alignBlocks(timeBlocks, endDay, selectedMonth, currentYear);

// 블록 생성 모달 관련 코드
const { isOpen, openModal, closeModal, setCurrentContent, currentContent } = useModal();

const handleNext = (blockData: {
blockName: string;
blockType: string;
Expand All @@ -73,6 +84,11 @@ const ArchivingPage = () => {
setCurrentContent(<UploadModal onClose={closeModal} teamId={+teamId} type={type} blockData={blockData} />);
};

const handleMonthClick = (month: MonthType) => {
setSelectedMonth(month);
daySectionRef.current?.scrollTo(0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요고는 의도가 무엇이죠 ???

Copy link
Member Author

@namdaeun namdaeun Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

달이 바뀔 때 스크롤 됐던 부분을 좌측으로 스크롤해주고자 작성해주었습니다 !

};

return (
<Flex
styles={{
Expand All @@ -86,12 +102,8 @@ const ArchivingPage = () => {
<section css={timelineStyle}>
<YearHeader handlePrevYear={handlePrevYear} handleNextYear={handleNextYear} currentYear={currentYear} />
<Flex css={contentStyle}>
<MonthHeader
currentMonth={selectedMonth}
onMonthClick={(month) => setSelectedMonth(month)}
selectedBlock={selectedBlock}
/>
<div id="block_area" css={daySectionStyle}>
<MonthHeader currentMonth={selectedMonth} onMonthClick={handleMonthClick} selectedBlock={selectedBlock} />
<div id="block_area" css={daySectionStyle} ref={daySectionRef}>
{Array.from({ length: endDay.getDate() }, (_, index) => {
const day = index + 1;
const isEven = day % 2 === 0;
Expand Down
4 changes: 1 addition & 3 deletions src/page/archiving/index/component/DaySection/DaySection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
bodyStyle,
dayHeaderStyle,
dayStyle,
selectedDayStyle,
Expand Down Expand Up @@ -37,9 +36,8 @@ const DottedDayLine = () => {

const DaySection = ({ day, isEven, isToday }: DaySectionProps) => {
return (
<Flex css={dayStyle(isEven, isToday)}>
<Flex tag="section" css={dayStyle(isEven, isToday)}>
<Flex css={dayHeaderStyle(isToday)}>{day}</Flex>
<Flex css={bodyStyle} />
{isToday && (
<>
<Circle width={8} height={8} css={selectedDayStyle} />
Expand Down
6 changes: 5 additions & 1 deletion src/page/archiving/index/hook/common/useDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { endOfMonth } from 'date-fns';

import { useState } from 'react';

export const useDate = () => {
export const useDate = (ref: React.RefObject<HTMLDivElement>) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref를 인자로 받게 한다면, useDate 커스텀 훅의 재사용성이 조금 낮아질 것 같다는 생각인데, 다른 대안은 없을까요 ?

Copy link
Member Author

@namdaeun namdaeun Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

재사용성이 낮아진다는 의견에 동의해요!
옵셔널로 받아서 아무런 값을 인자로 받지 않아도 가능하게끔 수정했습니다!

const currentDate = new Date();

const [currentYear, setCurrentYear] = useState(currentDate.getFullYear());
Expand All @@ -14,10 +14,14 @@ export const useDate = () => {

const handlePrevYear = () => {
setCurrentYear((prevYear) => prevYear - 1);
setSelectedMonth('1월');
ref.current?.scrollTo(0, 0);
};

const handleNextYear = () => {
setCurrentYear((prevYear) => prevYear + 1);
setSelectedMonth('1월');
ref.current?.scrollTo(0, 0);
};

return {
Expand Down
12 changes: 9 additions & 3 deletions src/page/archiving/index/util/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,21 @@ export const createTimeBlock = ({ startDate, endDate, currentYear, selectedMonth

if (blockStartDate.getFullYear() === currentYear && blockEndDate.getFullYear() === currentYear) {
if (startMonth < selectedMonth && selectedMonth < endMonth) {
// 타임블록이 3달 이상의 기간을 가질 때
blockStartDate = firstDay;
blockEndDate = lastDay;
} else if (startMonth !== selectedMonth) {
} else if (startMonth !== selectedMonth && endMonth === selectedMonth) {
blockStartDate = firstDay;
} else if (endMonth !== selectedMonth) {
} else if (startMonth === selectedMonth && endMonth !== selectedMonth) {
blockEndDate = lastDay;
}
} else {
if (startMonth <= selectedMonth || selectedMonth <= endMonth) {
blockStartDate =
startMonth === selectedMonth && blockStartDate.getFullYear() === currentYear ? blockStartDate : firstDay;
blockEndDate = endMonth === selectedMonth && blockEndDate.getFullYear() === currentYear ? blockEndDate : lastDay;
}
}

return { startDate: blockStartDate, endDate: blockEndDate };
};

Expand Down