mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
feat: add hide or show for media elements, mute or unmute for audio elements (#500)
* feat: create external tools section (#493) * feat: create external tools section * fix: better wording * Feature, added hide or show for media elements, mute or unmute for audio elements both effective on timeline and preview panel, with overlay icon for indicating so and state storing, * Minor UI vertical separator between magnifier and other buttons * fixed the AbortError issue in the AudioWaveform component. The error was occurring because of a race condition during cleanup when the component unmounts. * feat: implement bookmarking functionality in the timeline and project storage - Added bookmark management methods in the project store for toggling and checking bookmarks. - Updated the timeline component to display bookmark markers and integrate bookmark actions in the context menu. - Enhanced the storage service to handle bookmarks in project serialization and deserialization. - Updated project types to include bookmarks as an array of numbers. --------- Co-authored-by: Dominik K. <dominik@koch-bautechnik.de> Co-authored-by: Maze Winther <mazewinther@gmail.com>
This commit is contained in:
co-authored by
Dominik K.
Maze Winther
parent
b229d94a8d
commit
f255ccb818
@@ -19,22 +19,21 @@ const AudioWaveform: React.FC<AudioWaveformProps> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let mounted = true;
|
let mounted = true;
|
||||||
|
let ws = wavesurfer.current;
|
||||||
|
|
||||||
const initWaveSurfer = async () => {
|
const initWaveSurfer = async () => {
|
||||||
if (!waveformRef.current || !audioUrl) return;
|
if (!waveformRef.current || !audioUrl) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Clean up any existing instance
|
// Clear any existing instance safely
|
||||||
if (wavesurfer.current) {
|
if (ws) {
|
||||||
try {
|
// Instead of immediately destroying, just set to null
|
||||||
wavesurfer.current.destroy();
|
// We'll destroy it outside this function
|
||||||
} catch (e) {
|
|
||||||
// Silently ignore destroy errors
|
|
||||||
}
|
|
||||||
wavesurfer.current = null;
|
wavesurfer.current = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
wavesurfer.current = WaveSurfer.create({
|
// Create a fresh instance
|
||||||
|
const newWaveSurfer = WaveSurfer.create({
|
||||||
container: waveformRef.current,
|
container: waveformRef.current,
|
||||||
waveColor: "rgba(255, 255, 255, 0.6)",
|
waveColor: "rgba(255, 255, 255, 0.6)",
|
||||||
progressColor: "rgba(255, 255, 255, 0.9)",
|
progressColor: "rgba(255, 255, 255, 0.9)",
|
||||||
@@ -46,15 +45,28 @@ const AudioWaveform: React.FC<AudioWaveformProps> = ({
|
|||||||
interact: false,
|
interact: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Assign to ref only if component is still mounted
|
||||||
|
if (mounted) {
|
||||||
|
wavesurfer.current = newWaveSurfer;
|
||||||
|
} else {
|
||||||
|
// Component unmounted during initialization, clean up
|
||||||
|
try {
|
||||||
|
newWaveSurfer.destroy();
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore destroy errors
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Event listeners
|
// Event listeners
|
||||||
wavesurfer.current.on("ready", () => {
|
newWaveSurfer.on("ready", () => {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
setError(false);
|
setError(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
wavesurfer.current.on("error", (err) => {
|
newWaveSurfer.on("error", (err) => {
|
||||||
console.error("WaveSurfer error:", err);
|
console.error("WaveSurfer error:", err);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setError(true);
|
setError(true);
|
||||||
@@ -62,7 +74,7 @@ const AudioWaveform: React.FC<AudioWaveformProps> = ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await wavesurfer.current.load(audioUrl);
|
await newWaveSurfer.load(audioUrl);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to initialize WaveSurfer:", err);
|
console.error("Failed to initialize WaveSurfer:", err);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
@@ -72,17 +84,50 @@ const AudioWaveform: React.FC<AudioWaveformProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
initWaveSurfer();
|
// First safely destroy previous instance if it exists
|
||||||
|
if (ws) {
|
||||||
|
// Use this pattern to safely destroy the previous instance
|
||||||
|
const wsToDestroy = ws;
|
||||||
|
// Detach from ref immediately
|
||||||
|
wavesurfer.current = null;
|
||||||
|
|
||||||
|
// Wait a tick to destroy so any pending operations can complete
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
try {
|
||||||
|
wsToDestroy.destroy();
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore errors during destroy
|
||||||
|
}
|
||||||
|
// Only initialize new instance after destroying the old one
|
||||||
|
if (mounted) {
|
||||||
|
initWaveSurfer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// No previous instance to clean up, initialize directly
|
||||||
|
initWaveSurfer();
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
// Mark component as unmounted
|
||||||
mounted = false;
|
mounted = false;
|
||||||
if (wavesurfer.current) {
|
|
||||||
try {
|
// Store reference to current wavesurfer instance
|
||||||
wavesurfer.current.destroy();
|
const wsToDestroy = wavesurfer.current;
|
||||||
} catch (e) {
|
|
||||||
// Silently ignore destroy errors
|
// Immediately clear the ref to prevent accessing it after unmount
|
||||||
}
|
wavesurfer.current = null;
|
||||||
wavesurfer.current = null;
|
|
||||||
|
// If we have an instance to clean up, do it safely
|
||||||
|
if (wsToDestroy) {
|
||||||
|
// Delay destruction to avoid race conditions
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
try {
|
||||||
|
wsToDestroy.destroy();
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore destroy errors - they're expected
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [audioUrl, height]);
|
}, [audioUrl, height]);
|
||||||
|
|||||||
@@ -234,6 +234,7 @@ export function PreviewPanel() {
|
|||||||
|
|
||||||
tracks.forEach((track) => {
|
tracks.forEach((track) => {
|
||||||
track.elements.forEach((element) => {
|
track.elements.forEach((element) => {
|
||||||
|
if (element.hidden) return;
|
||||||
const elementStart = element.startTime;
|
const elementStart = element.startTime;
|
||||||
const elementEnd =
|
const elementEnd =
|
||||||
element.startTime +
|
element.startTime +
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
Link,
|
Link,
|
||||||
ZoomIn,
|
ZoomIn,
|
||||||
ZoomOut,
|
ZoomOut,
|
||||||
|
Bookmark,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
@@ -651,6 +652,30 @@ export function Timeline() {
|
|||||||
);
|
);
|
||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
})()}
|
})()}
|
||||||
|
|
||||||
|
{/* Bookmark markers */}
|
||||||
|
{(() => {
|
||||||
|
const { activeProject } = useProjectStore.getState();
|
||||||
|
if (!activeProject?.bookmarks?.length) return null;
|
||||||
|
|
||||||
|
return activeProject.bookmarks.map((bookmarkTime, i) => (
|
||||||
|
<div
|
||||||
|
key={`bookmark-${i}`}
|
||||||
|
className="absolute top-0 h-10 w-0.5 !bg-primary cursor-pointer"
|
||||||
|
style={{
|
||||||
|
left: `${bookmarkTime * TIMELINE_CONSTANTS.PIXELS_PER_SECOND * zoomLevel}px`,
|
||||||
|
}}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
usePlaybackStore.getState().seek(bookmarkTime);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className="absolute top-[-1px] left-[-5px] text-primary">
|
||||||
|
<Bookmark className="h-3 w-3 fill-primary" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
})()}
|
||||||
</div>
|
</div>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
</div>
|
</div>
|
||||||
@@ -773,6 +798,23 @@ export function Timeline() {
|
|||||||
<ContextMenuItem onClick={(e) => e.stopPropagation()}>
|
<ContextMenuItem onClick={(e) => e.stopPropagation()}>
|
||||||
Track settings (soon)
|
Track settings (soon)
|
||||||
</ContextMenuItem>
|
</ContextMenuItem>
|
||||||
|
{activeProject?.bookmarks?.length && activeProject.bookmarks.length > 0 && (
|
||||||
|
<>
|
||||||
|
<ContextMenuItem disabled>Bookmarks</ContextMenuItem>
|
||||||
|
{activeProject.bookmarks.map((bookmarkTime, i) => (
|
||||||
|
<ContextMenuItem
|
||||||
|
key={`bookmark-menu-${i}`}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
seek(bookmarkTime);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Bookmark className="h-3 w-3 mr-2 inline-block" />
|
||||||
|
{bookmarkTime.toFixed(1)}s
|
||||||
|
</ContextMenuItem>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</ContextMenuContent>
|
</ContextMenuContent>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
))}
|
))}
|
||||||
@@ -828,6 +870,7 @@ function TimelineToolbar({
|
|||||||
toggleRippleEditing,
|
toggleRippleEditing,
|
||||||
} = useTimelineStore();
|
} = useTimelineStore();
|
||||||
const { currentTime, duration, isPlaying, toggle } = usePlaybackStore();
|
const { currentTime, duration, isPlaying, toggle } = usePlaybackStore();
|
||||||
|
const { toggleBookmark, isBookmarked } = useProjectStore();
|
||||||
|
|
||||||
// Action handlers
|
// Action handlers
|
||||||
const handleSplitSelected = () => {
|
const handleSplitSelected = () => {
|
||||||
@@ -957,6 +1000,13 @@ function TimelineToolbar({
|
|||||||
const handleZoomSliderChange = (values: number[]) => {
|
const handleZoomSliderChange = (values: number[]) => {
|
||||||
setZoomLevel(values[0]);
|
setZoomLevel(values[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleToggleBookmark = async () => {
|
||||||
|
await toggleBookmark(currentTime);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if the current time is bookmarked
|
||||||
|
const currentBookmarked = isBookmarked(currentTime);
|
||||||
return (
|
return (
|
||||||
<div className="border-b flex items-center justify-between px-2 py-1">
|
<div className="border-b flex items-center justify-between px-2 py-1">
|
||||||
<div className="flex items-center gap-1 w-full">
|
<div className="flex items-center gap-1 w-full">
|
||||||
@@ -1088,6 +1138,17 @@ function TimelineToolbar({
|
|||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent>Delete element (Delete)</TooltipContent>
|
<TooltipContent>Delete element (Delete)</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
<div className="w-px h-6 bg-border mx-1" />
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Button variant="text" size="icon" onClick={handleToggleBookmark}>
|
||||||
|
<Bookmark className={`h-4 w-4 ${currentBookmarked ? "fill-primary text-primary" : ""}`} />
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
{currentBookmarked ? "Remove bookmark" : "Add bookmark"}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
@@ -1121,6 +1182,8 @@ function TimelineToolbar({
|
|||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
|
|
||||||
|
<div className="h-6 w-px bg-border mx-1" />
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<Button variant="text" size="icon" onClick={handleZoomOut}>
|
<Button variant="text" size="icon" onClick={handleZoomOut}>
|
||||||
<ZoomOut className="h-4 w-4" />
|
<ZoomOut className="h-4 w-4" />
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ import {
|
|||||||
Type,
|
Type,
|
||||||
Copy,
|
Copy,
|
||||||
RefreshCw,
|
RefreshCw,
|
||||||
|
EyeOff,
|
||||||
|
Eye,
|
||||||
|
Volume2,
|
||||||
|
VolumeX,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useMediaStore } from "@/stores/media-store";
|
import { useMediaStore } from "@/stores/media-store";
|
||||||
import { useTimelineStore } from "@/stores/timeline-store";
|
import { useTimelineStore } from "@/stores/timeline-store";
|
||||||
@@ -66,11 +70,18 @@ export function TimelineElement({
|
|||||||
addElementToTrack,
|
addElementToTrack,
|
||||||
replaceElementMedia,
|
replaceElementMedia,
|
||||||
rippleEditingEnabled,
|
rippleEditingEnabled,
|
||||||
|
toggleElementHidden,
|
||||||
} = useTimelineStore();
|
} = useTimelineStore();
|
||||||
const { currentTime } = usePlaybackStore();
|
const { currentTime } = usePlaybackStore();
|
||||||
|
|
||||||
const [elementMenuOpen, setElementMenuOpen] = useState(false);
|
const [elementMenuOpen, setElementMenuOpen] = useState(false);
|
||||||
|
|
||||||
|
const mediaItem =
|
||||||
|
element.type === "media"
|
||||||
|
? mediaItems.find((item) => item.id === element.mediaId)
|
||||||
|
: null;
|
||||||
|
const isAudio = mediaItem?.type === "audio";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
resizing,
|
resizing,
|
||||||
isResizing,
|
isResizing,
|
||||||
@@ -141,6 +152,11 @@ export function TimelineElement({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleToggleElementHidden = (e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
toggleElementHidden(track.id, element.id);
|
||||||
|
};
|
||||||
|
|
||||||
const handleReplaceClip = (e: React.MouseEvent) => {
|
const handleReplaceClip = (e: React.MouseEvent) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (element.type !== "media") {
|
if (element.type !== "media") {
|
||||||
@@ -332,7 +348,7 @@ export function TimelineElement({
|
|||||||
track.type
|
track.type
|
||||||
)} ${isSelected ? "border-b-[0.5px] border-t-[0.5px] border-foreground" : ""} ${
|
)} ${isSelected ? "border-b-[0.5px] border-t-[0.5px] border-foreground" : ""} ${
|
||||||
isBeingDragged ? "z-50" : "z-10"
|
isBeingDragged ? "z-50" : "z-10"
|
||||||
}`}
|
} ${element.hidden ? "opacity-50" : ""}`}
|
||||||
onClick={(e) => onElementClick && onElementClick(e, element)}
|
onClick={(e) => onElementClick && onElementClick(e, element)}
|
||||||
onMouseDown={handleElementMouseDown}
|
onMouseDown={handleElementMouseDown}
|
||||||
onContextMenu={(e) =>
|
onContextMenu={(e) =>
|
||||||
@@ -343,6 +359,16 @@ export function TimelineElement({
|
|||||||
{renderElementContent()}
|
{renderElementContent()}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{element.hidden && (
|
||||||
|
<div className="absolute inset-0 bg-black bg-opacity-50 flex items-center justify-center pointer-events-none">
|
||||||
|
{isAudio ? (
|
||||||
|
<VolumeX className="h-6 w-6 text-white" />
|
||||||
|
) : (
|
||||||
|
<EyeOff className="h-6 w-6 text-white" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{isSelected && (
|
{isSelected && (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
@@ -363,6 +389,29 @@ export function TimelineElement({
|
|||||||
<Scissors className="h-4 w-4 mr-2" />
|
<Scissors className="h-4 w-4 mr-2" />
|
||||||
Split at playhead
|
Split at playhead
|
||||||
</ContextMenuItem>
|
</ContextMenuItem>
|
||||||
|
<ContextMenuItem onClick={handleToggleElementHidden}>
|
||||||
|
{isAudio ? (
|
||||||
|
element.hidden ? (
|
||||||
|
<Volume2 className="h-4 w-4 mr-2" />
|
||||||
|
) : (
|
||||||
|
<VolumeX className="h-4 w-4 mr-2" />
|
||||||
|
)
|
||||||
|
) : element.hidden ? (
|
||||||
|
<Eye className="h-4 w-4 mr-2" />
|
||||||
|
) : (
|
||||||
|
<EyeOff className="h-4 w-4 mr-2" />
|
||||||
|
)}
|
||||||
|
<span>
|
||||||
|
{isAudio
|
||||||
|
? element.hidden
|
||||||
|
? "Unmute"
|
||||||
|
: "Mute"
|
||||||
|
: element.hidden
|
||||||
|
? "Show"
|
||||||
|
: "Hide"}{" "}
|
||||||
|
{element.type === "text" ? "text" : "clip"}
|
||||||
|
</span>
|
||||||
|
</ContextMenuItem>
|
||||||
<ContextMenuItem onClick={handleElementDuplicateContext}>
|
<ContextMenuItem onClick={handleElementDuplicateContext}>
|
||||||
<Copy className="h-4 w-4 mr-2" />
|
<Copy className="h-4 w-4 mr-2" />
|
||||||
Duplicate {element.type === "text" ? "text" : "clip"}
|
Duplicate {element.type === "text" ? "text" : "clip"}
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ class StorageService {
|
|||||||
backgroundColor: project.backgroundColor,
|
backgroundColor: project.backgroundColor,
|
||||||
backgroundType: project.backgroundType,
|
backgroundType: project.backgroundType,
|
||||||
blurIntensity: project.blurIntensity,
|
blurIntensity: project.blurIntensity,
|
||||||
|
bookmarks: project.bookmarks,
|
||||||
|
fps: project.fps,
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.projectsAdapter.set(project.id, serializedProject);
|
await this.projectsAdapter.set(project.id, serializedProject);
|
||||||
@@ -83,6 +85,8 @@ class StorageService {
|
|||||||
backgroundColor: serializedProject.backgroundColor,
|
backgroundColor: serializedProject.backgroundColor,
|
||||||
backgroundType: serializedProject.backgroundType,
|
backgroundType: serializedProject.backgroundType,
|
||||||
blurIntensity: serializedProject.blurIntensity,
|
blurIntensity: serializedProject.blurIntensity,
|
||||||
|
bookmarks: serializedProject.bookmarks,
|
||||||
|
fps: serializedProject.fps,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export interface StorageConfig {
|
|||||||
export type SerializedProject = Omit<TProject, "createdAt" | "updatedAt"> & {
|
export type SerializedProject = Omit<TProject, "createdAt" | "updatedAt"> & {
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
|
bookmarks?: number[];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extend FileSystemDirectoryHandle with missing async iterator methods
|
// Extend FileSystemDirectoryHandle with missing async iterator methods
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ interface ProjectStore {
|
|||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
updateProjectFps: (fps: number) => Promise<void>;
|
updateProjectFps: (fps: number) => Promise<void>;
|
||||||
|
|
||||||
|
// Bookmark methods
|
||||||
|
toggleBookmark: (time: number) => Promise<void>;
|
||||||
|
isBookmarked: (time: number) => boolean;
|
||||||
|
removeBookmark: (time: number) => Promise<void>;
|
||||||
|
|
||||||
getFilteredAndSortedProjects: (
|
getFilteredAndSortedProjects: (
|
||||||
searchQuery: string,
|
searchQuery: string,
|
||||||
sortOption: string
|
sortOption: string
|
||||||
@@ -40,6 +45,97 @@ export const useProjectStore = create<ProjectStore>((set, get) => ({
|
|||||||
isLoading: true,
|
isLoading: true,
|
||||||
isInitialized: false,
|
isInitialized: false,
|
||||||
|
|
||||||
|
// Implementation of bookmark methods
|
||||||
|
toggleBookmark: async (time: number) => {
|
||||||
|
const { activeProject } = get();
|
||||||
|
if (!activeProject) return;
|
||||||
|
|
||||||
|
// Round time to the nearest frame
|
||||||
|
const fps = activeProject.fps || 30;
|
||||||
|
const frameTime = Math.round(time * fps) / fps;
|
||||||
|
|
||||||
|
const bookmarks = activeProject.bookmarks || [];
|
||||||
|
let updatedBookmarks: number[];
|
||||||
|
|
||||||
|
// Check if already bookmarked
|
||||||
|
const bookmarkIndex = bookmarks.findIndex(
|
||||||
|
bookmark => Math.abs(bookmark - frameTime) < 0.001
|
||||||
|
);
|
||||||
|
|
||||||
|
if (bookmarkIndex !== -1) {
|
||||||
|
// Remove bookmark
|
||||||
|
updatedBookmarks = bookmarks.filter((_, i) => i !== bookmarkIndex);
|
||||||
|
} else {
|
||||||
|
// Add bookmark
|
||||||
|
updatedBookmarks = [...bookmarks, frameTime].sort((a, b) => a - b);
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedProject = {
|
||||||
|
...activeProject,
|
||||||
|
bookmarks: updatedBookmarks,
|
||||||
|
updatedAt: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await storageService.saveProject(updatedProject);
|
||||||
|
set({ activeProject: updatedProject });
|
||||||
|
await get().loadAllProjects(); // Refresh the list
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to update project bookmarks:", error);
|
||||||
|
toast.error("Failed to update bookmarks", {
|
||||||
|
description: "Please try again",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
isBookmarked: (time: number) => {
|
||||||
|
const { activeProject } = get();
|
||||||
|
if (!activeProject || !activeProject.bookmarks) return false;
|
||||||
|
|
||||||
|
// Round time to the nearest frame
|
||||||
|
const fps = activeProject.fps || 30;
|
||||||
|
const frameTime = Math.round(time * fps) / fps;
|
||||||
|
|
||||||
|
return activeProject.bookmarks.some(
|
||||||
|
bookmark => Math.abs(bookmark - frameTime) < 0.001
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
removeBookmark: async (time: number) => {
|
||||||
|
const { activeProject } = get();
|
||||||
|
if (!activeProject || !activeProject.bookmarks) return;
|
||||||
|
|
||||||
|
// Round time to the nearest frame
|
||||||
|
const fps = activeProject.fps || 30;
|
||||||
|
const frameTime = Math.round(time * fps) / fps;
|
||||||
|
|
||||||
|
const updatedBookmarks = activeProject.bookmarks.filter(
|
||||||
|
bookmark => Math.abs(bookmark - frameTime) >= 0.001
|
||||||
|
);
|
||||||
|
|
||||||
|
if (updatedBookmarks.length === activeProject.bookmarks.length) {
|
||||||
|
// No bookmark found to remove
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedProject = {
|
||||||
|
...activeProject,
|
||||||
|
bookmarks: updatedBookmarks,
|
||||||
|
updatedAt: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await storageService.saveProject(updatedProject);
|
||||||
|
set({ activeProject: updatedProject });
|
||||||
|
await get().loadAllProjects(); // Refresh the list
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to update project bookmarks:", error);
|
||||||
|
toast.error("Failed to remove bookmark", {
|
||||||
|
description: "Please try again",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
createNewProject: async (name: string) => {
|
createNewProject: async (name: string) => {
|
||||||
const newProject: TProject = {
|
const newProject: TProject = {
|
||||||
id: generateUUID(),
|
id: generateUUID(),
|
||||||
@@ -50,6 +146,7 @@ export const useProjectStore = create<ProjectStore>((set, get) => ({
|
|||||||
backgroundColor: "#000000",
|
backgroundColor: "#000000",
|
||||||
backgroundType: "color",
|
backgroundType: "color",
|
||||||
blurIntensity: 8,
|
blurIntensity: 8,
|
||||||
|
bookmarks: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
set({ activeProject: newProject });
|
set({ activeProject: newProject });
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ interface TimelineStore {
|
|||||||
pushHistory?: boolean
|
pushHistory?: boolean
|
||||||
) => void;
|
) => void;
|
||||||
toggleTrackMute: (trackId: string) => void;
|
toggleTrackMute: (trackId: string) => void;
|
||||||
|
toggleElementHidden: (trackId: string, elementId: string) => void;
|
||||||
|
|
||||||
// Split operations for elements
|
// Split operations for elements
|
||||||
splitElement: (
|
splitElement: (
|
||||||
@@ -868,6 +869,24 @@ export const useTimelineStore = create<TimelineStore>((set, get) => {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
toggleElementHidden: (trackId, elementId) => {
|
||||||
|
get().pushHistory();
|
||||||
|
updateTracksAndSave(
|
||||||
|
get()._tracks.map((track) =>
|
||||||
|
track.id === trackId
|
||||||
|
? {
|
||||||
|
...track,
|
||||||
|
elements: track.elements.map((element) =>
|
||||||
|
element.id === elementId
|
||||||
|
? { ...element, hidden: !element.hidden }
|
||||||
|
: element
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: track
|
||||||
|
)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
updateTextElement: (trackId, elementId, updates) => {
|
updateTextElement: (trackId, elementId, updates) => {
|
||||||
get().pushHistory();
|
get().pushHistory();
|
||||||
updateTracksAndSave(
|
updateTracksAndSave(
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ export interface TProject {
|
|||||||
backgroundType?: "color" | "blur";
|
backgroundType?: "color" | "blur";
|
||||||
blurIntensity?: number; // in pixels (4, 8, 18)
|
blurIntensity?: number; // in pixels (4, 8, 18)
|
||||||
fps?: number;
|
fps?: number;
|
||||||
|
bookmarks?: number[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ interface BaseTimelineElement {
|
|||||||
startTime: number;
|
startTime: number;
|
||||||
trimStart: number;
|
trimStart: number;
|
||||||
trimEnd: number;
|
trimEnd: number;
|
||||||
|
hidden?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Media element that references MediaStore
|
// Media element that references MediaStore
|
||||||
|
|||||||
Reference in New Issue
Block a user