From 1abd347cc31cf8cd2fafdd32d8c873721252444e Mon Sep 17 00:00:00 2001 From: Eunseo Sim <55528304+simeunseo@users.noreply.github.com> Date: Sat, 6 Jul 2024 02:29:26 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20batching=20=EB=B0=A9=EC=8B=9D=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../selectTimeSlot/hooks/useSlotSelection.ts | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/pages/selectSchedule/components/selectTimeSlot/hooks/useSlotSelection.ts b/src/pages/selectSchedule/components/selectTimeSlot/hooks/useSlotSelection.ts index 9225b7e6..40bd71cf 100644 --- a/src/pages/selectSchedule/components/selectTimeSlot/hooks/useSlotSelection.ts +++ b/src/pages/selectSchedule/components/selectTimeSlot/hooks/useSlotSelection.ts @@ -21,23 +21,25 @@ const useSlotSeletion = () => { const keys = Object.keys(selectedSlots).map(Number); const newKey = keys.length ? Math.max(...keys) + 1 : 0; - const newSelectedSlots = { ...removeOverlappedSlots(endSlot, dateOfStartSlot) }; - - newSelectedSlots[newKey] = newSelectedSlot; - setSelectedSlots(newSelectedSlots); + setSelectedSlots((prev) => { + const newSelectedSlots = { ...prev }; + newSelectedSlots[newKey] = newSelectedSlot; + return newSelectedSlots; + }); + removeOverlappedSlots(endSlot, dateOfStartSlot); } setStartSlot(undefined); }; const handleDeleteSlot = (selectedEntryId: number) => { - const newSelectedSlots = { ...selectedSlots }; - delete newSelectedSlots[selectedEntryId]; - setSelectedSlots(newSelectedSlots); + setSelectedSlots((prev) => { + const newSelectedSlots = { ...prev }; + delete newSelectedSlots[selectedEntryId]; + return newSelectedSlots; + }); }; const removeOverlappedSlots = (endSlot: string, dateOfStartSlot: string) => { - const newSelectedSlots = { ...selectedSlots }; - const selectedSlotsPerDate = Object.fromEntries( Object.entries(selectedSlots).filter(([, slot]) => slot.date === dateOfStartSlot), ); @@ -51,11 +53,10 @@ const useSlotSeletion = () => { selectedStartSlot > startSlotTime && selectedEndSlot < endSlotTime ) { - delete newSelectedSlots[parseInt(id)]; + handleDeleteSlot(Number(id)); } }, ); - return newSelectedSlots; }; const onClickSlot = (targetSlot: string, selectedEntryId?: number) => {