From 47288849319b7cec46aaf83f81845fb1ba5986d4 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Fri, 4 Jul 2025 01:30:24 +0200 Subject: refactor: new reusable draggable-item component and use it --- .../components/editor/media-panel/views/media.tsx | 80 +++++++--------------- .../components/editor/media-panel/views/text.tsx | 22 ++++-- 2 files changed, 44 insertions(+), 58 deletions(-) (limited to 'apps/web/src/components/editor') diff --git a/apps/web/src/components/editor/media-panel/views/media.tsx b/apps/web/src/components/editor/media-panel/views/media.tsx index e2c72106..50fb6fa6 100644 --- a/apps/web/src/components/editor/media-panel/views/media.tsx +++ b/apps/web/src/components/editor/media-panel/views/media.tsx @@ -7,7 +7,6 @@ import { useTimelineStore } from "@/stores/timeline-store"; import { Image, Music, Plus, Upload, Video } from "lucide-react"; import { useEffect, useRef, useState } from "react"; import { toast } from "sonner"; -import { AspectRatio } from "@/components/ui/aspect-ratio"; import { Button } from "@/components/ui/button"; import { DragOverlay } from "@/components/ui/drag-overlay"; import { @@ -24,6 +23,7 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; +import { DraggableMediaItem } from "@/components/ui/draggable-item"; export function MediaView() { const { mediaItems, addMediaItem, removeMediaItem } = useMediaStore(); @@ -98,19 +98,6 @@ export function MediaView() { return `${min}:${sec.toString().padStart(2, "0")}`; }; - const startDrag = (e: React.DragEvent, item: MediaItem) => { - // When dragging a media item, set drag data for timeline to read - e.dataTransfer.setData( - "application/x-media-item", - JSON.stringify({ - id: item.id, - type: item.type, - name: item.name, - }) - ); - e.dataTransfer.effectAllowed = "copy"; - }; - const [filteredMediaItems, setFilteredMediaItems] = useState(mediaItems); useEffect(() => { @@ -140,7 +127,7 @@ export function MediaView() { {item.name} @@ -293,45 +280,30 @@ export function MediaView() { > {/* Render each media item as a draggable button */} {filteredMediaItems.map((item) => ( -
- - - - - - Export clips - handleRemove(e, item.id)} - > - Delete - - - -
+ + + + + + Export clips + handleRemove(e, item.id)} + > + Delete + + + ))} )} diff --git a/apps/web/src/components/editor/media-panel/views/text.tsx b/apps/web/src/components/editor/media-panel/views/text.tsx index 9e4f6190..ab698528 100644 --- a/apps/web/src/components/editor/media-panel/views/text.tsx +++ b/apps/web/src/components/editor/media-panel/views/text.tsx @@ -1,11 +1,25 @@ -import { Card } from "@/components/ui/card"; +import { DraggableMediaItem } from "@/components/ui/draggable-item"; export function TextView() { return (
- - Default text - + + Default text +
+ } + dragData={{ + id: "default-text", + type: "text", + name: "Default text", + content: "Default text", + }} + aspectRatio={1} + className="w-24" + showLabel={false} + /> ); } -- cgit v1.3.1