summaryrefslogtreecommitdiff
path: root/apps/web/src/components/editor/panels/preview/bookmark-note-overlay.tsx
blob: 3d96f7623169ab54e8780e61e7a2aa5ea216bea5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use client";

import { useEditor } from "@/hooks/use-editor";
import { findCurrentScene } from "@/lib/scenes";
import { getBookmarksActiveAtTime } from "@/lib/timeline/bookmarks";

export function BookmarkNoteOverlay() {
	const editor = useEditor();
	const currentTime = editor.playback.getCurrentTime();
	const activeProject = editor.project.getActive();

	if (!activeProject) {
		return null;
	}

	const activeScene = findCurrentScene({
		scenes: activeProject.scenes,
		currentSceneId: activeProject.currentSceneId,
	});

	if (!activeScene) {
		return null;
	}

	const bookmarks = activeScene.bookmarks;
	const activeBookmarks = getBookmarksActiveAtTime({
		bookmarks,
		time: currentTime,
	});
	const bookmarksWithNotes = activeBookmarks.filter(
		(bookmark) => bookmark.note != null && bookmark.note.trim() !== "",
	);

	if (bookmarksWithNotes.length === 0) {
		return null;
	}

	return (
		<div
			className="pointer-events-none absolute top-2 left-2 flex flex-col gap-1.5"
			aria-live="polite"
		>
			{bookmarksWithNotes.map((bookmark) => (
				<div
					key={bookmark.time}
					className="flex max-w-[min(200px,50vw)] px-2.5 py-1.5 text-left text-white text-xs shadow-md backdrop-blur-sm"
					style={{
						backgroundColor: "rgb(0 0 0 / 0.5)",
						borderLeft: bookmark.color
							? `3px solid ${bookmark.color}`
							: "3px solid var(--primary)",
					}}
				>
					{bookmark.note}
				</div>
			))}
		</div>
	);
}