Spaces:
Sleeping
Sleeping
Tristan Yu commited on
Commit ·
eb3b755
1
Parent(s): 726a398
Add MongoDB storage for timecodes and robust video playback handling for time clashes
Browse files159 unmodified lines160161162163164165166167168169170171315 unmodified lines48748848949049149249340 unmodified lines534535536537538539159 unmodified linesconst currentTime = videoRef.currentTime;setCurrentTime(formatTime(currentTime));// Find current segment based on video time with precise timingconst foundSegment = subtitleSegments.find(segment => {const startTime = parseTimeToSeconds(segment.startTime);const endTime = parseTimeToSeconds(segment.endTime);return currentTime >= startTime && currentTime < endTime; // Use < instead of <= for precise timing});// Clear subtitle if no segment is found (outside of subtitle timecodes)if (!foundSegment) {315 unmodified lines}};const saveTimecodes = () => {if (editingSegment) {// Validate time formatconst timeFormat = /^\d{2}:\d{2}:\d{2},\d{3}$/;40 unmodified lines// Update state with new timecodessetSubtitleSegments(updatedSegments);localStorage.setItem('subtitleSegments', JSON.stringify(updatedSegments));console.log('Updated timecodes for segment:', editingSegment, 'to:', editStartTime, '-', editEndTime, 'duration:', duration);setEditingTimecodes(false);159 unmodified lines160161162163164165166167168169170171172173315 unmodified lines48949049149249349449549649749849950050150250350450550650750850951051151251351451551651751840 unmodified lines559560561562563564565566567568159 unmodified linesconst currentTime = videoRef.currentTime;setCurrentTime(formatTime(currentTime));// Find current segment based on video time with robust clash handlingconst foundSegment = subtitleSegments.filter(segment => {const startTime = parseTimeToSeconds(segment.startTime);const endTime = parseTimeToSeconds(segment.endTime);return currentTime >= startTime && currentTime < endTime;}).sort((a, b) => parseTimeToSeconds(a.startTime) - parseTimeToSeconds(b.startTime))[0]; // Get first segment if multiple matches// Clear subtitle if no segment is found (outside of subtitle timecodes)if (!foundSegment) {315 unmodified lines}};// Save timecodes to MongoDBconst saveTimecodesToDatabase = async (updatedSegments: SubtitleSegment[]) => {try {const user = localStorage.getItem('user');const token = localStorage.getItem('token');if (token && user) {const userData = JSON.parse(user);const timecodeData = {weekNumber: 2,segments: updatedSegments,updatedBy: userData._id,updatedAt: new Date().toISOString()};await api.post('/timecodes', timecodeData);console.log('Timecodes saved to database');}} catch (error) {console.error('Failed to save timecodes to database:', error);}};const saveTimecodes = async () => {if (editingSegment) {// Validate time formatconst timeFormat = /^\d{2}:\d{2}:\d{2},\d{3}$/;40 unmodified lines// Update state with new timecodessetSubtitleSegments(updatedSegments);localStorage.setItem('subtitleSegments', JSON.stringify(updatedSegments));// Save to MongoDBawait saveTimecodesToDatabase(updatedSegments);console.log('Updated timecodes for segment:', editingSegment, 'to:', editStartTime, '-', editEndTime, 'duration:', duration);setEditingTimecodes(false);
src/pages/WeeklyPractice.tsx+36-7