diff --git a/frontend/src/pages/VideoPlayer.tsx b/frontend/src/pages/VideoPlayer.tsx index d3ee89c..bc055dc 100644 --- a/frontend/src/pages/VideoPlayer.tsx +++ b/frontend/src/pages/VideoPlayer.tsx @@ -338,7 +338,12 @@ const VideoPlayer: React.FC = () => { const executeDelete = async () => { if (!id) return; - await deleteMutation.mutateAsync(id); + isDeletingRef.current = true; + try { + await deleteMutation.mutateAsync(id); + } catch (error) { + isDeletingRef.current = false; + } }; const handleDelete = () => { @@ -531,6 +536,7 @@ const VideoPlayer: React.FC = () => { const [hasViewed, setHasViewed] = useState(false); const lastProgressSave = useRef(0); const currentTimeRef = useRef(0); + const isDeletingRef = useRef(false); // Reset hasViewed when video changes useEffect(() => { @@ -541,7 +547,7 @@ const VideoPlayer: React.FC = () => { // Save progress on unmount useEffect(() => { return () => { - if (id && currentTimeRef.current > 0) { + if (id && currentTimeRef.current > 0 && !isDeletingRef.current) { axios.put(`${API_URL}/videos/${id}/progress`, { progress: Math.floor(currentTimeRef.current) }) .catch(err => console.error('Error saving progress on unmount:', err)); }