From f16ecd570f424e30b3505dc70830e141e6d7e039 Mon Sep 17 00:00:00 2001 From: wil Date: Tue, 5 Mar 2024 13:47:07 -0500 Subject: [PATCH] scrubber fully functional --- .../common/VideoQuickTrim/TrimScrubber.tsx | 13 ++++---- .../common/VideoQuickTrim/VideoQuickTrim.tsx | 32 +++++++++++++------ .../common/VideoQuickTrim/types.tsx | 1 + .../pageVSTApp/compAdvanceOptions.tsx | 2 +- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/packages/fakeyou.com/src/components/common/VideoQuickTrim/TrimScrubber.tsx b/packages/fakeyou.com/src/components/common/VideoQuickTrim/TrimScrubber.tsx index a2c97ae23e..b5fb2672af 100644 --- a/packages/fakeyou.com/src/components/common/VideoQuickTrim/TrimScrubber.tsx +++ b/packages/fakeyou.com/src/components/common/VideoQuickTrim/TrimScrubber.tsx @@ -1,7 +1,6 @@ import React, { useRef, useState, - useCallback, PointerEvent } from 'react'; import { @@ -14,7 +13,7 @@ export default function TrimScrubber({ trimStart, trimDuration, duration, - widthPercent, + width, boundingWidth, onChange }:{ @@ -22,7 +21,7 @@ export default function TrimScrubber({ trimDuration: number; duration: number; boundingWidth: number; - widthPercent:number; + width:number; onChange:(val:QuickTrimData)=>void }){ const [{ @@ -35,7 +34,7 @@ export default function TrimScrubber({ pointerStart:number }>({ left: trimStart/duration*boundingWidth, - leftOffset:0,//trimStart/duration*boundingWidth, + leftOffset: trimStart/duration*boundingWidth, pointerStart: -1 }); const ref = useRef(null); @@ -73,8 +72,8 @@ export default function TrimScrubber({ // console.log(`${e.clientX} - ${pointerStart} = ${e.clientX-pointerStart}`) let newLeft = leftOffset + e.clientX - pointerStart; // console.log(`${newLeft} + ${boundingWidth * widthPercent/100} > ${boundingWidth}`) - if (newLeft + boundingWidth * widthPercent/100 > boundingWidth) { - newLeft = boundingWidth - boundingWidth * widthPercent/100; + if (newLeft + width > boundingWidth) { + newLeft = boundingWidth - width; }else if(newLeft < 0) { newLeft = 0; } @@ -88,7 +87,7 @@ export default function TrimScrubber({
(true); const [{ canNotTrim, + trimReset, trimStart, trimEnd, trimDuration, @@ -140,22 +142,29 @@ export default memo(function VideoQuickTrim({ }, []); const handleChangeTrimDuration = (selected: string) =>{ - if(!canNotTrim){ - const newTrimEnd = trimStart+ trimOptions[selected]; + if(!canNotTrim && maxDuration > 0 && trimOptions[selected] <= maxDuration){ + let newTrimStart = trimStart; + let newTrimEnd = trimStart+ trimOptions[selected]; + if (newTrimEnd > maxDuration){ + newTrimEnd = maxDuration; + newTrimStart = maxDuration - trimOptions[selected]; + } setTrimState((curr)=>({ ...curr, + trimReset: new Date(), trimDuration: trimOptions[selected], + trimStart: newTrimStart, trimEnd: newTrimEnd, })) onSelect({ - trimStartSeconds: trimStart, + trimStartSeconds: newTrimStart, trimEndSeconds: newTrimEnd, }); if (isRepeatOn && videoRef.current && videoRef.current.currentTime > newTrimEnd ){ - videoRef.current.currentTime = trimStart; + videoRef.current.currentTime = newTrimStart; } } } @@ -168,10 +177,10 @@ export default memo(function VideoQuickTrim({ } }; - const trimScrubberWidth = videoRef.current + const trimScrubberWidth = videoRef.current && playbarWidth > 0 ? trimDuration > 0 && trimDuration < videoRef.current.duration - ? (trimDuration / videoRef.current.duration * 100) - : 100 + ? (trimDuration / videoRef.current.duration * playbarWidth) + : playbarWidth : 0; return ( @@ -212,9 +221,10 @@ export default memo(function VideoQuickTrim({
{videoRef.current && - } diff --git a/packages/fakeyou.com/src/components/common/VideoQuickTrim/types.tsx b/packages/fakeyou.com/src/components/common/VideoQuickTrim/types.tsx index c8aa5abe3b..4e3dd0db0d 100644 --- a/packages/fakeyou.com/src/components/common/VideoQuickTrim/types.tsx +++ b/packages/fakeyou.com/src/components/common/VideoQuickTrim/types.tsx @@ -7,6 +7,7 @@ export type QuickTrimData = { // INTERNALS export type TrimStates = { canNotTrim: boolean; + trimReset: Date; trimDuration: number; trimStart: number; trimEnd: number; diff --git a/packages/fakeyou.com/src/v2/view/pages/video_styletransfer/components/pageVSTApp/compAdvanceOptions.tsx b/packages/fakeyou.com/src/v2/view/pages/video_styletransfer/components/pageVSTApp/compAdvanceOptions.tsx index be700ae4aa..3948bb95ac 100644 --- a/packages/fakeyou.com/src/v2/view/pages/video_styletransfer/components/pageVSTApp/compAdvanceOptions.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/video_styletransfer/components/pageVSTApp/compAdvanceOptions.tsx @@ -28,7 +28,7 @@ import { defaultPreset, } from "./dataCnPresets"; -export default function SectionAdvanceOptions({ +export default function CompAdvanceOptions({ debug, t, vstValues: vstVal,