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 all 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.

66 changes: 43 additions & 23 deletions src/page/archiving/index/ArchivingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,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 { useMemo, useState } from 'react';
import { useEffect, useMemo, useRef, useState } from 'react';
import { useLocation } from 'react-router-dom';

import Add from '@/common/asset/svg/add_btn.svg?react';
Expand All @@ -31,25 +32,27 @@ const ArchivingPage = () => {
const [selectedTabId, setSelectedTabId] = useState('total');
const [selectedBlock, setSelectedBlock] = useState<Block>();

const daySectionRef = useRef<HTMLDivElement>(null);

const location = useLocation();
const teamId = new URLSearchParams(location.search).get('teamId');

const teamId = new URLSearchParams(location.search).get('teamId');
if (!teamId) throw new Error('has no error');

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

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

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

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

const {
currentDate,
currentYear,
selectedMonthString,
setSelectedMonthString,
handlePrevYear,
handleNextYear,
endDay,
} = useDate(daySectionRef);
const selectedMonth = parseInt(selectedMonthString.split('월')[0]);

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

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -59,10 +62,36 @@ const ArchivingPage = () => {
[currentYear, endDay, selectedMonthString, timeBlocks]
);

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

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

useEffect(() => {
setSelectedMonthString(`${currentDate.getMonth() + 1}월` as MonthType);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [teamId]);

const handleSelectedId = (id: string) => {
setSelectedTabId(id);
};

const handleNext = (blockData: {
blockName: string;
blockType: string;
dates: { startDate: string; endDate: string };
}) => {
const type = 'executive';
setCurrentContent(<UploadModal onClose={closeModal} teamId={+teamId} type={type} blockData={blockData} />);
};

const handleMonthClick = (month: MonthType) => {
console.log('click');
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.

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

setSelectedMonthString(month);
};

const handleBlockClick = (
e: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>,
block: Block
Expand All @@ -79,26 +108,17 @@ const ArchivingPage = () => {
setSelectedTabId('selected');
};

const handleNext = (blockData: {
blockName: string;
blockType: string;
dates: { startDate: string; endDate: string };
}) => {
const type = 'executive';
setCurrentContent(<UploadModal onClose={closeModal} teamId={+teamId} type={type} blockData={blockData} />);
};

return (
<Flex css={pageStyle}>
<section css={timelineStyle}>
<YearHeader handlePrevYear={handlePrevYear} handleNextYear={handleNextYear} currentYear={currentYear} />
<Flex css={contentStyle}>
<MonthHeader
currentMonth={selectedMonthString}
onMonthClick={setSelectedMonthString}
onMonthClick={handleMonthClick}
selectedBlock={selectedBlock}
/>
<div id="block_area" css={daySectionStyle}>
<div id="block_area" css={daySectionStyle} ref={daySectionRef}>
<DaySection endDay={endDay} />

{timeBlocks.map((block: Block) => {
Expand Down
2 changes: 0 additions & 2 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 @@ -51,7 +50,6 @@ const DaySection = memo(({ endDay }: DaySectionProps) => {
return (
<Flex css={dayStyle(isEven, isToday)}>
<Flex css={dayHeaderStyle(isToday)}>{day + 1}</Flex>
<Flex css={bodyStyle} />
{isToday && (
<>
<Circle width={8} height={8} css={selectedDayStyle} />
Expand Down
13 changes: 8 additions & 5 deletions src/page/archiving/index/component/TimeBlock/TimeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ const TimeBlock = ({
const blockWidth = (new Date(endDate).getDate() - new Date(startDate).getDate() + 1) * 6;
const startPosition = (new Date(startDate).getDate() - 1) * 6;

const handleEnterBlock = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === 'Enter') {
e.preventDefault();
onBlockClick(e);
}
};

return (
/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
<div
role="tab"
tabIndex={0}
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault();
onBlockClick(e);
}
handleEnterBlock(e);
}}
css={blockStyle(blockWidth, startPosition, floor, color, isSelected)}
onClick={onBlockClick}
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>) => {
const currentDate = new Date();

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

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

const handleNextYear = () => {
setCurrentYear((prevYear) => prevYear + 1);
setSelectedMonthString('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
Loading