summaryrefslogtreecommitdiff
path: root/apps/web/src/components
diff options
context:
space:
mode:
authorgantiro <gantiro396@gmail.com>2025-07-16 20:53:00 +0700
committergantiro <gantiro396@gmail.com>2025-07-16 20:53:00 +0700
commit955f6331f258143daa62cb6e004c6df089c55c64 (patch)
treef1e4ed03cbfb35408ae5282dfe35371e535e5eb8 /apps/web/src/components
parent2974fd89a942f4e3173642b165f228e2af604ae7 (diff)
parent3371a6889634f326063351295faca9a56c566706 (diff)
downloadopencut-955f6331f258143daa62cb6e004c6df089c55c64.tar.gz
Merge branch 'main' into feature/optimize-timeline-ruler
Diffstat (limited to 'apps/web/src/components')
-rw-r--r--apps/web/src/components/editor-header.tsx2
-rw-r--r--apps/web/src/components/editor-provider.tsx6
-rw-r--r--apps/web/src/components/editor/timeline.tsx72
-rw-r--r--apps/web/src/components/keyboard-shortcuts-help.tsx113
-rw-r--r--apps/web/src/components/landing/hero.tsx47
-rw-r--r--apps/web/src/components/ui/draggable-item.tsx37
6 files changed, 200 insertions, 77 deletions
diff --git a/apps/web/src/components/editor-header.tsx b/apps/web/src/components/editor-header.tsx
index c4081c75..3b51e182 100644
--- a/apps/web/src/components/editor-header.tsx
+++ b/apps/web/src/components/editor-header.tsx
@@ -7,6 +7,7 @@ import { useTimelineStore } from "@/stores/timeline-store";
import { HeaderBase } from "./header-base";
import { formatTimeCode } from "@/lib/time";
import { useProjectStore } from "@/stores/project-store";
+import { KeyboardShortcutsHelp } from "./keyboard-shortcuts-help";
export function EditorHeader() {
const { getTotalDuration } = useTimelineStore();
@@ -43,6 +44,7 @@ export function EditorHeader() {
const rightContent = (
<nav className="flex items-center gap-2">
+ <KeyboardShortcutsHelp />
<Button
size="sm"
variant="primary"
diff --git a/apps/web/src/components/editor-provider.tsx b/apps/web/src/components/editor-provider.tsx
index 38255956..d970f86d 100644
--- a/apps/web/src/components/editor-provider.tsx
+++ b/apps/web/src/components/editor-provider.tsx
@@ -3,6 +3,7 @@
import { useEffect } from "react";
import { Loader2 } from "lucide-react";
import { useEditorStore } from "@/stores/editor-store";
+import { useKeyboardShortcuts } from "@/hooks/use-keyboard-shortcuts";
interface EditorProviderProps {
children: React.ReactNode;
@@ -11,6 +12,11 @@ interface EditorProviderProps {
export function EditorProvider({ children }: EditorProviderProps) {
const { isInitializing, isPanelsReady, initializeApp } = useEditorStore();
+ useKeyboardShortcuts({
+ enabled: !isInitializing && isPanelsReady,
+ context: "editor",
+ });
+
useEffect(() => {
initializeApp();
}, [initializeApp]);
diff --git a/apps/web/src/components/editor/timeline.tsx b/apps/web/src/components/editor/timeline.tsx
index c6e6a331..bfb663c6 100644
--- a/apps/web/src/components/editor/timeline.tsx
+++ b/apps/web/src/components/editor/timeline.tsx
@@ -55,6 +55,7 @@ import {
getCumulativeHeightBefore,
getTotalTracksHeight,
TIMELINE_CONSTANTS,
+ snapTimeToFrame,
} from "@/constants/timeline-constants";
import { Slider } from "../ui/slider";
import TimelineCanvasRuler from "./timeline-canvas/timeline-canvas-ruler";
@@ -64,6 +65,7 @@ export function Timeline() {
// Timeline shows all tracks (video, audio, effects) and their elements.
// You can drag media here to add it to your project.
// elements can be trimmed, deleted, and moved.
+
const {
tracks,
addTrack,
@@ -232,7 +234,6 @@ export function Timeline() {
// Use frame snapping for timeline clicking
const projectFps = activeProject?.fps || 30;
- const { snapTimeToFrame } = require("@/constants/timeline-constants");
const time = snapTimeToFrame(rawTime, projectFps);
seek(time);
@@ -254,71 +255,6 @@ export function Timeline() {
setDuration(Math.max(totalDuration, 10)); // Minimum 10 seconds for empty timeline
}, [tracks, setDuration, getTotalDuration]);
- // Keyboard event for deleting selected elements
- useEffect(() => {
- const handleKeyDown = (e: KeyboardEvent) => {
- // Don't trigger when typing in input fields or textareas
- if (
- e.target instanceof HTMLInputElement ||
- e.target instanceof HTMLTextAreaElement
- ) {
- return;
- }
-
- // Only trigger when timeline is focused or mouse is over timeline
- if (
- !isInTimeline &&
- !timelineRef.current?.contains(document.activeElement)
- ) {
- return;
- }
-
- if (
- (e.key === "Delete" || e.key === "Backspace") &&
- selectedElements.length > 0
- ) {
- selectedElements.forEach(({ trackId, elementId }) => {
- removeElementFromTrack(trackId, elementId);
- });
- clearSelectedElements();
- }
- };
- window.addEventListener("keydown", handleKeyDown);
- return () => window.removeEventListener("keydown", handleKeyDown);
- }, [
- selectedElements,
- removeElementFromTrack,
- clearSelectedElements,
- isInTimeline,
- ]);
-
- // Keyboard event for undo (Cmd+Z)
- useEffect(() => {
- const handleKeyDown = (e: KeyboardEvent) => {
- if ((e.metaKey || e.ctrlKey) && e.key === "z" && !e.shiftKey) {
- e.preventDefault();
- undo();
- }
- };
- window.addEventListener("keydown", handleKeyDown);
- return () => window.removeEventListener("keydown", handleKeyDown);
- }, [undo]);
-
- // Keyboard event for redo (Cmd+Shift+Z or Cmd+Y)
- useEffect(() => {
- const handleKeyDown = (e: KeyboardEvent) => {
- if ((e.metaKey || e.ctrlKey) && e.key === "z" && e.shiftKey) {
- e.preventDefault();
- redo();
- } else if ((e.metaKey || e.ctrlKey) && e.key === "y") {
- e.preventDefault();
- redo();
- }
- };
- window.addEventListener("keydown", handleKeyDown);
- return () => window.removeEventListener("keydown", handleKeyDown);
- }, [redo]);
-
// Old marquee system removed - using new SelectionBox component instead
const handleDragEnter = (e: React.DragEvent) => {
@@ -376,7 +312,9 @@ export function Timeline() {
useTimelineStore.getState().addTextToNewTrack(dragData);
} else {
// Handle media items
- const mediaItem = mediaItems.find((item) => item.id === dragData.id);
+ const mediaItem = mediaItems.find(
+ (item: any) => item.id === dragData.id
+ );
if (!mediaItem) {
toast.error("Media item not found");
return;
diff --git a/apps/web/src/components/keyboard-shortcuts-help.tsx b/apps/web/src/components/keyboard-shortcuts-help.tsx
new file mode 100644
index 00000000..9f0d1e57
--- /dev/null
+++ b/apps/web/src/components/keyboard-shortcuts-help.tsx
@@ -0,0 +1,113 @@
+"use client";
+
+import { useState } from "react";
+import { Button } from "./ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "./ui/dialog";
+import { Badge } from "./ui/badge";
+import { Keyboard } from "lucide-react";
+import { useKeyboardShortcuts } from "@/hooks/use-keyboard-shortcuts";
+
+const KeyBadge = ({ keyName }: { keyName: string }) => {
+ // Replace common key names with symbols
+ const displayKey = keyName
+ .replace("Cmd", "⌘")
+ .replace("Shift", "⇧")
+ .replace("←", "◀")
+ .replace("→", "▶")
+ .replace("Space", "⎵");
+
+ return (
+ <Badge variant="secondary" className="font-mono text-xs px-2 py-1">
+ {displayKey}
+ </Badge>
+ );
+};
+
+const ShortcutItem = ({ shortcut }: { shortcut: any }) => (
+ <div className="flex items-center justify-between py-2 px-3 rounded-lg hover:bg-muted/50">
+ <div className="flex items-center gap-3">
+ {shortcut.icon && (
+ <div className="text-muted-foreground">{shortcut.icon}</div>
+ )}
+ <span className="text-sm">{shortcut.description}</span>
+ </div>
+ <div className="flex items-center gap-1">
+ {shortcut.keys.map((key: string, index: number) => (
+ <div key={index} className="flex items-center gap-1">
+ <KeyBadge keyName={key} />
+ {index < shortcut.keys.length - 1 && (
+ <span className="text-xs text-muted-foreground">+</span>
+ )}
+ </div>
+ ))}
+ </div>
+ </div>
+);
+
+export const KeyboardShortcutsHelp = () => {
+ const [open, setOpen] = useState(false);
+
+ // Get shortcuts from centralized hook (disabled so it doesn't add event listeners)
+ const { shortcuts } = useKeyboardShortcuts({ enabled: false });
+
+ const categories = Array.from(new Set(shortcuts.map((s) => s.category)));
+
+ return (
+ <Dialog open={open} onOpenChange={setOpen}>
+ <DialogTrigger asChild>
+ <Button variant="text" size="sm" className="gap-2">
+ <Keyboard className="w-4 h-4" />
+ Shortcuts
+ </Button>
+ </DialogTrigger>
+ <DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto">
+ <DialogHeader>
+ <DialogTitle className="flex items-center gap-2">
+ <Keyboard className="w-5 h-5" />
+ Keyboard Shortcuts
+ </DialogTitle>
+ <DialogDescription>
+ Speed up your video editing workflow with these keyboard shortcuts.
+ Most shortcuts work when the timeline is focused.
+ </DialogDescription>
+ </DialogHeader>
+
+ <div className="space-y-6">
+ {categories.map((category) => (
+ <div key={category}>
+ <h3 className="font-semibold text-sm text-muted-foreground uppercase tracking-wide mb-3">
+ {category}
+ </h3>
+ <div className="space-y-1">
+ {shortcuts
+ .filter((shortcut) => shortcut.category === category)
+ .map((shortcut, index) => (
+ <ShortcutItem key={index} shortcut={shortcut} />
+ ))}
+ </div>
+ </div>
+ ))}
+ </div>
+
+ <div className="mt-6 p-4 bg-muted/30 rounded-lg">
+ <h4 className="font-medium text-sm mb-2">Tips:</h4>
+ <ul className="text-sm text-muted-foreground space-y-1">
+ <li>
+ • Shortcuts work when the editor is focused (not typing in inputs)
+ </li>
+ <li>• J/K/L are industry-standard video editing shortcuts</li>
+ <li>• Use arrow keys for frame-perfect positioning</li>
+ <li>• Hold Shift with arrow keys for larger jumps</li>
+ </ul>
+ </div>
+ </DialogContent>
+ </Dialog>
+ );
+};
diff --git a/apps/web/src/components/landing/hero.tsx b/apps/web/src/components/landing/hero.tsx
index b1910dc5..6e6a45cb 100644
--- a/apps/web/src/components/landing/hero.tsx
+++ b/apps/web/src/components/landing/hero.tsx
@@ -84,7 +84,9 @@ export function Hero() {
});
} else {
toast.error("Oops!", {
- description: (data as { error: string }).error || "Something went wrong. Please try again.",
+ description:
+ (data as { error: string }).error ||
+ "Something went wrong. Please try again.",
});
}
} catch (error) {
@@ -98,7 +100,13 @@ export function Hero() {
return (
<div className="min-h-[calc(100vh-4.5rem)] supports-[height:100dvh]:min-h-[calc(100dvh-4.5rem)] flex flex-col justify-between items-center text-center px-4">
- <Image className="absolute top-0 left-0 -z-50 size-full object-cover" src="/landing-page-bg.png" height={1903.5} width={1269} alt="landing-page.bg" />
+ <Image
+ className="absolute top-0 left-0 -z-50 size-full object-cover"
+ src="/landing-page-bg.png"
+ height={1903.5}
+ width={1269}
+ alt="landing-page.bg"
+ />
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
@@ -121,11 +129,20 @@ export function Hero() {
animate={{ opacity: 1 }}
transition={{ delay: 0.4, duration: 0.8 }}
>
- A simple but powerful video editor that gets the job done. Works on any platform.
+ A simple but powerful video editor that gets the job done. Works on
+ any platform.
</motion.p>
- <motion.div className="mt-12 flex gap-8 justify-center" initial={{ opacity: 0 }} animate={{ opacity: 1 }} transition={{ delay: 0.6, duration: 0.8 }}>
- <form onSubmit={handleSubmit} className="flex gap-3 w-full max-w-lg flex-col sm:flex-row">
+ <motion.div
+ className="mt-12 flex gap-8 justify-center"
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ transition={{ delay: 0.6, duration: 0.8 }}
+ >
+ <form
+ onSubmit={handleSubmit}
+ className="flex gap-3 w-full max-w-lg flex-col sm:flex-row"
+ >
<div className="relative w-full">
<Input
type="email"
@@ -137,12 +154,28 @@ export function Hero() {
required
/>
</div>
- <Button type="submit" size="lg" className="px-6 h-11 text-base !bg-foreground" disabled={isSubmitting || !csrfToken}>
- <span className="relative z-10">{isSubmitting ? "Joining..." : "Join waitlist"}</span>
+ <Button
+ type="submit"
+ size="lg"
+ className="px-6 h-11 text-base !bg-foreground"
+ disabled={isSubmitting || !csrfToken}
+ >
+ <span className="relative z-10">
+ {isSubmitting ? "Joining..." : "Join waitlist"}
+ </span>
<ArrowRight className="relative z-10 ml-0.5 h-4 w-4 inline-block" />
</Button>
</form>
</motion.div>
+ <motion.div
+ initial={{ opacity: 0, y: 10 }}
+ animate={{ opacity: 1, y: 0 }}
+ transition={{ delay: 0.8, duration: 0.6 }}
+ className="mt-8 inline-flex items-center gap-2 text-sm text-muted-foreground justify-center"
+ >
+ <div className="w-2 h-2 bg-green-500 rounded-full animate-pulse" />
+ <span>50k+ people already joined</span>
+ </motion.div>
</motion.div>
</div>
);
diff --git a/apps/web/src/components/ui/draggable-item.tsx b/apps/web/src/components/ui/draggable-item.tsx
index c1f81e16..b15e8df8 100644
--- a/apps/web/src/components/ui/draggable-item.tsx
+++ b/apps/web/src/components/ui/draggable-item.tsx
@@ -2,6 +2,11 @@
import { AspectRatio } from "@/components/ui/aspect-ratio";
import { Button } from "@/components/ui/button";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@/components/ui/tooltip";
import { ReactNode, useState, useRef, useEffect } from "react";
import { createPortal } from "react-dom";
import { Plus } from "lucide-react";
@@ -139,7 +144,12 @@ export function DraggableMediaItem({
<div className="w-full h-full [&_img]:w-full [&_img]:h-full [&_img]:object-cover [&_img]:rounded-none">
{preview}
</div>
- {showPlusOnDrag && <PlusButton onClick={handleAddToTimeline} tooltipText="Add to timeline or drag to position" />}
+ {showPlusOnDrag && (
+ <PlusButton
+ onClick={handleAddToTimeline}
+ tooltipText="Add to timeline or drag to position"
+ />
+ )}
</AspectRatio>
</div>
</div>,
@@ -149,8 +159,16 @@ export function DraggableMediaItem({
);
}
-function PlusButton({ className, onClick }: { className?: string; onClick?: () => void }) {
- return (
+function PlusButton({
+ className,
+ onClick,
+ tooltipText,
+}: {
+ className?: string;
+ onClick?: () => void;
+ tooltipText?: string;
+}) {
+ const button = (
<Button
size="icon"
className={cn("absolute bottom-2 right-2 size-4", className)}
@@ -163,4 +181,17 @@ function PlusButton({ className, onClick }: { className?: string; onClick?: () =
<Plus className="!size-3" />
</Button>
);
+
+ if (tooltipText) {
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>{button}</TooltipTrigger>
+ <TooltipContent>
+ <p>{tooltipText}</p>
+ </TooltipContent>
+ </Tooltip>
+ );
+ }
+
+ return button;
}