From 996d44f33d56cde77878b41725d91a2fe7d0af81 Mon Sep 17 00:00:00 2001 From: Xavier Oliveira Date: Thu, 28 May 2026 11:23:57 +0100 Subject: [PATCH] feat: request optimizations --- .../src/components/header/index.tsx | 53 +-- .../src/components/header/styles.module.css | 5 + .../src/components/sidebar/index.tsx | 18 +- .../src/hooks/useGetVideos.ts | 6 +- .../src/hooks/useGetWorkshops.ts | 4 +- .../src/pages/private/admin/_layout.tsx | 76 ++-- .../pages/private/admin/createUser/index.tsx | 13 - .../pages/private/admin/createVideo/index.tsx | 13 - .../private/admin/createWorkshop/index.tsx | 13 - .../pages/private/admin/editVideo/[id].tsx | 3 +- .../pages/private/admin/editWorkshop/[id].tsx | 17 +- .../src/pages/private/admin/user/[id].tsx | 77 +++- .../private/admin/user/styles.module.css | 62 ++- .../src/pages/private/admin/users/index.tsx | 85 +++-- .../src/pages/private/contactos/index.tsx | 4 +- .../src/pages/private/dashboard/index.tsx | 148 ++++---- .../src/pages/private/profile/index.tsx | 354 +++++++++++++----- .../pages/private/profile/styles.module.css | 188 ++++++++++ .../src/pages/private/utilizador/_layout.tsx | 37 -- .../private/utilizador/dashboard/index.tsx | 13 - .../utilizador/dashboard/styles.module.css | 0 .../private/utilizador/styles.module.css | 26 -- .../pages/private/utilizador/videos/index.tsx | 169 --------- .../utilizador/videos/styles.module.css | 95 ----- .../private/utilizador/workshops/index.tsx | 126 ------- .../utilizador/workshops/styles.module.css | 123 ------ .../src/pages/private/videos/index.tsx | 169 +++++---- .../src/pages/private/workshop/[id].tsx | 1 - .../src/pages/private/workshops/index.tsx | 133 ++++--- .../pages/private/workshops/styles.module.css | 4 + .../src/pages/public/login/index.tsx | 3 +- .../src/pages/public/logout/index.tsx | 3 + frontend-plataforma-tutoriais/src/types.tsx | 39 +- .../Http/Controllers/DashboardController.php | 92 +++++ .../app/Http/Controllers/UserController.php | 118 +++++- .../app/Http/Controllers/VideosController.php | 66 ++-- .../Http/Controllers/WorkshopsController.php | 13 +- plataforma-tutorias/routes/api.php | 5 +- 38 files changed, 1258 insertions(+), 1116 deletions(-) delete mode 100644 frontend-plataforma-tutoriais/src/pages/private/utilizador/_layout.tsx delete mode 100644 frontend-plataforma-tutoriais/src/pages/private/utilizador/dashboard/index.tsx delete mode 100644 frontend-plataforma-tutoriais/src/pages/private/utilizador/dashboard/styles.module.css delete mode 100644 frontend-plataforma-tutoriais/src/pages/private/utilizador/styles.module.css delete mode 100644 frontend-plataforma-tutoriais/src/pages/private/utilizador/videos/index.tsx delete mode 100644 frontend-plataforma-tutoriais/src/pages/private/utilizador/videos/styles.module.css delete mode 100644 frontend-plataforma-tutoriais/src/pages/private/utilizador/workshops/index.tsx delete mode 100644 frontend-plataforma-tutoriais/src/pages/private/utilizador/workshops/styles.module.css create mode 100644 plataforma-tutorias/app/Http/Controllers/DashboardController.php diff --git a/frontend-plataforma-tutoriais/src/components/header/index.tsx b/frontend-plataforma-tutoriais/src/components/header/index.tsx index 9526048..4372dee 100644 --- a/frontend-plataforma-tutoriais/src/components/header/index.tsx +++ b/frontend-plataforma-tutoriais/src/components/header/index.tsx @@ -3,17 +3,17 @@ import { LuUser, LuMenu, LuSearch, LuLogOut, LuUsers, LuMail, LuGraduationCap, L import { useEffect, useState } from "react"; import { useNavigate, Link } from "react-router"; import { Button, NavLink, Offcanvas } from "react-bootstrap"; -import type { User, Workshop } from "../../types"; +import type { Workshop } from "../../types"; import type { Video } from "../../types"; import { CgSpinner } from "react-icons/cg"; import { useDebounce } from "../../hooks/useDebounce"; import { useGetVideos } from "../../hooks/useGetVideos"; -import { useGetVideosLength } from "../../hooks/useGetVideosLength"; import { useGetVideosSearch } from "../../hooks/useGetVideosSearch"; import { PiCheckCircleFill } from "react-icons/pi"; import { useGetWorkshopsSearch } from "../../hooks/useGetWorkshopsSearch"; import { imageSkeletonFadeStyle, onImageSkeletonLoad } from "../../utils/imageSkeleton"; import { motion, AnimatePresence } from "framer-motion"; +import { useGetCurrentUser } from "../../hooks/useGetCurrentUser"; export default function Header() { const [showMenu, setShowMenu] = useState(false); @@ -23,31 +23,28 @@ export default function Header() { const [searchCompleted, setSearchCompleted] = useState(false); const [videosSearched, setVideosSearched] = useState([]); const [workshopsSearched, setWorkshopsSearched] = useState([]); - const user = JSON.parse(localStorage.getItem("user") || "{}") as User; - const isAdmin = user.role_id === 1; const debouncedSearch = useDebounce(search, 500); const [showDropdown, setShowDropdown] = useState(false); const { getVideos } = useGetVideos(); - const { getVideosLength } = useGetVideosLength(); const { getVideosSearch } = useGetVideosSearch(); const { getWorkshopsSearch } = useGetWorkshopsSearch(); - const [videosStats, setVideosStats] = useState({ - videos: 0, - videosWatched: 0 - }); - + const { getCurrentUser } = useGetCurrentUser(); + const [role, setRole] = useState(0); + const [videosWatched, setVideosWatched] = useState(0); + const [videosCount, setVideosCount] = useState(0); + const navigate = useNavigate(); - + useEffect(() => { - if (isAdmin) return; - - const fetchProgressVideos = async () => { - const videosLengthData = await getVideosLength(); - if ("videos" in videosLengthData) { - setVideosStats(videosLengthData as { videos: number, videosWatched: number }); - } + const fetchAll = async () => { + const videosWatched = localStorage.getItem("videosWatched"); + setVideosWatched(videosWatched ? parseInt(videosWatched) : 0); + const videosCount = localStorage.getItem("videosCount"); + setVideosCount(videosCount ? parseInt(videosCount) : 0); + const userData = await getCurrentUser(); + setRole(userData.data.role_id); }; - fetchProgressVideos(); + fetchAll(); }, []); const handleCloseMenu = () => setShowMenu(false); @@ -132,7 +129,13 @@ export default function Header() { - Logo + Logo @@ -150,7 +153,7 @@ export default function Header() {
  • Workshops
  • - {isAdmin && ( + {role === 1 && (
  • Utilizadores
  • @@ -161,10 +164,10 @@ export default function Header() { - {!isAdmin && videosStats.videos > 0 && ( + {role !== 1 && videosCount > 0 && (
    Vídeos assistidos - {videosStats.videosWatched}/{videosStats.videos} + {videosWatched}/{videosCount}
    )} @@ -177,11 +180,11 @@ export default function Header() {