Skip to content

Commit

Permalink
fix: batching 방식으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
simeunseo committed Jul 5, 2024
1 parent d084000 commit 1abd347
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand All @@ -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) => {
Expand Down

0 comments on commit 1abd347

Please sign in to comment.