-
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
Feat/#479 킬링파트 등록 시 구간 선택을 토글 형식으로 변경 #482
Changes from all commits
a7c7a78
5cda5c3
35843b1
a45c321
a1e960e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,16 +16,16 @@ const VoteInterface = () => { | |
const { showToast } = useToastContext(); | ||
const { interval, partStartTime, songId, songVideoId } = useVoteInterfaceContext(); | ||
const { videoPlayer } = useVideoPlayerContext(); | ||
|
||
const { createKillingPart } = usePostKillingPart(); | ||
const { isOpen, openModal, closeModal } = useModal(); | ||
|
||
const { user } = useAuthContext(); | ||
|
||
const voteTimeText = toPlayingTimeText(partStartTime, partStartTime + interval); | ||
|
||
const voteTimeText = interval ? toPlayingTimeText(partStartTime, partStartTime + interval) : ''; | ||
const isDisabledSummit = interval === null; | ||
const submitKillingPart = async () => { | ||
if (!interval) return; | ||
videoPlayer.current?.pauseVideo(); | ||
|
||
await createKillingPart(songId, { startSecond: partStartTime, length: interval }); | ||
openModal(); | ||
}; | ||
|
@@ -46,9 +46,15 @@ const VoteInterface = () => { | |
<Spacing direction="vertical" size={24} /> | ||
<VideoSlider /> | ||
<Spacing direction="vertical" size={16} /> | ||
<Register type="button" onClick={submitKillingPart}> | ||
<Register type="button" onClick={submitKillingPart} disabled={isDisabledSummit}> | ||
등록 | ||
</Register> | ||
{isDisabledSummit && ( | ||
<> | ||
<Spacing direction="vertical" size={8} /> | ||
<Information>킬링파트 구간 선택 후 등록이 가능합니다.</Information> | ||
</> | ||
)} | ||
|
||
<Modal isOpen={isOpen} closeModal={closeModal}> | ||
<ModalTitle> | ||
|
@@ -90,15 +96,16 @@ const RegisterTitle = styled.p` | |
`; | ||
|
||
const Register = styled.button` | ||
cursor: pointer; | ||
cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')}; | ||
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. globalStyle로 가면 좋을 것 같네요! button {
cursor: pointer;
background: none;
border: 0;
&:disabled {
cursor: not-allowed;
}
} |
||
|
||
width: 100%; | ||
height: 36px; | ||
|
||
font-weight: 700; | ||
color: ${({ theme: { color } }) => color.white}; | ||
color: ${({ theme: { color }, disabled }) => (disabled ? color.disabled : color.white)}; | ||
|
||
background-color: ${({ theme: { color } }) => color.primary}; | ||
background-color: ${({ theme: { color }, disabled }) => | ||
disabled ? color.disabledBackground : color.primary}; | ||
border: none; | ||
border-radius: 10px; | ||
`; | ||
|
@@ -150,3 +157,7 @@ const ButtonContainer = styled.div` | |
const Warning = styled.div` | ||
color: ${({ theme: { color } }) => color.subText}; | ||
`; | ||
|
||
const Information = styled.p` | ||
color: ${({ theme: { color } }) => color.primary}; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
interface VoteInterfaceContextProps extends VoteInterfaceProviderProps { | ||
partStartTime: number; | ||
interval: KillingPartInterval; | ||
interval: KillingPartInterval | null; | ||
// NOTE: Why both setState and eventHandler have same naming convention? | ||
updatePartStartTime: (timeUnit: string, value: number) => void; | ||
updateKillingPartInterval: React.MouseEventHandler<HTMLButtonElement>; | ||
|
@@ -25,19 +25,25 @@ | |
songId, | ||
songVideoId, | ||
}: PropsWithChildren<VoteInterfaceProviderProps>) => { | ||
const [interval, setInterval] = useState<KillingPartInterval>(10); | ||
const [interval, setInterval] = useState<KillingPartInterval | null>(10); | ||
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 [partStartTime, setPartStartTime] = useState(0); | ||
const { videoPlayer } = useVideoPlayerContext(); | ||
|
||
const updateKillingPartInterval: React.MouseEventHandler<HTMLButtonElement> = (e) => { | ||
const newInterval = Number(e.currentTarget.dataset['interval']) as KillingPartInterval; | ||
if (newInterval === interval) { | ||
setInterval(null); | ||
return; | ||
} | ||
|
||
const partEndTime = partStartTime + newInterval; | ||
|
||
if (partEndTime > videoLength) { | ||
const overflowedSeconds = partEndTime - videoLength; | ||
setPartStartTime(partStartTime - overflowedSeconds); | ||
} | ||
|
||
videoPlayer.current?.seekTo(partStartTime, true); | ||
setInterval(newInterval); | ||
}; | ||
|
||
|
@@ -62,12 +68,13 @@ | |
}; | ||
|
||
useEffect(() => { | ||
if (!interval) return; | ||
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 timer = window.setInterval(() => { | ||
videoPlayer.current?.seekTo(partStartTime, true); | ||
}, interval * 1000); | ||
|
||
return () => window.clearInterval(timer); | ||
}, [videoPlayer.current, partStartTime, interval]); | ||
Check warning on line 77 in frontend/src/features/songs/components/VoteInterfaceProvider.tsx GitHub Actions / test
|
||
|
||
return ( | ||
<VoteInterfaceContext.Provider | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,12 @@ const VideoSlider = () => { | |
const { interval, partStartTime, videoLength, updatePartStartTime } = useVoteInterfaceContext(); | ||
const { videoPlayer } = useVideoPlayerContext(); | ||
|
||
const partEndTime = partStartTime + interval; | ||
const partStartTimeText = toMinSecText(partStartTime); | ||
const partEndTimeText = toMinSecText(partEndTime); | ||
const partStartTimeText = interval ? toMinSecText(partStartTime) : toMinSecText(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. |
||
const partEndTimeText = interval | ||
? toMinSecText(partStartTime + interval) | ||
: toMinSecText(videoLength); | ||
|
||
const maxPlayingTime = interval ? videoLength - interval : videoLength; | ||
|
||
const changeTime: ChangeEventHandler<HTMLInputElement> = ({ | ||
currentTarget: { valueAsNumber: currentSelectedTime }, | ||
|
@@ -40,7 +43,7 @@ const VideoSlider = () => { | |
onTouchEnd={seekToTime} | ||
onMouseUp={seekToTime} | ||
min={0} | ||
max={videoLength - interval} | ||
max={maxPlayingTime} | ||
step={1} | ||
interval={interval} | ||
/> | ||
|
@@ -86,7 +89,7 @@ export const PartEndTime = styled.span` | |
font-weight: 700; | ||
`; | ||
|
||
const Slider = styled.input<{ interval: number }>` | ||
const Slider = styled.input<{ interval: number | null }>` | ||
cursor: pointer; | ||
|
||
width: 100%; | ||
|
@@ -99,7 +102,7 @@ const Slider = styled.input<{ interval: number }>` | |
position: relative; | ||
top: -4px; | ||
|
||
width: ${({ interval }) => interval * 6}px; | ||
width: ${({ interval }) => (interval ? interval * 6 : 2)}px; | ||
height: 16px; | ||
|
||
-webkit-appearance: none; | ||
|
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.
💬 개행좀 부탁드려도 될까요?😭 22