feat: paginate workshops and videos pages
This commit is contained in:
29
frontend-plataforma-tutoriais/src/hooks/useVideoWatch.ts
Normal file
29
frontend-plataforma-tutoriais/src/hooks/useVideoWatch.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useState, useRef } from "react";
|
||||
|
||||
export function useVideoWatch(videoId: number, initialWatched: boolean) {
|
||||
const [watched, setWatched] = useState(initialWatched);
|
||||
const alreadySent = useRef(false);
|
||||
|
||||
const markAsWatched = async () => {
|
||||
if (alreadySent.current || watched ) return;
|
||||
|
||||
alreadySent.current = true;
|
||||
|
||||
try {
|
||||
await fetch(`http://127.0.0.1:8000/api/video/${videoId}/watch`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${localStorage.getItem("token")}`
|
||||
},
|
||||
});
|
||||
|
||||
setWatched(true);
|
||||
} catch (error) {
|
||||
console.error("Erro ao marcar o vídeo como assistido: ", error);
|
||||
alreadySent.current = false;
|
||||
}
|
||||
}
|
||||
|
||||
return { watched, markAsWatched };
|
||||
}
|
||||
Reference in New Issue
Block a user