Skip to content

Commit

Permalink
refactor: useTimeState 훅 코드리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
hamo-o committed Aug 28, 2024
1 parent a4753b1 commit 0aa29cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
10 changes: 6 additions & 4 deletions packages/wow-ui/src/components/Picker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ const TimePicker = forwardRef<HTMLDivElement, TimePickerProps>(
};
const setSelectedTime = context?.setSelectedTime || propSetSelectedTime!;

const { isAM, handleClickAMOrPM, handleChangeHour, handleChangeMinute } =
useTimeState({ selectedTime, setSelectedTime });
const { isAM, handleClickAMOrPM, handleChangeTime } = useTimeState({
selectedTime,
setSelectedTime,
});

const strTime = formatTimeToString(selectedTime);

Expand Down Expand Up @@ -77,7 +79,7 @@ const TimePicker = forwardRef<HTMLDivElement, TimePickerProps>(
{strTime.hour}
</button>
}
onChange={handleChangeHour}
onChange={(value) => handleChangeTime("hour", value)}
>
{hours.map((hour) => (
<DropDownOption
Expand All @@ -98,7 +100,7 @@ const TimePicker = forwardRef<HTMLDivElement, TimePickerProps>(
{strTime.minute}
</button>
}
onChange={handleChangeMinute}
onChange={(value) => handleChangeTime("minute", value)}
>
{minutes.map((minute) => (
<DropDownOption
Expand Down
26 changes: 7 additions & 19 deletions packages/wow-ui/src/hooks/useTimeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,21 @@ const useTimeState = ({ selectedTime, setSelectedTime }: TimeStateProps) => {
setIsAM((prev) => !prev);
};

const handleChangeHour = (value: {
selectedValue: string;
selectedText: React.ReactNode;
}) => {
const handleChangeTime = (
type: "hour" | "minute",
value: { selectedValue: string; selectedText: React.ReactNode }
) => {
setSelectedTime({
isAM: isAM,
hour: +value.selectedValue,
minute: selectedTime.minute,
});
};

const handleChangeMinute = (value: {
selectedValue: string;
selectedText: React.ReactNode;
}) => {
setSelectedTime({
isAM: isAM,
hour: selectedTime.hour,
minute: +value.selectedValue,
hour: type === "hour" ? +value.selectedValue : selectedTime.hour,
minute: type === "minute" ? +value.selectedValue : selectedTime.minute,
});
};

return {
isAM,
handleClickAMOrPM,
handleChangeHour,
handleChangeMinute,
handleChangeTime,
};
};

Expand Down

0 comments on commit 0aa29cd

Please sign in to comment.