summaryrefslogtreecommitdiff
path: root/apps/web
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2025-07-09 23:59:13 +0200
committerMaze Winther <mazewinther@gmail.com>2025-07-09 23:59:13 +0200
commit7bf6671c0a40b54f7cbce09022c4a874e82bc8ad (patch)
treec354f2614ff4f0e3785635b842c22f3e9456e264 /apps/web
parentb6aa8e10d69ccf547f3cb0051d10fda014a2d01e (diff)
downloadopencut-7bf6671c0a40b54f7cbce09022c4a874e82bc8ad.tar.gz
feat: add conditional rendering to properties panel with text size functionality
Diffstat (limited to 'apps/web')
-rw-r--r--apps/web/src/components/editor/properties-panel.tsx73
-rw-r--r--apps/web/src/stores/timeline-store.ts41
2 files changed, 102 insertions, 12 deletions
diff --git a/apps/web/src/components/editor/properties-panel.tsx b/apps/web/src/components/editor/properties-panel.tsx
index b0f9c62e..4aea58c7 100644
--- a/apps/web/src/components/editor/properties-panel.tsx
+++ b/apps/web/src/components/editor/properties-panel.tsx
@@ -4,25 +4,74 @@ import { useProjectStore } from "@/stores/project-store";
import { useAspectRatio } from "@/hooks/use-aspect-ratio";
import { Label } from "../ui/label";
import { ScrollArea } from "../ui/scroll-area";
+import { useTimelineStore } from "@/stores/timeline-store";
+import { Input } from "../ui/input";
+import { MediaElement, TextElement } from "@/types/timeline";
+import { useMediaStore } from "@/stores/media-store";
export function PropertiesPanel() {
const { activeProject } = useProjectStore();
const { getDisplayName, canvasSize } = useAspectRatio();
+ const { selectedElements, tracks, updateTextElement } = useTimelineStore();
+ const { mediaItems } = useMediaStore();
+
+ const emptyView = (
+ <div className="space-y-4 p-5">
+ {/* Media Properties */}
+ <div className="flex flex-col gap-3">
+ <PropertyItem label="Name:" value={activeProject?.name || ""} />
+ <PropertyItem label="Aspect ratio:" value={getDisplayName()} />
+ <PropertyItem
+ label="Resolution:"
+ value={`${canvasSize.width} × ${canvasSize.height}`}
+ />
+ <PropertyItem label="Frame rate:" value="30.00fps" />
+ </div>
+ </div>
+ );
+
+ const TextProperties = (element: TextElement, trackId: string) => (
+ <div className="space-y-4 p-5">
+ <Input
+ placeholder="Name"
+ defaultValue={element.content}
+ onChange={(e) =>
+ updateTextElement(trackId, element.id, { content: e.target.value })
+ }
+ />
+ </div>
+ );
+
+ const MediaProperties = (element: MediaElement) => {
+ const mediaItem = mediaItems.find((item) => item.id === element.mediaId);
+
+ if (mediaItem?.type === "audio") {
+ return <div className="space-y-4 p-5">Audio properties</div>;
+ }
+
+ // video or image
+ return <div className="space-y-4 p-5">Video/Image properties</div>;
+ };
+
+ const ElementProperties = (
+ <>
+ {selectedElements.map(({ trackId, elementId }) => {
+ const track = tracks.find((t) => t.id === trackId);
+ const element = track?.elements.find((e) => e.id === elementId);
+
+ if (element?.type === "text") {
+ return <div key={elementId}>{TextProperties(element, trackId)}</div>;
+ }
+ if (element?.type === "media") {
+ return <div key={elementId}>{MediaProperties(element)}</div>;
+ }
+ })}
+ </>
+ );
return (
<ScrollArea className="h-full bg-panel rounded-sm">
- <div className="space-y-4 p-5">
- {/* Media Properties */}
- <div className="flex flex-col gap-3">
- <PropertyItem label="Name:" value={activeProject?.name || ""} />
- <PropertyItem label="Aspect ratio:" value={getDisplayName()} />
- <PropertyItem
- label="Resolution:"
- value={`${canvasSize.width} × ${canvasSize.height}`}
- />
- <PropertyItem label="Frame rate:" value="30.00fps" />
- </div>
- </div>
+ {selectedElements.length > 0 ? ElementProperties : emptyView}
</ScrollArea>
);
}
diff --git a/apps/web/src/stores/timeline-store.ts b/apps/web/src/stores/timeline-store.ts
index 7431e085..8c934392 100644
--- a/apps/web/src/stores/timeline-store.ts
+++ b/apps/web/src/stores/timeline-store.ts
@@ -4,6 +4,7 @@ import {
TimelineElement,
CreateTimelineElement,
TimelineTrack,
+ TextElement,
sortTracksByOrder,
ensureMainTrack,
validateElementTrackCompatibility,
@@ -136,6 +137,28 @@ interface TimelineStore {
loadProjectTimeline: (projectId: string) => Promise<void>;
saveProjectTimeline: (projectId: string) => Promise<void>;
clearTimeline: () => void;
+ updateTextElement: (
+ trackId: string,
+ elementId: string,
+ updates: Partial<
+ Pick<
+ TextElement,
+ | "content"
+ | "fontSize"
+ | "fontFamily"
+ | "color"
+ | "backgroundColor"
+ | "textAlign"
+ | "fontWeight"
+ | "fontStyle"
+ | "textDecoration"
+ | "x"
+ | "y"
+ | "rotation"
+ | "opacity"
+ >
+ >
+ ) => void;
}
export const useTimelineStore = create<TimelineStore>((set, get) => {
@@ -494,6 +517,24 @@ export const useTimelineStore = create<TimelineStore>((set, get) => {
);
},
+ updateTextElement: (trackId, elementId, updates) => {
+ get().pushHistory();
+ updateTracksAndSave(
+ get()._tracks.map((track) =>
+ track.id === trackId
+ ? {
+ ...track,
+ elements: track.elements.map((element) =>
+ element.id === elementId && element.type === "text"
+ ? { ...element, ...updates }
+ : element
+ ),
+ }
+ : track
+ )
+ );
+ },
+
splitElement: (trackId, elementId, splitTime) => {
const { _tracks } = get();
const track = _tracks.find((t) => t.id === trackId);