Skip to content
Open

done #36

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
<title>GitHub Project</title>
</head>
<body>
<div id="root"></div>
Expand Down
16 changes: 12 additions & 4 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import React from 'react';
import Navbar from './components/Navbar';
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import Home from "./pages/Home";
import Projects from "./pages/Projects";

// TODO: Import react router dom here
// TODO: Import react router dom here = done

import Footer from './components/Footer';
import './styles/App.css';

function App() {
return (

<Router>
<div className="app">
<Navbar />
<Navbar />
<main className="main-content">
{/* TODO: Add react router dom routes here */}

<Routes>
<Route path="/" element={<Home />} />
<Route path="/Projects" element={<Projects />} />

</Routes>=
</main>

<Footer />
</div>
</Router>
Expand Down
3 changes: 3 additions & 0 deletions src/components/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import {Link} from "react-router-dom";

// TODO: Import LINK from react router dom components
import { useLocation } from 'react-router-dom'
Expand All @@ -19,9 +20,11 @@ const Navbar = () => {

<ul className="navbar-menu">
<li className="navbar-item">
<Link to="/" >Home</Link>
{/* TODO: Add the home route here */}
</li>
<li className="navbar-item">
<Link to="/Projects">Projects</Link>
{/* TODO: Add the projects route here */}
</li>
</ul>
Expand Down
23 changes: 20 additions & 3 deletions src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import axios from "axios";

// TODO: Import axios here
// TODO: Import axios here = done

import moment from 'moment';
import { Users, Star, GitBranch, MapPin, Calendar, ExternalLink } from 'lucide-react';
Expand All @@ -13,9 +14,25 @@ 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/safiacodes

useEffect (() => {
const fetchUser = async () => {
try {
setLoading(true);
await axios
.get ("https://api.github.com/users/safiyacodes")
.then ((response)=> {
setUser(response.data);
setLoading(false);
});
} catch (error){
console.log(error);
setLoading(false);
}
};
fetchUser();
},[] );

if (loading) {
return <div className="loading">Loading profile data...</div>;
Expand Down
29 changes: 22 additions & 7 deletions src/pages/Projects.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import React, { useState, useEffect } from 'react';

// TODO: Import axios here


import axios from 'axios';
import ProjectCard from '../components/ProjectCard';
import '../styles/Projects.css';

Expand All @@ -11,10 +8,28 @@ const Projects = () => {
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/safiacodes/repos?per_page=10&sort=updated

useEffect (() => {
const fetchUserProjects = async () => {
try {
setLoading(true);
setError(null);
const response = await axios.get("https://api.github.com/users/safiyacodes/repos?per_page=10&sort=updated");

setRepos(response.data || []);
}
catch (error){
setError("Failed to load user. Please try again.");
console.error(error);
} finally {
setLoading (false);
}
};
fetchUserProjects();
}, []);

if (loading) {
return <div className="loading">Loading repositories...</div>;
Expand Down