import { useState } from "react"; import Pagination from "@mui/material/Pagination"; import CircularProgress from "@mui/material/CircularProgress"; import Alert from "@mui/material/Alert"; import Box from "@mui/material/Box"; import { useGetTests } from "../../hooks/Tests/useGetTests"; import Container from "../../components/shared/Container"; import TestListCard from "../../components/TestListCard/TestListCard"; import { FormControl, InputLabel, MenuItem, Select, Typography, type SelectChangeEvent, } from "@mui/material"; import { useCategories } from "../../hooks/Question/useCategories"; const TestsPage = () => { const [currentPage, setCurrentPage] = useState(1); const [selectedCategory, setSelectedCategory] = useState( "all" ); const { data: categories } = useCategories(); const { data, isLoading, isError } = useGetTests({ categoryId: selectedCategory === "all" ? undefined : selectedCategory, page: currentPage, }); const handleCategoryChange = (event: SelectChangeEvent) => { const value = event.target.value; setSelectedCategory(value === "all" ? "all" : Number(value)); setCurrentPage(1); }; if (isLoading) return ; if (isError) return Failed to load tests; return ( Curated tests Category {isLoading ? (
Loading tests...
) : isError ? (
Failed to load tests
) : ( data?.data.map((test) => ) )} {data?.meta?.last_page && data.meta.last_page > 1 && ( setCurrentPage(value)} sx={{ mt: 3, mb: 3, display: "flex", justifyContent: "center" }} /> )}
); }; export default TestsPage;