From 387e56330580e0ef379aa626dd55e84f2665893c Mon Sep 17 00:00:00 2001 From: Ange230700 Date: Wed, 7 Feb 2024 14:53:49 +0100 Subject: [PATCH] last commit --- backend/src/controllers/filmControllers.js | 6 -- backend/src/models/CategorieParFilmManager.js | 2 - backend/src/models/FilmManager.js | 2 +- backend/src/services/multer.js | 5 -- frontend/src/components/CategoryDisplay.jsx | 4 +- frontend/src/pages/AddVideos.jsx | 66 ++++++++------ frontend/src/pages/EditSection.jsx | 4 +- frontend/src/pages/EditVideo.jsx | 88 +++++++++---------- frontend/src/pages/MoviePlayer.jsx | 22 ++--- frontend/src/sass/_addVideos.scss | 6 ++ frontend/src/sass/_editVideo.scss | 44 +++++++++- 11 files changed, 147 insertions(+), 102 deletions(-) diff --git a/backend/src/controllers/filmControllers.js b/backend/src/controllers/filmControllers.js index 2c90141..499afeb 100644 --- a/backend/src/controllers/filmControllers.js +++ b/backend/src/controllers/filmControllers.js @@ -28,14 +28,10 @@ const edit = async (req, res, next) => { const { id } = req.params; req.body.id = id; - console.warn("req.body.cover in edit", req.body.cover); - if (req.files.cover && req.files.cover[0]) { req.body.cover_filename = req.files.cover[0].filename; } - console.warn("req.body.miniature in edit", req.body.miniature); - if (req.files.miniature && req.files.miniature[0]) { req.body.miniature_filename = req.files.miniature[0].filename; } @@ -58,8 +54,6 @@ const edit = async (req, res, next) => { }; const add = async (req, res, next) => { - console.warn("req.body.images in add", req.body.images); - if (req.files.cover && req.files.cover[0]) { req.body.cover_filename = req.files.cover[0].filename; } diff --git a/backend/src/models/CategorieParFilmManager.js b/backend/src/models/CategorieParFilmManager.js index cfe0f46..5cfd5f0 100644 --- a/backend/src/models/CategorieParFilmManager.js +++ b/backend/src/models/CategorieParFilmManager.js @@ -20,8 +20,6 @@ class CategorieParFilmManager extends AbstractManager { arrDep.push(filmId, catId, unique_key); }); - // console.log("querySQL =>", querySQL); - // console.log("arrDep =>", arrDep); // Execute the SQL INSERT query to add a new categorieParFilm to the "categorieParFilm" table const result = await this.database.query(`${querySQL};`, arrDep); diff --git a/backend/src/models/FilmManager.js b/backend/src/models/FilmManager.js index b4ff0ad..1a77bac 100644 --- a/backend/src/models/FilmManager.js +++ b/backend/src/models/FilmManager.js @@ -61,7 +61,7 @@ class FilmManager extends AbstractManager { IsAvailable, }) { const [result] = await this.database.query( - `update ${this.table} SET miniature_filename=?, cover_filename=?, title=?, videoUrl=?, videoFilename=?, duration=?, year=?, description=?, IsAvailable=? where id=?`, + `update ${this.table} SET miniature_filename = COALESCE(?, miniature_filename), cover_filename = COALESCE(?, cover_filename), title = COALESCE(?, title), videoUrl = COALESCE(?, videoUrl), videoFilename = COALESCE(?, videoFilename), duration = COALESCE(?, duration), year = COALESCE(?, year), description = COALESCE(?, description), IsAvailable = COALESCE(?, IsAvailable) where id=?`, [ miniature_filename, cover_filename, diff --git a/backend/src/services/multer.js b/backend/src/services/multer.js index 8ac0124..dd50f08 100644 --- a/backend/src/services/multer.js +++ b/backend/src/services/multer.js @@ -21,8 +21,6 @@ const imagesStorage = multer.diskStorage({ if (req.body.miniature) { req.body.miniature = name; } - - console.warn("req.body.images in imagesStorage", req.body.images); cb(null, name); }, }); @@ -44,9 +42,6 @@ const imagesStorage2 = multer.diskStorage({ if (req.body.miniature) { req.body.miniature = name; } - - console.warn("req.body.cover in imagesStorage", req.body.cover); - console.warn("req.body.miniature in imagesStorage", req.body.miniature); cb(null, name); }, }); diff --git a/frontend/src/components/CategoryDisplay.jsx b/frontend/src/components/CategoryDisplay.jsx index 1943ba3..383801e 100644 --- a/frontend/src/components/CategoryDisplay.jsx +++ b/frontend/src/components/CategoryDisplay.jsx @@ -77,11 +77,11 @@ function CategoryDisplay({ categorie, getCategories }) { toast.success("Category deleted"); getCategories(); } else { - toast.error("An error occurred"); + toast.error("Error deleting category"); } } catch (error) { console.error(error); - toast.error("An error occurred"); + toast.error("Error deleting category"); } finally { setIsDeleting(false); } diff --git a/frontend/src/pages/AddVideos.jsx b/frontend/src/pages/AddVideos.jsx index 4239432..2c5beae 100644 --- a/frontend/src/pages/AddVideos.jsx +++ b/frontend/src/pages/AddVideos.jsx @@ -11,7 +11,6 @@ function AddVideos() { const [file, setFile] = useState(undefined); const [previewFile, setPreviewFile] = useState(); const [previewCover, setPreviewCover] = useState(); - const [previewVideo, setPreviewVideo] = useState(); const [cover, setCover] = useState(undefined); const [description, setDescription] = useState(""); const [title, setTitle] = useState(""); @@ -69,7 +68,7 @@ function AddVideos() { duration || isAvailable) === (undefined || "" || false) ) { - toast.error("champ manquant"); + toast.error("Missing fields"); } else if (isAvailable === "utilisateur") { setIsAvailable(true); } else if (isAvailable === "visiteur") { @@ -133,10 +132,6 @@ function AddVideos() { const objectUrlCover = URL.createObjectURL(cover); setPreviewCover(objectUrlCover); } - if (videoFilename) { - const objectUrlVideo = URL.createObjectURL(videoFilename); - setPreviewVideo(objectUrlVideo); - } }, [file, cover]); return ( @@ -156,14 +151,43 @@ function AddVideos() {
-
- setVideoUrl(e.target.value)} - placeholder="lien de la video" - /> +
+
+ setVideoUrl(e.target.value)} + placeholder="video url" + /> +
+

+ Or +

+
+
+

Add a video file

+
+ setVideoFilename(e.target.files[0])} + type="file" + accept="video/*" + /> +
@@ -193,20 +217,6 @@ function AddVideos() { accept="image/*" />
-
-
-

Add a video file

-
- {previewVideo && videoFile} -
-
- setVideoFilename(e.target.files[0])} - type="file" - accept="video/*" - /> -
{ console.error(error); - toast.error("An error occurred"); + toast.error("Error updating category name"); }); } @@ -127,7 +127,7 @@ function EditSection() { } } catch (error) { console.error(error); - toast.error("An error occurred"); + toast.error("Error saving changes"); } finally { setIsSaving(false); } diff --git a/frontend/src/pages/EditVideo.jsx b/frontend/src/pages/EditVideo.jsx index 3addd8f..6a1db0b 100644 --- a/frontend/src/pages/EditVideo.jsx +++ b/frontend/src/pages/EditVideo.jsx @@ -4,7 +4,7 @@ import toast from "react-hot-toast"; import axios from "axios"; import { useMovies } from "../contexts/MovieContext"; -// § The user should be able to decide if he wanna upload a video or use a youtube link to edit a video. +// § When uploading a video, I would like to see a preview of the video being a snapshot of the video. How can I do that? function EditVideo() { const { movieId } = useParams(); @@ -36,7 +36,7 @@ function EditVideo() { `${import.meta.env.VITE_BACKEND_URL}/api/categoriesParFilm/${uniqueKey}` ); if (response.status === 200) { - toast.success("Success"); + toast.success("Success deleting category"); setCategorieVideo((prevCategorieVideo) => prevCategorieVideo.filter( (categorie) => categorie.unique_key !== uniqueKey @@ -44,7 +44,7 @@ function EditVideo() { ); } } catch (e) { - console.error("Error deleting", e); + console.error("Error deleting category", e); } }; @@ -147,7 +147,7 @@ function EditVideo() { } ); if (response.status === 201) { - toast.success("Success"); + toast.success("Success adding category"); fetchCategorieVideo(); } } catch (e) { @@ -178,7 +178,7 @@ function EditVideo() { } ); if (response.status === 204) { - toast.success("Success"); + toast.success("Success editing video"); if (selectedFile) URL.revokeObjectURL(selectedFile); if (selectedFile2) URL.revokeObjectURL(selectedFile2); if (selectedFile3) URL.revokeObjectURL(selectedFile3); @@ -195,7 +195,7 @@ function EditVideo() { `${import.meta.env.VITE_BACKEND_URL}/api/films/${movieId}` ); if (response.status === 200) { - toast.success("Success"); + toast.success("Success deleting video"); navigate("/"); } } catch (e) { @@ -233,21 +233,6 @@ function EditVideo() { return video?.miniature_url; }; - const imageSrc3 = () => { - if (selectedFile3) { - return URL.createObjectURL(selectedFile3); - } - if (video.videoFilename) { - return ( - video.videoFilename && - `${import.meta.env.VITE_BACKEND_URL}/assets/images/${ - video?.videoFilename - }` - ); - } - return video?.videoUrl; - }; - useEffect(() => { return () => { if (selectedFile) { @@ -298,15 +283,6 @@ function EditVideo() { accept="image/*" />
-
- videoFilename - -
- - +
+ +

+ Or +

+ +