Skip to content

Commit

Permalink
chore: add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
corinthionia committed Apr 29, 2024
1 parent 1b35488 commit 2a4be68
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 96 deletions.
14 changes: 8 additions & 6 deletions src/components/addTime/calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ const Calendar = ({

const [date, setDate] = useState<Date>(new Date());

// date: ํ˜„์žฌ ์บ˜๋ฆฐ๋”์— ๋ณด์ด๋Š” ๋‚ ์งœ๋“ค (react-calendar)
// return: class name (string)
const addTileClassName = ({ date }: { date: Date }) => {
// ์ผ์ • ๋“ฑ๋ก์ด ๊ฐ€๋Šฅํ•œ ๋‚ ์งœ์ธ ๊ฒฝ์šฐ
if (dates.indexOf(dayjs(date).format('YYYY-MM-DD')) !== -1) {
// ์„ ํƒ๋œ ๋‚ ์งœ์ธ ๊ฒฝ์šฐ
if (selected.indexOf(dayjs(date).format('YYYY-MM-DD 00:00')) !== -1) {
return `selected valid availableDate${dayjs(date).format(
'YYYY-MM-DD'
Expand All @@ -47,24 +51,22 @@ const Calendar = ({
};

useEffect(() => {
const index = selected.indexOf(`${dayjs(date).format('YYYY-MM-DD')} 00:00`);

const element = document.querySelector(
`.availableDate${dayjs(date).format('YYYY-MM-DD')}`
) as HTMLElement;

if (element) {
if (index === -1) {
element.classList.add('selected');
setSelected([...selected, `${dayjs(date).format('YYYY-MM-DD')} 00:00`]);
} else {
if (selected.includes(`${dayjs(date).format('YYYY-MM-DD')} 00:00`)) {
element.classList.remove('selected');
setSelected(
selected.filter(
(availableDate: string) =>
availableDate !== `${dayjs(date).format('YYYY-MM-DD')} 00:00`
)
);
} else {
element.classList.add('selected');
setSelected([...selected, `${dayjs(date).format('YYYY-MM-DD')} 00:00`]);
}
}
}, [date]);
Expand Down
25 changes: 19 additions & 6 deletions src/components/addTime/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import {
} from './index.styles';
import { TableType } from '../tableArea/index.types';

interface ValidDateType {
date: string;
isValidDate: boolean;
}

const Table = ({
contentRef,
selected,
Expand All @@ -28,12 +33,12 @@ const Table = ({
isResetButtonClick,
setIsResetButtonClick,
}: TableType) => {
const timeDetail = getTimeArray(times);

const selectoRef = useRef<any>(null);
const timeDetail = getTimeArray(times);

useEffect(() => {
if (selected[tablePage]) {
// ๋“ฑ๋กํ–ˆ๋˜ ์ผ์ •์„ ์ˆ˜์ •ํ•  ๊ฒฝ์šฐ className ์ œ๊ฑฐํ•˜๋Š” ๊ณผ์ • ํ•„์š”
const selectedElements = document.querySelectorAll('.selected');
selectedElements.forEach((element) => {
element.classList.remove('selected');
Expand All @@ -44,40 +49,48 @@ const Table = ({
element?.classList.add('selected');
});

// ํŽ˜์ด์ง€ ์ง„์ž… ์‹œ ์ด์ „์— ์„ ํƒํ–ˆ๋˜ ์นธ์— ์„ ํƒ ํ‘œ์‹œ
selectoRef.current.setSelectedTargets(
selected[tablePage].map((id) => document.getElementById(id))
);
}
}, [tablePage, selected]);

// ์‹œ๊ฐ„ ์„ ํƒ ๋ฐฉ๋ฒ•์„ ํ† ๊ธ€ํ•˜๋ฉด ์„ ํƒํ•œ ํ•ญ๋ชฉ ์ดˆ๊ธฐํ™”
useEffect(() => {
selectoRef.current.setSelectedTargets([]);
setIsResetButtonClick(false);
}, [selectedMethod, isResetButtonClick]);

// Selecto ์ปดํฌ๋„ŒํŠธ์— ์ „๋‹ฌํ•  onSelect ํ•ธ๋“ค๋Ÿฌ
const handleCellSelect = (e: any) => {
if (e.inputEvent.type !== 'touchstart') {
e.added.forEach((el: any) => {
e.added.forEach((el: HTMLElement) => {
el.classList.add('selected');
});

e.removed.forEach((el: any) => {
e.removed.forEach((el: HTMLElement) => {
el.classList.remove('selected');
});
}
};

const addSelectedToObject = () => {
// ํ˜„์žฌ table page์—์„œ ์„ ํƒ๋œ ์‹œ๊ฐ„
const newArr: string[] = Array.from(
document.querySelectorAll('.selected')
).map((node: Element) => node.id);

// key: table page
// value: ๊ฐ table page์—์„œ ์„ ํƒ๋œ ์‹œ๊ฐ„ ๋ฐฐ์—ด
const newObj = { ...selected };

newObj[tablePage] = newArr;

setSelected(newObj);
};

// ํ•œ ์นธ์”ฉ ํด๋ฆญํ•ด์„œ ์„ ํƒํ•  ๊ฒฝ์šฐ
const handleClickOneElement = (
e: React.MouseEvent<HTMLDivElement> | React.TouchEvent<HTMLDivElement>
) => {
Expand All @@ -102,7 +115,7 @@ const Table = ({
<Blank />
<DateWrapper>
{validDateChunks[tablePage].map(
({ date, isValidDate }: { date: string; isValidDate: boolean }) =>
({ date, isValidDate }: ValidDateType) =>
date.slice(0, 5) === 'blank' ? (
<Date key={date} isValidDate={isValidDate} />
) : (
Expand All @@ -122,7 +135,7 @@ const Table = ({
</TimeWrapper>

{validDateChunks[tablePage]?.map(
({ date, isValidDate }: { date: string; isValidDate: boolean }) => (
({ date, isValidDate }: ValidDateType) => (
<SelectWrapper key={date} className="container">
<Selecto
className="mpr-designer-selection"
Expand Down
14 changes: 7 additions & 7 deletions src/components/addTime/tableArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ const TableArea = ({
if (data) {
const newObj: TableSelectedTypes = {};

data.availableDateTimes.forEach((time: string) => {
validDateChunks.map((chunk, index) => {
chunk.map((date) => {
if (date.date.slice(0, 10) === time.slice(0, 10)) {
if (newObj[index] === undefined) {
newObj[index] = [time];
data.availableDateTimes.forEach((date: string) => {
validDateChunks.map((chunk, tablePage) => {
chunk.map((item) => {
if (item.date.slice(0, 10) === date.slice(0, 10)) {
if (newObj[tablePage]) {
newObj[tablePage].push(date);
} else {
newObj[index].push(time);
newObj[tablePage] = [date];
}
}
});
Expand Down
9 changes: 7 additions & 2 deletions src/components/addTime/tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import {
import guideIcon from '@/assets/icons/guide.png';
import guideHandle from '@/assets/icons/guideHandle.png';
import closeIcon from '@/assets/icons/close.png';
import { useCallback } from 'react';
import { Dispatch, SetStateAction, useCallback } from 'react';

const Tooltip = ({ isTooltipShown, setIsTooltipShown }: any) => {
interface Props {
isTooltipShown: boolean;
setIsTooltipShown: Dispatch<SetStateAction<boolean>>;
}

const Tooltip = ({ isTooltipShown, setIsTooltipShown }: Props) => {
const handleGuideCloseClick = useCallback(() => {
localStorage.setItem('isTooltipShown', JSON.stringify(false));
setIsTooltipShown(false);
Expand Down
12 changes: 9 additions & 3 deletions src/components/createRoom/calendar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { useCallback, useEffect, useState } from 'react';
import {
Dispatch,
SetStateAction,
useCallback,
useEffect,
useState,
} from 'react';
import { DateObject, getAllDatesInRange } from 'react-multi-date-picker';
import {
CalendarComponent,
Expand All @@ -9,8 +15,8 @@ import Toggle from '../toggle';

interface Calendar {
dates: string[];
setDates: React.Dispatch<React.SetStateAction<string[]>>;
setMonth: React.Dispatch<React.SetStateAction<string>>;
setDates: Dispatch<SetStateAction<string[]>>;
setMonth: Dispatch<SetStateAction<string>>;
}

const Calendar = ({ dates, setDates, setMonth }: Calendar) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/current/shareLinkBottomSheet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { useRecoilState } from 'recoil';
import { useSetRecoilState } from 'recoil';
import { LinkShareBottomSheetState } from '@/atoms/LinkShareBottomSheetAtom';

import {
Expand All @@ -23,7 +23,7 @@ const ShareLinkBottomSheet = () => {
const { inviteURL, handleUseShareAPI, handleCopyToClipBoard } =
useShareLink();

const [, setIsLinkShareBottomSheetOpened] = useRecoilState(
const setIsLinkShareBottomSheetOpened = useSetRecoilState(
LinkShareBottomSheetState
);

Expand Down
44 changes: 16 additions & 28 deletions src/components/current/table/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';

import {
Expand All @@ -14,8 +13,6 @@ import {
Wrapper,
} from './index.styles';

import { AvailableDateTimeTypes } from '@/types/current';

import { getTimeRange } from '@/utils/getTimeRange';
import { getTableDateFormat } from '@/utils/getTableDateFormat';
import { getCurrentTableInfo } from '@/utils/getCurrentTableInfo';
Expand All @@ -32,20 +29,8 @@ const Table = ({ dates, startTime, endTime, participants }: TableTypes) => {
const { roomUUID } = useParams() as { roomUUID: string };
const timeRange = getTimeRange(parseInt(startTime), parseInt(endTime));

const [currentTableInfo, setCurrentTableInfo] = useState<
AvailableDateTimeTypes[]
>([]);

const { data } = useGetAvailableTimesByGroup(roomUUID);

useEffect(() => {
if (data) {
setCurrentTableInfo(
getCurrentTableInfo(data.availableDateTimes, timeRange)
);
}
}, [data]);

return (
<Wrapper>
<Top>
Expand All @@ -70,19 +55,22 @@ const Table = ({ dates, startTime, endTime, participants }: TableTypes) => {
))}
</TimeWrapper>

{currentTableInfo.map(({ availableDate, availableTimeInfos }: any) => (
<SelectWrapper key={availableDate}>
{availableTimeInfos.map(
({ time, count }: { time: number; count: number }) => (
<Select
key={`${availableDate} ${time}`}
count={count}
total={participants.length}
/>
)
)}
</SelectWrapper>
))}
{data &&
getCurrentTableInfo(data.availableDateTimes, timeRange).map(
({ availableDate, availableTimeInfos }: any) => (
<SelectWrapper key={availableDate}>
{availableTimeInfos.map(
({ time, count }: { time: number; count: number }) => (
<Select
key={`${availableDate} ${time}`}
count={count}
total={participants.length}
/>
)
)}
</SelectWrapper>
)
)}
</Bottom>
</Wrapper>
);
Expand Down
15 changes: 9 additions & 6 deletions src/hooks/useScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ export const useScroll = () => {

const onMouseMove = (e: MouseEvent) => {
const newTop = e.clientY - shiftY - track.getBoundingClientRect().top;
const bottomEdge = track.offsetHeight - thumb.offsetHeight;

const updatedOffsetY = Math.min(Math.max(0, newTop), bottomEdge);
// track์—์„œ thumb์˜ ์œ„์น˜
// 0์ผ ๊ฒฝ์šฐ thumb๋Š” track์˜ ์ตœ์ƒ๋‹จ์— ์œ„์น˜
const diff = track.offsetHeight - thumb.offsetHeight;

const updatedOffsetY = Math.min(Math.max(0, newTop), diff);
setOffsetY(updatedOffsetY);
};

const onMouseUp = () => {
document.removeEventListener('mouseup', onMouseUp);
document.removeEventListener('mousemove', onMouseMove);
document.removeEventListener('mouseup', onMouseUp);
};

document.addEventListener('mousemove', onMouseMove);
Expand All @@ -46,15 +49,15 @@ export const useScroll = () => {
const onTouchMove = (e: TouchEvent) => {
const newTop =
e.touches[0].clientY - shiftY - track.getBoundingClientRect().top;
const bottomEdge = track.offsetHeight - thumb.offsetHeight;
const diff = track.offsetHeight - thumb.offsetHeight;

const updatedOffsetY = Math.min(Math.max(0, newTop), bottomEdge);
const updatedOffsetY = Math.min(Math.max(0, newTop), diff);
setOffsetY(updatedOffsetY);
};

const onTouchEnd = () => {
document.removeEventListener('touchend', onTouchEnd);
document.removeEventListener('touchmove', onTouchMove);
document.removeEventListener('touchend', onTouchEnd);
};

document.addEventListener('touchmove', onTouchMove);
Expand Down
18 changes: 5 additions & 13 deletions src/pages/addTime/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react';
import { useRef, useState } from 'react';
import { useParams } from 'react-router-dom';
import { useRecoilState } from 'recoil';

Expand All @@ -11,10 +11,8 @@ import AddToggle from '@/components/addTime/toggle';
import AddTimeTable from '@/components/addTime/tableArea';
import AddCalendar from '@/components/addTime/calendar';
import { Body, Main, Title, TitleWrapper, Wrapper } from './index.styles';
import { initialRoomInfoData } from '@/assets/data/initialRoomInfoData';

import { TableSelectedTypes } from './index.types';
import { RoomTypes } from '@/types/roomInfo';

import { useGetRoomInfo } from '@/queries/room/useGetRoomInfo';
import { ROUTES } from '@/constants/ROUTES';
Expand All @@ -34,15 +32,9 @@ const AddTime = () => {
const [isTooltipShown, setIsTooltipShown] =
useRecoilState<boolean>(tooltipState);

const { data } = useGetRoomInfo(roomUUID);
const [{ title, dates, startTime, endTime }, setRoomInfo] =
useState<RoomTypes>(initialRoomInfoData);

useEffect(() => {
if (data) {
setRoomInfo(data);
}
}, [data]);
const {
data: { title, dates, startTime, endTime },
} = useGetRoomInfo(roomUUID);

const isTableView = startTime !== null && endTime !== null ? true : false;

Expand All @@ -63,7 +55,7 @@ const AddTime = () => {
<Title>์‹œ๊ฐ„์œผ๋กœ ์„ ํƒํ•ด ์ฃผ์„ธ์š”</Title>
</TitleWrapper>
<Main>
{startTime !== null && endTime !== null ? (
{isTableView ? (
<AddTimeTable
wrapperRef={wrapperRef}
startTime={parseInt(startTime)}
Expand Down
16 changes: 7 additions & 9 deletions src/utils/getAddTimeTableInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ export const getAddTimeTableInfo = (dates: string[]) => {
newDates = [...newDates, `blank${i}`];
}

const validDates: ValidDate[][] = [
newDates.map((date: string) =>
date.slice(0, 5) === 'blank'
? { date: date, isValidDate: false }
: { date: date, isValidDate: true }
),
];
const validDates: ValidDate[] = newDates.map((date: string) =>
date.slice(0, 5) === 'blank'
? { date: date, isValidDate: false }
: { date: date, isValidDate: true }
);

let dateChunks: Array<ValidDate[]> = [];

for (let i = 0; i < validDates[0].length; i += 3) {
dateChunks = [...dateChunks, validDates[0].slice(i, i + 3)];
for (let i = 0; i < validDates.length; i += 3) {
dateChunks = [...dateChunks, validDates.slice(i, i + 3)];
}

return dateChunks;
Expand Down
Loading

0 comments on commit 2a4be68

Please sign in to comment.