diff --git a/frontend-tools/chapters-editor/client/src/components/TimelineControls.tsx b/frontend-tools/chapters-editor/client/src/components/TimelineControls.tsx index 7ae9bde2..f7e79066 100644 --- a/frontend-tools/chapters-editor/client/src/components/TimelineControls.tsx +++ b/frontend-tools/chapters-editor/client/src/components/TimelineControls.tsx @@ -3947,11 +3947,11 @@ const TimelineControls = ({ @@ -3974,7 +3974,7 @@ const TimelineControls = ({ className="modal-button modal-button-primary" onClick={handleSaveChaptersConfirm} > - {clipSegments.filter((s) => s.chapterTitle && s.chapterTitle.trim()).length === 0 + {clipSegments.length === 0 ? 'Clear Chapters' : 'Save Chapters'} @@ -3982,14 +3982,9 @@ const TimelineControls = ({ } >

- {(() => { - const chaptersWithTitles = clipSegments.filter((s) => s.chapterTitle && s.chapterTitle.trim()).length; - if (chaptersWithTitles === 0) { - return "Are you sure you want to clear all chapters? This will remove all existing chapters from the database."; - } else { - return `Are you sure you want to save the chapters? This will save ${chaptersWithTitles} chapters to the database.`; - } - })()} + {clipSegments.length === 0 + ? "Are you sure you want to clear all chapters? This will remove all existing chapters from the database." + : `Are you sure you want to save the chapters? This will save ${clipSegments.filter((s) => s.chapterTitle && s.chapterTitle.trim()).length} chapters to the database.`}

diff --git a/frontend-tools/chapters-editor/client/src/hooks/useVideoChapters.tsx b/frontend-tools/chapters-editor/client/src/hooks/useVideoChapters.tsx index 63befaa3..eedd186f 100644 --- a/frontend-tools/chapters-editor/client/src/hooks/useVideoChapters.tsx +++ b/frontend-tools/chapters-editor/client/src/hooks/useVideoChapters.tsx @@ -147,8 +147,15 @@ const useVideoChapters = () => { initialSegments.push(segment); } } else { - // Start with empty state - no default segment - initialSegments = []; + // Create a default segment that spans the entire video on first load + const initialSegment: Segment = { + id: 1, + chapterTitle: '', + startTime: 0, + endTime: video.duration, + }; + + initialSegments = [initialSegment]; } // Initialize history state with the segments @@ -267,17 +274,24 @@ const useVideoChapters = () => { // Check if we now have duration and initialize if needed if (video.duration > 0 && clipSegments.length === 0) { - logger.debug('Safari: Successfully initialized metadata with empty state'); + logger.debug('Safari: Successfully initialized metadata, creating default segment'); + const defaultSegment: Segment = { + id: 1, + chapterTitle: '', + startTime: 0, + endTime: video.duration, + }; + setDuration(video.duration); setTrimEnd(video.duration); - setClipSegments([]); + setClipSegments([defaultSegment]); const initialState: EditorState = { trimStart: 0, trimEnd: video.duration, splitPoints: [], - clipSegments: [], + clipSegments: [defaultSegment], }; setHistory([initialState]);