diff --git a/src/Components/DashboardPage/TechnicianButtons.tsx b/src/Components/DashboardPage/TechnicianButtons.tsx index 793c782..a9aa1a4 100644 --- a/src/Components/DashboardPage/TechnicianButtons.tsx +++ b/src/Components/DashboardPage/TechnicianButtons.tsx @@ -1,6 +1,4 @@ -import { useQueries } from "@tanstack/react-query"; import styles from "../../styles"; -import { EquipmentsAPI, EquipmentInstancesAPI, UserAPI } from "../API/API"; import { useNavigate } from "react-router-dom"; import { Button } from "@mui/material"; import FormatListBulletedIcon from "@mui/icons-material/FormatListBulleted"; @@ -18,22 +16,6 @@ export default function TechnicianButtons() { const [addSKUmodalOpen, SetAddSKUModalOpen] = useState(false); const [additemmodalOpen, SetAddItemModalOpen] = useState(false); const navigate = useNavigate(); - const queries = useQueries({ - queries: [ - { - queryKey: ["equipments"], - queryFn: EquipmentsAPI, - }, - { - queryKey: ["equipment_instances"], - queryFn: EquipmentInstancesAPI, - }, - { - queryKey: ["user"], - queryFn: UserAPI, - }, - ], - }); return ( <>

{ diff --git a/src/Components/DashboardPage/TechnicianWidgets.tsx b/src/Components/DashboardPage/TechnicianWidgets.tsx index ee9f39e..15b132c 100644 --- a/src/Components/DashboardPage/TechnicianWidgets.tsx +++ b/src/Components/DashboardPage/TechnicianWidgets.tsx @@ -1,6 +1,7 @@ import { useQueries } from "@tanstack/react-query"; import styles from "../../styles"; import { EquipmentsAPI, EquipmentInstancesAPI, UserAPI } from "../API/API"; +import CircularProgress from "@mui/material/CircularProgress"; export default function TechnicianWidgets() { const queries = useQueries({ @@ -19,6 +20,22 @@ export default function TechnicianWidgets() { }, ], }); + const isLoading = queries.some((result) => result.isLoading); + if (isLoading) { + return ( + <> + +

+ Loading +

+ + ); + } return (
+ +

+ Loading +

+ + ); + } if (props.allow_only === "Teacher") { if (user.data && user.data.is_teacher) { return <>{props.children}; diff --git a/src/Pages/DashboardPage/DashboardPage.tsx b/src/Pages/DashboardPage/DashboardPage.tsx index f5b89fd..1c77d0e 100644 --- a/src/Pages/DashboardPage/DashboardPage.tsx +++ b/src/Pages/DashboardPage/DashboardPage.tsx @@ -1,62 +1,10 @@ import Header from "../../Components/Header/Header"; import styles from "../../styles"; -import { useQueries } from "@tanstack/react-query"; -import { - EquipmentsAPI, - EquipmentInstancesAPI, - UserAPI, -} from "../../Components/API/API"; import RestrictedComponent from "../../Components/RestrictedComponent/RestrictedComponent"; import TechnicianWidgets from "../../Components/DashboardPage/TechnicianWidgets"; import TechnicianButtons from "../../Components/DashboardPage/TechnicianButtons"; import TechnicianLogs from "../../Components/DashboardPage/TechnicianLogs"; -import CircularProgress from "@mui/material/CircularProgress/CircularProgress"; export default function Dashboard() { - const queries = useQueries({ - queries: [ - { - queryKey: ["equipments"], - queryFn: EquipmentsAPI, - }, - { - queryKey: ["equipment_instances"], - queryFn: EquipmentInstancesAPI, - }, - { - queryKey: ["user"], - queryFn: UserAPI, - }, - ], - }); - const isLoading = queries.some((result) => result.isLoading); - - if (isLoading) { - return ( -
-
-
- -

- Loading -

-
-
- ); - } return (