Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: improve videos ux (#743)
Ameer Al Ashhaba10c9e067913
diff --git a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsxindex 7cf14aa87..a774ad596 100644--- a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx+++ b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx@@ -502,6 +502,8 @@ export const EmbedVideo = forwardRef<const percentage = Math.max(0, Math.min(1, clickX / rect.width));const seekTime = percentage * longestDuration;+ console.log(seekTime, 'seek time')+videoRef.current.currentTime = seekTime;setCurrentTime(seekTime);};@@ -512,24 +514,28 @@ export const EmbedVideo = forwardRef<handleSeek(e);};- const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {- if (isDragging) {- handleSeek(e);- }- };-- const handleMouseUp = () => {- setIsDragging(false);- };-+ // Global timeline scrubbinguseEffect(() => {- if (isDragging) {- const handleGlobalMouseUp = () => setIsDragging(false);- document.addEventListener("mouseup", handleGlobalMouseUp);- return () =>- document.removeEventListener("mouseup", handleGlobalMouseUp);- }- }, [isDragging]);+ if (!isDragging) return;+ const handleGlobalMouseMove = (e: MouseEvent) => {+ if (!timelineRef.current || !videoRef.current || longestDuration === 0) return;+ const rect = timelineRef.current.getBoundingClientRect();+ const x = e.clientX - rect.left;+ const percentage = Math.max(0, Math.min(1, x / rect.width));+ const seekTime = percentage * longestDuration;+ videoRef.current.currentTime = seekTime;+ setCurrentTime(seekTime);+ };+ const handleGlobalMouseUp = () => {+ setIsDragging(false);+ };+ document.addEventListener("mousemove", handleGlobalMouseMove);+ document.addEventListener("mouseup", handleGlobalMouseUp);+ return () => {+ document.removeEventListener("mousemove", handleGlobalMouseMove);+ document.removeEventListener("mouseup", handleGlobalMouseUp);+ };+ }, [isDragging, longestDuration]);const handleChapterSeek = (chapterStart: number) => {if (!videoRef.current) return;@@ -583,12 +589,11 @@ export const EmbedVideo = forwardRef<return (<divid="embed-video-container"- className="relative w-screen h-screen bg-black overflow-hidden group"+ className="overflow-hidden relative w-screen h-screen bg-black group"><div- className={`absolute inset-0 flex items-center justify-center z-10 bg-black transition-opacity duration-300 ${- isLoading ? "opacity-100" : "opacity-0 pointer-events-none"- }`}+ className={`absolute inset-0 flex items-center justify-center z-10 bg-black transition-opacity duration-300 ${isLoading ? "opacity-100" : "opacity-0 pointer-events-none"+ }`}><LogoSpinner className="w-8 h-auto animate-spin xs:w-10" /></div>@@ -602,13 +607,12 @@ export const EmbedVideo = forwardRef<</div>{!isLoading && (<div- className={`absolute inset-0 z-20 flex flex-col items-center justify-center transition-opacity duration-300 ${- (overlayVisible && isPlaying) ||+ className={`absolute inset-0 z-20 flex flex-col items-center justify-center transition-opacity duration-300 ${(overlayVisible && isPlaying) ||tempOverlayVisible ||!isPlaying- ? "opacity-100"- : "opacity-0"- }`}+ ? "opacity-100"+ : "opacity-0"+ }`}><buttonaria-label={isPlaying ? "Pause video" : "Play video"}@@ -621,12 +625,12 @@ export const EmbedVideo = forwardRef<}}}>- <div className="flex flex-col items-center gap-4">+ <div className="flex flex-col gap-4 items-center"><AnimatePresence initial={false} mode="popLayout">{isPlaying ? (<motion.divkey="pause-button"- className="flex relative z-30 justify-center items-center size-16 xs:size-20 md:size-24 bg-black bg-opacity-60 rounded-full"+ className="flex relative z-30 justify-center items-center bg-black bg-opacity-60 rounded-full size-16 xs:size-20 md:size-24"initial={{ opacity: 0, scale: 0 }}animate={{scale: 1,@@ -640,7 +644,7 @@ export const EmbedVideo = forwardRef<) : (<motion.divkey="play-button"- className="flex relative z-30 justify-center items-center size-16 xs:size-20 md:size-24 bg-black bg-opacity-60 rounded-full"+ className="flex relative z-30 justify-center items-center bg-black bg-opacity-60 rounded-full size-16 xs:size-20 md:size-24"initial={{ opacity: 0, scale: 0 }}animate={{scale: 1,@@ -664,7 +668,7 @@ export const EmbedVideo = forwardRef<e.stopPropagation();window.open("https://cap.so", "_blank");}}- className="hidden xs:flex items-center gap-2 text-white/80 hover:text-white transition-colors duration-200 text-sm bg-black/50 px-3 py-2 rounded-full backdrop-blur-sm"+ className="hidden gap-2 items-center px-3 py-2 text-sm rounded-full backdrop-blur-sm transition-colors duration-200 xs:flex text-white/80 hover:text-white bg-black/50"aria-label="Powered by Cap"><span className="text-sm text-white/80">Powered by</span>@@ -686,15 +690,15 @@ export const EmbedVideo = forwardRef<className="absolute top-2 left-2 xs:top-6 xs:left-6 z-30 max-w-[calc(100%-1rem)] xs:max-w-2xl"><div className="bg-gradient-to-r from-black/70 to-black/50 backdrop-blur-md rounded-lg sm:rounded-xl px-2 py-1.5 sm:px-4 sm:py-3 border border-white/10 shadow-2xl">- <div className="flex items-center gap-2 sm:gap-3">+ <div className="flex gap-2 items-center sm:gap-3">{ownerName && (<Avatarname={ownerName}- className="hidden xs:flex xs:size-10 flex-shrink-0"+ className="hidden flex-shrink-0 xs:flex xs:size-10"letterClass="xs:text-base font-medium"/>)}- <div className="min-w-0 flex-1">+ <div className="flex-1 min-w-0"><ahref={`/s/${data.id}`}target="_blank"@@ -702,21 +706,21 @@ export const EmbedVideo = forwardRef<className="block"onClick={(e) => e.stopPropagation()}>- <h1 className="text-white text-sm sm:text-xl md:text-2xl font-semibold leading-tight truncate hover:underline transition-all duration-200 cursor-pointer">+ <h1 className="text-sm font-semibold leading-tight text-white truncate transition-all duration-200 cursor-pointer sm:text-xl md:text-2xl hover:underline">{data.name}</h1></a><div className="flex items-center gap-1 sm:gap-2 mt-0.5 sm:mt-1">{ownerName && (- <p className="text-gray-300 text-xs sm:text-sm font-medium truncate">+ <p className="text-xs font-medium text-gray-300 truncate sm:text-sm">{ownerName}</p>)}{ownerName && longestDuration > 0 && (- <span className="text-gray-400 text-xs">•</span>+ <span className="text-xs text-gray-400">•</span>)}{longestDuration > 0 && (- <p className="text-gray-300 text-xs sm:text-sm">+ <p className="text-xs text-gray-300 sm:text-sm">{formatTime(longestDuration)}</p>)}@@ -730,11 +734,10 @@ export const EmbedVideo = forwardRef<{currentSubtitle && currentSubtitle.text && subtitlesVisible && (<div- className={`absolute z-10 p-2 w-full text-center transition-all duration-300 ease-in-out ${- overlayVisible- ? "bottom-24 xs:bottom-24"- : "bottom-8 xs:bottom-8"- }`}+ className={`absolute z-10 p-2 w-full text-center transition-all duration-300 ease-in-out ${overlayVisible+ ? "bottom-24 xs:bottom-24"+ : "bottom-8 xs:bottom-8"+ }`}><div className="inline px-3 py-2 text-base text-white bg-black bg-opacity-75 rounded-xl xs:text-lg md:text-2xl max-w-[90%] xs:max-w-none">{currentSubtitle.text@@ -752,11 +755,11 @@ export const EmbedVideo = forwardRef<animate={{ opacity: 1 }}exit={{ opacity: 0 }}transition={{ duration: 0.3 }}- className="hidden xs:flex absolute top-4 left-4 xs:top-6 xs:left-6 z-30"+ className="hidden absolute top-4 left-4 z-30 xs:flex xs:top-6 xs:left-6"><buttononClick={() => window.open("https://cap.so", "_blank")}- className="opacity-30 hover:opacity-100 transition-opacity duration-200 cursor-pointer"+ className="opacity-30 transition-opacity duration-200 cursor-pointer hover:opacity-100"aria-label="Powered by Cap"><Logo className="w-auto h-6 xs:h-8" white={true} />@@ -767,18 +770,14 @@ export const EmbedVideo = forwardRef<</div><div- className={`absolute left-0 right-0 z-30 transition-all duration-300 ease-in-out ${- overlayVisible ? "bottom-[68px] xs:bottom-[60px]" : "bottom-0"- }`}+ className={`absolute left-0 right-0 z-30 transition-all duration-300 ease-in-out ${overlayVisible ? "bottom-[68px] xs:bottom-[60px]" : "bottom-0"+ }`}><divref={timelineRef}- className="h-8 xs:h-6 cursor-pointer px-4 py-2 xs:py-0 touch-manipulation"+ className="px-4 py-2 h-8 cursor-pointer xs:h-6 xs:py-0 touch-manipulation"onMouseDown={handleMouseDown}- onMouseMove={handleMouseMove}- onMouseUp={handleMouseUp}onTouchStart={(e) => {- e.preventDefault();const touch = e.touches[0];const rect = timelineRef.current?.getBoundingClientRect();if (rect && touch) {@@ -796,7 +795,6 @@ export const EmbedVideo = forwardRef<}}onTouchMove={(e) => {if (isDragging) {- e.preventDefault();const touch = e.touches[0];const rect = timelineRef.current?.getBoundingClientRect();if (rect && touch) {@@ -840,7 +838,7 @@ export const EmbedVideo = forwardRef<return (<divkey={comment.id}- className="absolute z-10 text-sm transition-all hover:scale-125 active:scale-110 -mt-5 md:-mt-5 touch-manipulation"+ className="absolute z-10 -mt-5 text-sm transition-all hover:scale-125 active:scale-110 md:-mt-5 touch-manipulation"style={{left: `${commentPosition}%`,}}@@ -899,7 +897,7 @@ export const EmbedVideo = forwardRef<}}><div- className="w-full h-full bg-gray-400 bg-opacity-50 group-hover:bg-opacity-70 transition-colors"+ className="w-full h-full bg-gray-400 bg-opacity-50 transition-colors group-hover:bg-opacity-70"style={{boxShadow: "0 0 20px rgba(0,0,0,0.6)",borderRight:@@ -948,9 +946,8 @@ export const EmbedVideo = forwardRef<</div><div- className={`absolute bottom-0 left-0 right-0 bg-black bg-opacity-60 z-20 transition-transform duration-300 ease-in-out ${- overlayVisible ? "translate-y-0" : "translate-y-full"- }`}+ className={`absolute bottom-0 left-0 right-0 bg-black bg-opacity-60 z-20 transition-transform duration-300 ease-in-out ${overlayVisible ? "translate-y-0" : "translate-y-full"+ }`}onMouseEnter={() => {setIsHoveringControls(true);}}@@ -958,7 +955,7 @@ export const EmbedVideo = forwardRef<setIsHoveringControls(false);}}>- <div className="flex justify-between items-center px-3 xs:px-4 py-3 xs:py-3">+ <div className="flex justify-between items-center px-3 py-3 xs:px-4 xs:py-3"><div className="flex items-center space-x-2 xs:space-x-3"><buttonaria-label="Play video"@@ -973,7 +970,7 @@ export const EmbedVideo = forwardRef<<Play className="w-auto h-6 xs:h-5 md:h-6" />)}</button>- <div className="text-xs xs:text-sm text-white font-medium select-none tabular">+ <div className="text-xs font-medium text-white select-none xs:text-sm tabular">{formatTime(currentTime)} / {formatTime(longestDuration)}</div></div>@@ -1139,9 +1136,8 @@ export const EmbedVideo = forwardRef<subscriptionStatus: user.stripeSubscriptionStatus,}) && (<div- className={`absolute top-4 z-30 transition-all duration-300 ${- showTitleOverlay ? "right-4" : "left-4"- }`}+ className={`absolute top-4 z-30 transition-all duration-300 ${showTitleOverlay ? "right-4" : "left-4"+ }`}><divclassName="block cursor-pointer"@@ -1156,9 +1152,8 @@ export const EmbedVideo = forwardRef<</div><div- className={`absolute top-8 transition-transform duration-300 ease-in-out origin-top scale-y-0 peer-hover:scale-y-100 ${- showTitleOverlay ? "right-0" : "left-0"- }`}+ className={`absolute top-8 transition-transform duration-300 ease-in-out origin-top scale-y-0 peer-hover:scale-y-100 ${showTitleOverlay ? "right-0" : "left-0"+ }`}><p className="text-white text-xs font-medium whitespace-nowrap bg-black bg-opacity-50 px-2 py-0.5 rounded">Remove watermarkdiff --git a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx b/apps/web/app/s/[videoId]/_components/ShareVideo.tsxindex f9e88e21f..d3d727e5e 100644--- a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx+++ b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx@@ -117,6 +117,40 @@ export const ShareVideo = forwardRef<videoMetadataLoaded);+ // Global timeline seeking (desktop)+ useEffect(() => {+ if (!seeking) return;+ const timeline = document.getElementById("seek");+ if (!timeline) return;++ const handleGlobalMouseMove = (e: MouseEvent) => {+ // Synthesize a React-like event for handleSeekMouseMove+ const rect = timeline.getBoundingClientRect();+ const syntheticEvent = {+ ...e,+ currentTarget: timeline,+ clientX: e.clientX,+ } as unknown as React.MouseEvent<HTMLDivElement>;+ handleSeekMouseMove(syntheticEvent);+ };+ const handleGlobalMouseUp = (e: MouseEvent) => {+ // Synthesize a React-like event for handleSeekMouseUp+ const rect = timeline.getBoundingClientRect();+ const syntheticEvent = {+ ...e,+ currentTarget: timeline,+ clientX: e.clientX,+ } as unknown as React.MouseEvent<HTMLDivElement>;+ handleSeekMouseUp(syntheticEvent);+ };+ document.addEventListener("mousemove", handleGlobalMouseMove);+ document.addEventListener("mouseup", handleGlobalMouseUp);+ return () => {+ document.removeEventListener("mousemove", handleGlobalMouseMove);+ document.removeEventListener("mouseup", handleGlobalMouseUp);+ };+ }, [seeking]);+// Update isMP4Source based on query resultuseEffect(() => {if (videoSourceData) {@@ -955,9 +989,8 @@ export const ShareVideo = forwardRef<className="overflow-hidden relative w-full h-full rounded-lg shadow-lg group"><div- className={`absolute inset-0 flex items-center justify-center z-10 bg-black transition-opacity duration-300 ${- isLoading ? "opacity-100" : "opacity-0 pointer-events-none"- }`}+ className={`absolute inset-0 flex items-center justify-center z-10 bg-black transition-opacity duration-300 ${isLoading ? "opacity-100" : "opacity-0 pointer-events-none"+ }`}><LogoSpinner className="w-8 h-auto animate-spin sm:w-10" /></div>@@ -971,11 +1004,10 @@ export const ShareVideo = forwardRef<</div>{!isLoading && (<div- className={`absolute inset-0 z-20 flex items-center justify-center transition-opacity duration-300 ${- (overlayVisible && isPlaying) || tempOverlayVisible || !isPlaying- ? "opacity-100"- : "opacity-0"- }`}+ className={`absolute inset-0 z-20 flex items-center justify-center transition-opacity duration-300 ${(overlayVisible && isPlaying) || tempOverlayVisible || !isPlaying+ ? "opacity-100"+ : "opacity-0"+ }`}><buttonaria-label={isPlaying ? "Pause video" : "Play video"}@@ -1024,9 +1056,8 @@ export const ShareVideo = forwardRef<)}{currentSubtitle && currentSubtitle.text && subtitlesVisible && (<div- className={`absolute z-10 p-2 w-full text-center transition-all duration-300 ease-in-out ${- overlayVisible ? "bottom-16 sm:bottom-20" : "bottom-6 sm:bottom-8"- }`}+ className={`absolute z-10 p-2 w-full text-center transition-all duration-300 ease-in-out ${overlayVisible ? "bottom-16 sm:bottom-20" : "bottom-6 sm:bottom-8"+ }`}><div className="inline px-2 py-1 text-sm text-white bg-black bg-opacity-75 rounded-xl sm:text-lg md:text-2xl">{currentSubtitle.text@@ -1109,21 +1140,13 @@ export const ShareVideo = forwardRef<)}<div- className={`absolute left-0 right-0 z-30 transition-all duration-300 ease-in-out ${- overlayVisible ? "bottom-[40px] md:bottom-[60px]" : "bottom-1"- }`}+ className={`absolute left-0 right-0 z-30 transition-all duration-300 ease-in-out ${overlayVisible ? "bottom-[40px] md:bottom-[60px]" : "bottom-1"+ }`}><divid="seek"className="h-6 cursor-pointer"onMouseDown={handleSeekMouseDown}- onMouseMove={(e) => {- handleSeekMouseMove(e);- }}- onMouseUp={handleSeekMouseUp}- onMouseLeave={() => {- setSeeking(false);- }}onTouchStart={handleSeekMouseDown}onTouchMove={(e) => {handleSeekMouseMove(e);@@ -1144,79 +1167,50 @@ export const ShareVideo = forwardRef<onMouseMove={handleTimelineHover}onMouseLeave={handleTimelineLeave}>+ {/* Render chapter backgrounds */}{chapters.length > 0 && longestDuration > 0 ? (<div className="absolute top-2.5 w-full h-1 sm:h-1.5 z-10 flex">{chapters.map((chapter, index) => {const nextChapter = chapters[index + 1];const chapterStart = chapter.start;- const chapterEnd = nextChapter- ? nextChapter.start- : longestDuration;+ const chapterEnd = nextChapter ? nextChapter.start : longestDuration;const chapterDuration = chapterEnd - chapterStart;- const chapterWidth =- (chapterDuration / longestDuration) * 100;-- const chapterProgress = Math.max(- 0,- Math.min((currentTime - chapterStart) / chapterDuration, 1)- );-- const isCurrentChapter =- currentTime >= chapterStart && currentTime < chapterEnd;-+ const chapterWidth = (chapterDuration / longestDuration) * 100;return (<divkey={chapter.start}className="relative h-full cursor-pointer group"- style={{ width: `${chapterWidth}%` }}+ style={{+ width: `${chapterWidth}%`,+ background: "rgba(156, 163, 175, 0.5)", // bg-gray-400 bg-opacity-50+ borderRight:+ index < chapters.length - 1+ ? "1px solid rgba(255,255,255,0.3)"+ : "none",+ }}onClick={(e) => {e.stopPropagation();applyTimeToVideos(chapter.start);}}- >- <div- className="w-full h-full bg-gray-400 bg-opacity-50 transition-colors group-hover:bg-opacity-70"- style={{- boxShadow: "0 0 20px rgba(0,0,0,0.6)",- borderRight:- index < chapters.length - 1- ? "1px solid rgba(255,255,255,0.3)"- : "none",- }}- />- {isCurrentChapter && (- <div- className="absolute top-0 left-0 h-full bg-white transition-all duration-100"- style={{ width: `${chapterProgress * 100}%` }}- />- )}- {currentTime > chapterEnd && (- <div className="absolute top-0 left-0 w-full h-full bg-white" />- )}- </div>+ />);})}</div>) : (- <>- <div- style={{ boxShadow: "0 0 20px rgba(0,0,0,0.6)" }}- className="absolute top-2.5 w-full h-1 sm:h-1.5 bg-gray-400 bg-opacity-50 z-10"- />- <div- className="absolute top-2.5 h-1 sm:h-1.5 bg-white cursor-pointer z-10"- style={{ width: `${watchedPercentage}%` }}- />- </>+ <div className="absolute top-2.5 w-full h-1 sm:h-1.5 bg-gray-400 bg-opacity-50 z-10" />)}-+ {/* Render the main progress bar (white) */}+ <div+ className="absolute top-2.5 h-1 sm:h-1.5 bg-white z-20"+ style={{ width: `${watchedPercentage}%` }}+ /><divstyle={{boxShadow: "0 0 20px rgba(0,0,0,0.1)",left: `${watchedPercentage}%`,}}className={clsx(- "drag-button absolute top-2 z-20 -mt-1.5 -ml-2 w-5 h-5 bg-white rounded-full cursor-pointer focus:outline-none border-2 border-gray-5",+ "drag-button absolute top-2 z-20 -mt-1.5 w-5 h-5 bg-white rounded-full cursor-pointer focus:outline-none border-2 border-gray-5",seeking? "scale-125 transition-transform ring-blue-300 ring-offset-2 ring-2": ""@@ -1228,9 +1222,8 @@ export const ShareVideo = forwardRef<</div><div- className={`absolute bottom-0 left-0 right-0 bg-black bg-opacity-60 z-20 transition-transform duration-300 ease-in-out ${- overlayVisible ? "translate-y-0" : "translate-y-full"- }`}+ className={`absolute bottom-0 left-0 right-0 bg-black bg-opacity-60 z-20 transition-transform duration-300 ease-in-out ${overlayVisible ? "translate-y-0" : "translate-y-full"+ }`}onMouseEnter={() => {setIsHoveringControls(true);}}@@ -1283,7 +1276,7 @@ export const ShareVideo = forwardRef<<span className="inline-flex"><buttonaria-label={`Change video speed to ${videoSpeed}x`}- className="inline-flex min-w-[35px] sm:min-w-[45px] items-center text-xs sm:text-sm font-medium transition ease-in-out duration-150 focus:outline-none border text-gray-100 border-transparent hover:text-white focus:border-white hover:bg-gray-100 hover:bg-opacity-10 active:bg-gray-100 active:bg-gray-100 active:bg-opacity-10 px-1 sm:px-2 py-1 sm:py-2 justify-center rounded-lg"+ className="inline-flex min-w-[35px] sm:min-w-[45px] items-center text-xs sm:text-sm font-medium transition ease-in-out duration-150 focus:outline-none border text-gray-100 border-transparent hover:text-white focus:border-white hover:bg-gray-100 hover:bg-opacity-10 active:bg-gray-100 active:bg-opacity-10 px-1 sm:px-2 py-1 sm:py-2 justify-center rounded-lg"tabIndex={0}type="button"onClick={handleSpeedChange}@@ -1597,7 +1590,7 @@ function CommentIndicators(props: {return (<divkey={comment.id}- className="absolute z-10 text-sm transition-all hover:scale-125 -mt-5 md:-mt-5"+ className="absolute z-10 -mt-5 text-sm transition-all hover:scale-125 md:-mt-5"style={{left: `${commentPosition}%`,}}diff --git a/apps/web/components/pages/HomePage/RecordingModes.tsx b/apps/web/components/pages/HomePage/RecordingModes.tsxindex 67bb7f375..628422907 100644--- a/apps/web/components/pages/HomePage/RecordingModes.tsx+++ b/apps/web/components/pages/HomePage/RecordingModes.tsx@@ -5,7 +5,6 @@ import {} from "@/utils/platform";import { Button } from "@cap/ui";import clsx from "clsx";-import { motion } from "framer-motion";import { useDetectPlatform } from "hooks/useDetectPlatform";import { Clapperboard, Zap } from "lucide-react";import { useState } from "react";@@ -98,7 +97,7 @@ const RecordingModes = () => {}}><iframe- src="https://cap.so/embed/8cq21vmz12tm1zf"+ src="http://localhost:3000/embed/nyb0x5znd822kqb"frameBorder="0"allowFullScreenstyle={{