({ mode })
| 4 | import axios from 'axios'; |
| 5 | |
| 6 | const Projects = ({ mode }) => { |
| 7 | const VITE_SERVER_PORT = import.meta.env.VITE_SERVER_PORT || "https://bitbox-uxbo.onrender.com"; |
| 8 | |
| 9 | const navigate = useNavigate(); |
| 10 | const [projects, setProjects] = useState([]); // State to store fetched projects |
| 11 | const [loading, setLoading] = useState(true); // State for loading state |
| 12 | const [error, setError] = useState(null); // State for error handling |
| 13 | |
| 14 | useEffect(() => { |
| 15 | // Fetch the data from the API when the component mounts |
| 16 | const fetchProjects = async () => { |
| 17 | try { |
| 18 | const response = await axios.get(`${VITE_SERVER_PORT}/api/showcaseProjects/all-projects`); |
| 19 | setProjects(response.data); // Store the fetched projects in state |
| 20 | setLoading(false); // Set loading to false after data is fetched |
| 21 | } catch (err) { |
| 22 | setError('Error fetching projects'); |
| 23 | setLoading(false); // Set loading to false if an error occurs |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | fetchProjects(); // Call the function to fetch data |
| 28 | }, []); // Empty dependency array means this effect runs once on mount |
| 29 | |
| 30 | const handleButtonClick = () => { |
| 31 | navigate('/uploadProject'); |
| 32 | }; |
| 33 | |
| 34 | if (loading) { |
| 35 | return <div>Loading...</div>; |
| 36 | } |
| 37 | |
| 38 | if (error) { |
| 39 | return <div>{error}</div>; |
| 40 | } |
| 41 | |
| 42 | return ( |
| 43 | <div |
| 44 | className={`container mx-auto p-6 mt-32 ${mode === 'dark' ? 'bg-gray-900 text-white' : 'bg-white text-gray-900'}`} |
| 45 | > |
| 46 | <div className="relative mb-12"> |
| 47 | <h1 className="text-4xl font-extrabold text-center tracking-tight"> |
| 48 | Projects Showcase |
| 49 | </h1> |
| 50 | <button |
| 51 | className={`absolute top-0 right-0 mt-4 mr-6 ${mode === 'dark' |
| 52 | ? 'text-white bg-gray-700 hover:bg-gray-600' |
| 53 | : 'text-gray-900 bg-gray-200 hover:bg-gray-300' |
| 54 | } px-4 py-2 rounded-md text-sm font-semibold transition-colors duration-300`} |
| 55 | onClick={handleButtonClick} |
| 56 | > |
| 57 | Add Project |
| 58 | </button> |
| 59 | </div> |
| 60 | <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8"> |
| 61 | {projects.map((project, index) => ( |
| 62 | <div |
| 63 | key={index} |
nothing calls this directly
no test coverage detected