mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-18 03:40:23 +01:00
refactor: address GitHub Copilot review comments
- Remove unnecessary currentSegment from skipSegment dependency array - Remove redundant wrappedSeek wrapper (ref guard prevents issues) - Document 200ms setTimeout delay for seek operations - Improve code clarity and reduce unnecessary re-renders
This commit is contained in:
@@ -313,9 +313,12 @@ export const Controls: FC<Props> = ({
|
|||||||
const maxSeconds = maxMs ? msToSeconds(maxMs) : undefined;
|
const maxSeconds = maxMs ? msToSeconds(maxMs) : undefined;
|
||||||
|
|
||||||
// Wrapper to convert segment skip from seconds to milliseconds
|
// Wrapper to convert segment skip from seconds to milliseconds
|
||||||
|
// Includes 200ms delay to allow seek operation to complete before resuming playback
|
||||||
const seekMs = useCallback(
|
const seekMs = useCallback(
|
||||||
(timeInSeconds: number) => {
|
(timeInSeconds: number) => {
|
||||||
seek(timeInSeconds * 1000);
|
seek(timeInSeconds * 1000);
|
||||||
|
// Brief delay ensures the seek operation completes before resuming playback
|
||||||
|
// Without this, playback may resume from the old position
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
play();
|
play();
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|||||||
@@ -53,14 +53,6 @@ export const useSegmentSkipper = ({
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Memoize the seek wrapper to prevent cascading useEffect triggers
|
|
||||||
const wrappedSeek = useCallback(
|
|
||||||
(time: number) => {
|
|
||||||
seek(time);
|
|
||||||
},
|
|
||||||
[seek],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Find current segment
|
// Find current segment
|
||||||
const currentSegment =
|
const currentSegment =
|
||||||
segments.find(
|
segments.find(
|
||||||
@@ -76,9 +68,9 @@ export const useSegmentSkipper = ({
|
|||||||
// For Outro segments, prevent seeking past the end
|
// For Outro segments, prevent seeking past the end
|
||||||
if (segmentType === "Outro" && totalDuration) {
|
if (segmentType === "Outro" && totalDuration) {
|
||||||
const seekTime = Math.min(currentSegment.endTime, totalDuration);
|
const seekTime = Math.min(currentSegment.endTime, totalDuration);
|
||||||
wrappedSeek(seekTime);
|
seek(seekTime);
|
||||||
} else {
|
} else {
|
||||||
wrappedSeek(currentSegment.endTime);
|
seek(currentSegment.endTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only trigger haptic feedback if explicitly requested (manual skip)
|
// Only trigger haptic feedback if explicitly requested (manual skip)
|
||||||
@@ -86,7 +78,7 @@ export const useSegmentSkipper = ({
|
|||||||
haptic();
|
haptic();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[currentSegment, segmentType, totalDuration, wrappedSeek, haptic],
|
[segmentType, totalDuration, seek, haptic],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Auto-skip logic when mode is 'auto'
|
// Auto-skip logic when mode is 'auto'
|
||||||
|
|||||||
Reference in New Issue
Block a user