Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 60 additions & 83 deletions src/components/FileUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useRef, useState, useEffect} from "react";
import { useRef, useState, useEffect } from "react";
import { Film, FolderOpen } from "lucide-react";
import LottiePlayer from "./LottiePlayer";
import uploadAnim from "@/lib/lottie/upload.json";
Expand All @@ -25,7 +25,7 @@ export default function FileUpload({
const [dragging, setDragging] = useState(false);
const [error, setError] = useState("");
const [warning, setWarning] = useState("");

useEffect(() => {
const handler = (e: KeyboardEvent) => {
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "o") {
Expand All @@ -41,18 +41,11 @@ export default function FileUpload({
setError("");
setWarning("");

// Validate type
if (!file.type.startsWith("video/")) {
setError("Only video files are allowed.");
return;
}

if (file.size > 500 * 1024 * 1024) {
setError("File size exceeds 500MB limit. Please select a smaller video.");
return;
}

// Hard limit
if (file.size > MAX_FILE_SIZE) {
setError(
`File too large (${formatBytes(
Expand All @@ -62,7 +55,6 @@ export default function FileUpload({
return;
}

// Soft warning
if (file.size > WARNING_FILE_SIZE) {
const estimatedMinutes = Math.max(1, Math.round(file.size / (100 * 1024 * 1024)));
setWarning(
Expand All @@ -83,58 +75,62 @@ export default function FileUpload({
if (file) handleFile(file);
};

const FileInfo = () => (
<div className="px-4 py-3 bg-film-50 border border-film-200 rounded-lg">
<div className="flex flex-col lg:flex-row lg:items-center gap-3">

<div className="flex items-start gap-3 flex-1 min-w-0">

<div className="hidden lg:flex items-center justify-center w-9 h-9 rounded-lg bg-[var(--surface)] border border-[var(--border)] shrink-0">
<Film size={16} className="text-film-600" />
</div>

<Film size={18} className="lg:hidden text-film-600 shrink-0 mt-0.5" />

<div className="flex-1 min-w-0">
<div className="flex flex-wrap items-center gap-2 mb-0.5">
<p className="text-sm font-semibold text-film-700 truncate max-w-[320px] xl:max-w-[420px]">
{currentFile?.name}
</p>
{currentFile && (
<span className="px-2 py-0.5 bg-gray-700 text-white font-bold tracking-wider rounded text-[10px] uppercase shrink-0">
{currentFile.name.includes(".")
? currentFile.name.split(".").pop()
: "VIDEO"}
</span>
)}
const FileInfo = () => (
<div className="rounded-lg border border-film-200 bg-film-50 px-4 py-3">
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div className="flex min-w-0 items-start gap-3">
<div className="hidden h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--surface)] sm:flex">
<Film size={16} className="text-film-600" />
</div>
<div className="text-xs text-gray-500 dark:text-gray-400 mt-1 space-y-0.5">
<p>{formatBytes(currentFile?.size ?? 0)}</p>

<p>
<Film size={18} className="mt-0.5 shrink-0 text-film-600 sm:hidden" />

<div className="min-w-0">
<div className="mb-1 flex min-w-0 flex-wrap items-center gap-2">
{currentFile && (
<span className="shrink-0 rounded bg-gray-700 px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider text-white">
{currentFile.name.includes(".") ? currentFile.name.split(".").pop() : "VIDEO"}
</span>
)}
<p className="min-w-0 break-all text-sm font-semibold text-film-700">
{currentFile?.name}
</p>
</div>

<p className="text-xs text-gray-500 dark:text-gray-400">
{formatBytes(currentFile?.size ?? 0)}
{duration > 0
? `Duration: ${formatDuration(duration)}`
: "Loading duration..."}
? ` - ${formatDuration(duration)}`
: " - Loading duration..."}
</p>
</div>
</div>
</div>

<button
type="button"
onClick={() => inputRef.current?.click()}
className="text-xs font-semibold text-film-600 hover:text-film-700 uppercase tracking-wide"
>
Change
<span className="text-[var(--muted)] ml-1">(Ctrl+O)</span>
</button>
<button
type="button"
onClick={() => inputRef.current?.click()}
className="self-start whitespace-nowrap text-xs font-semibold uppercase tracking-wide text-film-600 hover:text-film-700 sm:self-center"
>
Change
<span className="ml-1 text-[var(--muted)]">(Ctrl+O)</span>
</button>
</div>

<div className="mt-3 flex flex-col gap-2 border-t border-film-200 pt-3 sm:flex-row sm:items-center sm:justify-between">
<div className="inline-flex w-fit items-center gap-2 rounded-lg border border-[var(--border)] bg-[var(--surface)] px-3 py-2 text-sm font-heading font-medium text-[var(--muted)]">
<FolderOpen size={14} />
MP4 / MOV / AVI / WebM
</div>
<p className="text-xs text-gray-500">
Supports MP4, MOV, AVI, MKV, WebM, and most video formats
</p>
</div>

{fileError && (
<p className="text-xs text-red-500 mt-2 font-medium">
<p className="mt-2 text-xs font-medium text-red-500">
{fileError}
</p>
)}

<input
ref={inputRef}
type="file"
Expand All @@ -146,31 +142,13 @@ export default function FileUpload({
}}
/>
</div>
);

<p className="text-xs text-gray-500 mt-3 break-words">
Supports: MP4, MOV, AVI, MKV, WebM, and most video formats
</p>

{fileError && (
<p className="text-xs text-red-500 mt-2 font-medium">{fileError}</p>
)}

<input
ref={inputRef}
type="file"
accept="video/*"
className="hidden"
onChange={(e) => {
const f = e.target.files?.[0];
if (f) handleFile(f);
}}
/>
</div>
);
const DropZone = () => (
<div
id="upload-zone"
role="button"
aria-label="Upload video file"
tabIndex={0}
onDragOver={(e) => {
e.preventDefault();
Expand All @@ -192,7 +170,6 @@ export default function FileUpload({
: "border-[var(--border)] bg-[var(--bg)] hover:border-film-400 hover:bg-film-50/40"
)}
>
{/* Premium Light Beam Shimmer Effect */}
{dragging && (
<div className="absolute inset-0 -translate-x-full animate-shimmer bg-gradient-to-r from-transparent via-film-500/20 to-transparent pointer-events-none" />
)}
Expand Down Expand Up @@ -235,18 +212,18 @@ export default function FileUpload({
</p>
)}

<input
ref={inputRef}
type="file"
accept="video/*"
className="hidden"
onChange={(e) => {
const f = e.target.files?.[0];

if (f) handleFile(f);
}}
/>
</div>
<input
ref={inputRef}
type="file"
accept="video/*"
className="hidden"
onChange={(e) => {
const f = e.target.files?.[0];

if (f) handleFile(f);
}}
/>
</div>
);

return (
Expand Down
Loading