-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/#499' into myPartQA
- Loading branch information
Showing
10 changed files
with
249 additions
and
37 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { useMemo, useRef, useState } from 'react'; | ||
import useCollectingPartContext from '@/features/killingParts/hooks/useCollectingPartContext'; | ||
import { toMinSecText } from '@/shared/utils/convertTime'; | ||
|
||
interface Pin { | ||
partStartTime: number; | ||
interval: number; | ||
text: string; | ||
} | ||
|
||
const usePin = () => { | ||
const { partStartTime, interval, setPartStartTime, setInterval } = useCollectingPartContext(); | ||
const [pinList, setPinList] = useState<Pin[]>([]); | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
const activePinIndex = useMemo( | ||
() => | ||
pinList.findIndex((pin) => pin.partStartTime === partStartTime && pin.interval === interval), | ||
[pinList, partStartTime, interval] | ||
); | ||
|
||
const isPinListEmpty = pinList.length === 0; | ||
|
||
const pinAnimationRef = useRef<number>(1); | ||
const refreshPinAnimation = () => { | ||
pinAnimationRef.current += 1; | ||
}; | ||
|
||
const addPin = () => { | ||
const text = `${toMinSecText(partStartTime)}`; | ||
|
||
setPinList((prevTimeList) => [ | ||
{ | ||
partStartTime, | ||
interval, | ||
text, | ||
}, | ||
...prevTimeList.filter((pin) => pin.text !== text), | ||
]); | ||
|
||
if (ref.current) { | ||
ref.current.scrollTo({ | ||
left: 0, | ||
behavior: 'smooth', | ||
}); | ||
} | ||
|
||
refreshPinAnimation(); | ||
}; | ||
|
||
const deletePin = () => { | ||
if (activePinIndex >= 0) { | ||
setPinList(pinList.filter((_, index) => index !== activePinIndex)); | ||
} else { | ||
setPinList(pinList.slice(1)); | ||
} | ||
}; | ||
|
||
const playPin = (start: number, interval: number) => () => { | ||
setPartStartTime(start); | ||
setInterval(interval); | ||
}; | ||
|
||
return { | ||
pinList, | ||
isPinListEmpty, | ||
activePinIndex, | ||
pinAnimationRef, | ||
ref, | ||
addPin, | ||
deletePin, | ||
playPin, | ||
}; | ||
}; | ||
|
||
export default usePin; |
Oops, something went wrong.