Skip to content

🎥 Make videos programmatically with React

UI niceness

Jonny Burgere69ade4aa6d4
diff --git a/packages/convert/app/components/BackButton.tsx b/packages/convert/app/components/BackButton.tsx
new file mode 100644
index 0000000000..6f4c3ea508
--- /dev/null
+++ b/packages/convert/app/components/BackButton.tsx
@@ -0,0 +1,32 @@
+import React, {useCallback} from 'react';
+import {Source} from '~/lib/convert-state';
+import {Button} from './ui/button';
+
+export const BackButton: React.FC<{
+ readonly setSrc: React.Dispatch<React.SetStateAction<Source | null>>;
+}> = ({setSrc}) => {
+ const clear = useCallback(() => {
+ setSrc(null);
+ }, [setSrc]);
+
+ return (
+ <div className="block lg:h-10">
+ <div className="lg:fixed">
+ <Button variant="link" onClick={clear}>
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 448 512"
+ style={{height: 16}}
+ >
+ <path
+ fill="currentcolor"
+ d="M18.2 273l-17-17 17-17L171.8 85.4l17-17 33.9 33.9-17 17L93.1 232 424 232l24 0 0 48-24 0L93.1 280 205.8 392.6l17 17-33.9 33.9-17-17L18.2 273z"
+ />
+ </svg>
+ <div className="w-2" />
+ Choose another file
+ </Button>
+ </div>
+ </div>
+ );
+};
diff --git a/packages/convert/app/components/FileAvailable.tsx b/packages/convert/app/components/FileAvailable.tsx
index 2196a25d2f..1d8b3cff6e 100644
--- a/packages/convert/app/components/FileAvailable.tsx
+++ b/packages/convert/app/components/FileAvailable.tsx
@@ -6,12 +6,12 @@ import {defaultRotateOrMirorState, RotateOrMirrorState} from '~/lib/default-ui';
import {formatBytes} from '~/lib/format-bytes';
import {useThumbnail} from '~/lib/use-thumbnail';
import {RouteAction} from '~/seo';
+import {BackButton} from './BackButton';
import ConvertUI from './ConvertUi';
import {Footer} from './Footer';
import {Probe} from './Probe';
import {VideoThumbnailRef} from './VideoThumbnail';
import {getBrightnessOfFrame} from './get-brightness-of-frame';
-import {Button} from './ui/button';
import {useProbe} from './use-probe';
const idealBrightness = 0.8;
@@ -25,10 +25,6 @@ export const FileAvailable: React.FC<{
() => routeAction.type === 'generic-probe',
);
- const clear = useCallback(() => {
- setSrc(null);
- }, [setSrc]);
-
const bestBrightness = useRef<number | null>(null);
const videoThumbnailRef = useRef<VideoThumbnailRef>(null);
@@ -99,22 +95,7 @@ export const FileAvailable: React.FC<{
<div>
<div className="overflow-y-auto w-full lg:flex lg:justify-center pt-6 pb-10 px-4 bg-slate-50 min-h-[100vh]">
<div>
- <div className="block">
- <Button variant="link" onClick={clear}>
- <svg
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 448 512"
- style={{height: 16}}
- >
- <path
- fill="currentcolor"
- d="M18.2 273l-17-17 17-17L171.8 85.4l17-17 33.9 33.9-17 17L93.1 232 424 232l24 0 0 48-24 0L93.1 280 205.8 392.6l17 17-33.9 33.9-17-17L18.2 273z"
- />
- </svg>
- <div className="w-2" />
- Choose another file
- </Button>
- </div>
+ <BackButton setSrc={setSrc} />
<div className="lg:inline-flex lg:flex-row items-start">
<Probe
thumbnailError={err}
diff --git a/packages/convert/app/components/Probe.tsx b/packages/convert/app/components/Probe.tsx
index 10f99d6406..0ce74cf164 100644
--- a/packages/convert/app/components/Probe.tsx
+++ b/packages/convert/app/components/Probe.tsx
@@ -83,93 +83,99 @@ export const Probe: React.FC<{
}, [probeDetails, sortedTracks, trackDetails]);
return (
- <Card className="w-full lg:w-[350px] overflow-hidden">
- <div className="flex flex-row lg:flex-col w-full border-b-2 border-black">
- {error ? null : thumbnailError ? null : (
- <VideoThumbnail
- ref={videoThumbnailRef}
- smallThumbOnMobile
- rotation={userRotation - (rotation ?? 0)}
- mirrorHorizontal={mirrorHorizontal}
- mirrorVertical={mirrorVertical}
- initialReveal={false}
- />
- )}
- <CardHeader className="p-3 lg:p-4 w-full">
- <CardTitle title={name ?? undefined}>
- {name ? name : <Skeleton className="h-5 w-[220px] inline-block" />}
- </CardTitle>
- {error ? (
- <CardDescription className="!mt-0">
- <p className="text-red-500">
- Failed to parse media:
- <br />
- {error.message}
- </p>
+ <div className="w-full lg:w-[350px]">
+ <Card className="overflow-hidden static lg:fixed lg:w-[350px]">
+ <div className="flex flex-row lg:flex-col w-full border-b-2 border-black">
+ {error ? null : thumbnailError ? null : (
+ <VideoThumbnail
+ ref={videoThumbnailRef}
+ smallThumbOnMobile
+ rotation={userRotation - (rotation ?? 0)}
+ mirrorHorizontal={mirrorHorizontal}
+ mirrorVertical={mirrorVertical}
+ initialReveal={false}
+ />
+ )}
+ <CardHeader className="p-3 lg:p-4 w-full">
+ <CardTitle title={name ?? undefined}>
+ {name ? (
+ name
+ ) : (
+ <Skeleton className="h-5 w-[220px] inline-block" />
+ )}
+ </CardTitle>
+ {error ? (
+ <CardDescription className="!mt-0">
+ <p className="text-red-500">
+ Failed to parse media:
+ <br />
+ {error.message}
+ </p>
+ </CardDescription>
+ ) : null}
+ <CardDescription
+ className={clsx('!mt-0 truncate', styles['fade-in'])}
+ >
+ {done ? (
+ <SourceLabel src={src} />
+ ) : (
+ <span id="not-done">0% read</span>
+ )}
</CardDescription>
- ) : null}
- <CardDescription
- className={clsx('!mt-0 truncate', styles['fade-in'])}
- >
- {done ? (
- <SourceLabel src={src} />
- ) : (
- <span id="not-done">0% read</span>
- )}
- </CardDescription>
- </CardHeader>
- </div>
- {sortedTracks.length && probeDetails ? (
- <div className="pr-6 border-b-2 border-black overflow-y-auto">
- <TrackSwitcher
- selectedTrack={trackDetails}
- sortedTracks={sortedTracks}
- onTrack={(track) => {
- setTrackDetails(track);
- }}
- />
+ </CardHeader>
</div>
- ) : null}
- {isNarrow ? null : (
- <>
- <ScrollArea height={300} className="flex-1">
- {selectedTrack === null ? (
- <ContainerOverview
- container={container ?? null}
- dimensions={dimensions ?? null}
- videoCodec={videoCodec ?? null}
- size={size ?? null}
- durationInSeconds={durationInSeconds}
- audioCodec={audioCodec}
- fps={fps}
- metadata={metadata}
- isHdr={isHdr}
- location={location}
- />
- ) : selectedTrack.type === 'video' ? (
- <VideoTrackOverview
- location={location}
- metadata={metadata}
- track={selectedTrack}
- keyframes={keyframes}
- durationInSeconds={durationInSeconds ?? null}
- />
- ) : selectedTrack.type === 'audio' ? (
- <AudioTrackOverview
- location={location}
- metadata={metadata}
- track={selectedTrack}
- />
- ) : null}
- </ScrollArea>
- <Separator orientation="horizontal" />
- </>
- )}
- <div className="flex flex-row items-center justify-center">
- <Button disabled={!tracks} variant="link" onClick={onClick}>
- {probeDetails ? 'Hide details' : 'Show details'}
- </Button>
- </div>
- </Card>
+ {sortedTracks.length && probeDetails ? (
+ <div className="pr-6 border-b-2 border-black overflow-y-auto">
+ <TrackSwitcher
+ selectedTrack={trackDetails}
+ sortedTracks={sortedTracks}
+ onTrack={(track) => {
+ setTrackDetails(track);
+ }}
+ />
+ </div>
+ ) : null}
+ {isNarrow ? null : (
+ <>
+ <ScrollArea height={300} className="flex-1">
+ {selectedTrack === null ? (
+ <ContainerOverview
+ container={container ?? null}
+ dimensions={dimensions ?? null}
+ videoCodec={videoCodec ?? null}
+ size={size ?? null}
+ durationInSeconds={durationInSeconds}
+ audioCodec={audioCodec}
+ fps={fps}
+ metadata={metadata}
+ isHdr={isHdr}
+ location={location}
+ />
+ ) : selectedTrack.type === 'video' ? (
+ <VideoTrackOverview
+ location={location}
+ metadata={metadata}
+ track={selectedTrack}
+ keyframes={keyframes}
+ durationInSeconds={durationInSeconds ?? null}
+ />
+ ) : selectedTrack.type === 'audio' ? (
+ <AudioTrackOverview
+ location={location}
+ metadata={metadata}
+ track={selectedTrack}
+ />
+ ) : null}
+ </ScrollArea>
+ <Separator orientation="horizontal" />
+ </>
+ )}
+ <div className="flex flex-row items-center justify-center">
+ <Button disabled={!tracks} variant="link" onClick={onClick}>
+ {probeDetails ? 'Hide details' : 'Show details'}
+ </Button>
+ </div>
+ </Card>
+ </div>
);
};
diff --git a/packages/convert/app/tailwind.css b/packages/convert/app/tailwind.css
index dc9eb3002e..98c3f114bd 100644
--- a/packages/convert/app/tailwind.css
+++ b/packages/convert/app/tailwind.css
@@ -2,6 +2,10 @@
@tailwind components;
@tailwind utilities;
+html {
+ background-color: #f8fafc;
+}
+
@layer base {
@font-face {
font-family: 'GTPlanar';