diff --git a/src/App.jsx b/src/App.jsx index f3deba0..8624d12 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,10 +1,13 @@ -import React from 'react'; -import Navbar from './components/Navbar'; +import React from "react"; +import Navbar from "./components/Navbar"; // TODO: Import react router dom here +import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; +import Home from "./pages/Home"; +import Projects from "./pages/Projects"; -import Footer from './components/Footer'; -import './styles/App.css'; +import Footer from "./components/Footer"; +import "./styles/App.css"; function App() { return ( @@ -12,8 +15,12 @@ function App() {
- {/* TODO: Add react router dom routes here */} - + {/* TODO: Add react router dom routes here */} + + + } /> + } /> +
@@ -21,4 +28,4 @@ function App() { ); } -export default App; \ No newline at end of file +export default App; diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index c371cae..849cd00 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -1,10 +1,11 @@ -import React from 'react'; +import React from "react"; +import { Link } from "react-router-dom"; // TODO: Import LINK from react router dom components -import { useLocation } from 'react-router-dom' +import { useLocation } from "react-router-dom"; -import { Github } from 'lucide-react'; -import '../styles/Navbar.css'; +import { Github } from "lucide-react"; +import "../styles/Navbar.css"; const Navbar = () => { const location = useLocation(); @@ -19,10 +20,16 @@ const Navbar = () => { diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index aaac8db..fd563ac 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -1,11 +1,20 @@ -import React, { useState, useEffect } from 'react'; -import { Link } from 'react-router-dom'; +import React, { useState, useEffect } from "react"; +import { Link } from "react-router-dom"; // TODO: Import axios here -import moment from 'moment'; -import { Users, Star, GitBranch, MapPin, Calendar, ExternalLink } from 'lucide-react'; -import '../styles/Home.css'; +import axios from "axios"; + +import moment from "moment"; +import { + Users, + Star, + GitBranch, + MapPin, + Calendar, + ExternalLink, +} from "lucide-react"; +import "../styles/Home.css"; const Home = () => { const [user, setUser] = useState(null); @@ -13,9 +22,33 @@ const Home = () => { const [error, setError] = useState(null); // TODO: Fetch user data from GitHub API using axios and useEffect and set the user state, also handle the loading and error states - // API: https://api.github.com/users/YOUR_USERNAME + // API: https://api.github.com/users/YOUR_USERNAME + + useEffect(() => { + // Create an async function that calls the API\ + const fetchUser = async () => { + try { + setLoading(true); + await axios + .get("https://api.github.com/users/zacimka") + .then((response) => { + setUser(response.data); + setLoading(false); + }) + .catch((err) => { + setError(err.message); + setLoading(false); + }); + } catch (error) { + console.log(error); + setLoading(false); + } + }; + // Execute the function + fetchUser(); + }, []); if (loading) { return
Loading profile data...
; @@ -32,10 +65,10 @@ const Home = () => {
- {`${user.name}'s
@@ -49,13 +82,15 @@ const Home = () => { )}

- Joined on {moment(user.created_at).format('MMMM D, YYYY')} + + Joined on {moment(user.created_at).format("MMMM D, YYYY")} +

- +
-

{user.bio || 'No bio available'}

+

{user.bio || "No bio available"}

@@ -91,10 +126,16 @@ const Home = () => { )} {user.blog && (

- Website: - + Website: + {user.blog}

@@ -103,10 +144,10 @@ const Home = () => { )}
- Visit GitHub @@ -122,4 +163,4 @@ const Home = () => { ); }; -export default Home; \ No newline at end of file +export default Home; diff --git a/src/pages/Projects.jsx b/src/pages/Projects.jsx index def4d8a..2e6a8fa 100644 --- a/src/pages/Projects.jsx +++ b/src/pages/Projects.jsx @@ -1,20 +1,47 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect } from "react"; // TODO: Import axios here +import axios from "axios"; -import ProjectCard from '../components/ProjectCard'; -import '../styles/Projects.css'; +import ProjectCard from "../components/ProjectCard"; +import "../styles/Projects.css"; const Projects = () => { const [repos, setRepos] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); - // TODO: Fetch repositories from GitHub API using axios and useEffect and set the repos state, also handle the loading and error states - // API: https://api.github.com/users/YOUR_GITHUB_USERNAME/repos?per_page=10&sort=updated + // TODO: Fetch repositories from GitHub API using axios and useEffect and set the repos state, also handle the loading and error states + // API: https://api.github.com/users/YOUR_GITHUB_USERNAME/repos?per_page=10&sort=updated + useEffect(() => { + // Create an async function that calls the API\ + const fetchRepositories = async () => { + try { + setLoading(true); + await axios + .get( + "https://api.github.com/users/zacimka/repos?per_page=10&sort=updated" + ) + .then((response) => { + setRepos(response.data); + setLoading(false); + }) + .catch((err) => { + setError(err.message); + setLoading(false); + }); + } catch (error) { + console.log(error); + setLoading(false); + } + }; + + // Execute the function + fetchRepositories(); + }, []); if (loading) { return
Loading repositories...
; @@ -28,9 +55,7 @@ const Projects = () => {

GitHub Projects

-

- My latest GitHub repositories. -

+

My latest GitHub repositories.

@@ -59,4 +84,4 @@ const Projects = () => { ); }; -export default Projects; \ No newline at end of file +export default Projects;