feat: add conditional rendering to properties panel with text size functionality

This commit is contained in:
Maze Winther
2025-07-09 23:59:13 +02:00
parent b6aa8e10d6
commit 7bf6671c0a
2 changed files with 102 additions and 12 deletions

View File

@ -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>
);
}

View File

@ -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);