Skip to content

Open source CapCut alternative.

TypeScript

feat(site): point an empty timeline at the one with the edit

David Le14276c00522a
diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsx
index 00d1f870..e363fd91 100644
--- a/site/src/cut/components/Timeline.tsx
+++ b/site/src/cut/components/Timeline.tsx
@@ -7,7 +7,7 @@ import { ArrowDownToLine, AudioLines, Check, Clapperboard, Copy, Diamond, Downlo
import { EFFECT_CHIP_ICONS, effectIconKind, SHAPE_CHIP_ICONS, TRANSITION_ICONS } from "@/cut/components/entityIcons";
import { Button } from "@/components/ui/button";
import { GuidesMenu } from "@/cut/components/GuidesMenu";
-import { TimelinePicker } from "@/cut/components/TimelinePicker";
+import { EmptyTimelineNote, TimelinePicker } from "@/cut/components/TimelinePicker";
import {
DropdownMenu,
DropdownMenuContent,
@@ -2295,6 +2295,7 @@ export function Timeline() {
</div>
</div>
<RulerBand />
+ {total <= 0 && <EmptyTimelineNote />}
{marquee && (
<div
className="pointer-events-none fixed z-50 rounded-[3px] border-2 border-[#0a84ff]"
diff --git a/site/src/cut/components/TimelinePicker.tsx b/site/src/cut/components/TimelinePicker.tsx
index b272a9e0..ebf1accf 100644
--- a/site/src/cut/components/TimelinePicker.tsx
+++ b/site/src/cut/components/TimelinePicker.tsx
@@ -12,8 +12,9 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { useEditor } from "@/cut/lib/store";
+import { timelineEnd } from "@/cut/lib/timelineEnd";
import { switchTimeline, useTimelinePicker } from "@/cut/lib/timelineSwitch";
-import { isTimelineId, TIMELINE_IDS, TIMELINE_LABELS } from "@/cut/lib/types";
+import { isTimelineId, TIMELINE_IDS, TIMELINE_LABELS, type TimelineBody } from "@/cut/lib/types";
/** The timeline picker at the head of the toolbar: the open timeline's name,
* and the project's others under it. Held while work is still landing on the
@@ -55,3 +56,52 @@ export function TimelinePicker() {
</>
);
}
+
+// A parked timeline holds the edit by the same rule the open one is empty by:
+// it ends past zero. Parked bodies change only on a switch, so each one's end
+// is computed once.
+const parkedEnds = new WeakMap<Partial<TimelineBody>, number>();
+function holdsItems(b: Partial<TimelineBody> | undefined): boolean {
+ if (!b) {
+ return false;
+ }
+ let end = parkedEnds.get(b);
+ if (end === undefined) {
+ end = timelineEnd(b);
+ parkedEnds.set(b, end);
+ }
+ return end > 0;
+}
+
+/** The note an empty timeline shows when another of the project's timelines
+ * holds the edit, so opening an empty one never reads as the edit gone. */
+export function EmptyTimelineNote() {
+ const timeline = useEditor((s) => s.timeline);
+ const readOnly = useEditor((s) => s.readOnly);
+ const other = useEditor((s) => TIMELINE_IDS.find((id) => id !== s.timeline && holdsItems(s.timelines[id])));
+ const { supported, blocked } = useTimelinePicker();
+ if (readOnly || !supported || !other) {
+ return null;
+ }
+
+ // Centered over the lanes; only the button takes the pointer, so drops onto
+ // the empty timeline still land.
+ return (
+ <div className="pointer-events-none absolute inset-0 z-30 grid place-items-center">
+ <div className="flex items-center gap-2 text-sm text-muted-foreground">
+ <span>
+ {TIMELINE_LABELS[timeline]} is empty. Your edit is on {TIMELINE_LABELS[other]}.
+ </span>
+ <Button
+ variant="outline"
+ size="sm"
+ className="pointer-events-auto"
+ disabled={blocked}
+ onClick={() => void switchTimeline(other)}
+ >
+ Open {TIMELINE_LABELS[other]}
+ </Button>
+ </div>
+ </div>
+ );
+}