-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from 13 commits
b649cbc
e78b1e9
f74d84f
15d720e
df4baf4
8447d7b
e0abd1f
8dfecce
05fd288
a1546f1
8ab9f90
1f5f4df
9f87289
e9fea31
cae3003
89f24fa
acdd4c9
0984121
7a59d81
b009245
2b7a79c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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]); | ||
|
||
const handleSelectedId = (id: string) => { | ||
setSelectedId(id); | ||
}; | ||
|
@@ -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; | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요고는 의도가 무엇이죠 ??? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 달이 바뀔 때 스크롤 됐던 부분을 좌측으로 스크롤해주고자 작성해주었습니다 ! |
||
}; | ||
|
||
return ( | ||
<Flex | ||
styles={{ | ||
|
@@ -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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { endOfMonth } from 'date-fns'; | |
|
||
import { useState } from 'react'; | ||
|
||
export const useDate = () => { | ||
export const useDate = (ref: React.RefObject<HTMLDivElement>) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 재사용성이 낮아진다는 의견에 동의해요! |
||
const currentDate = new Date(); | ||
|
||
const [currentYear, setCurrentYear] = useState(currentDate.getFullYear()); | ||
|
@@ -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 { | ||
|
There was a problem hiding this comment.
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
를 적용하신거 너무 보기 좋네요 :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 수정하겠습니다 !! 감사합니당