aboutsummaryrefslogtreecommitdiff
path: root/src/components/GitHubProjects.jsx
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2024-02-08 21:41:36 -0500
committerAndrew Lee <alee14498@protonmail.com>2024-02-08 21:41:36 -0500
commitc1b2794611548ef1fa30055a91926c4074f2f63e (patch)
tree85f218f28d933e310196095a724463afc037d8ad /src/components/GitHubProjects.jsx
parentdc6e36f13c8f94b148f6a3ec8378c66e5fd5034a (diff)
downloadpersonal-website-c1b2794611548ef1fa30055a91926c4074f2f63e.tar.gz
personal-website-c1b2794611548ef1fa30055a91926c4074f2f63e.tar.bz2
personal-website-c1b2794611548ef1fa30055a91926c4074f2f63e.zip
Fixed overflow for mobile, loading in gh projects
Diffstat (limited to 'src/components/GitHubProjects.jsx')
-rw-r--r--src/components/GitHubProjects.jsx42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/components/GitHubProjects.jsx b/src/components/GitHubProjects.jsx
index c4e805b..7497b4a 100644
--- a/src/components/GitHubProjects.jsx
+++ b/src/components/GitHubProjects.jsx
@@ -4,6 +4,7 @@ import { useState, useEffect } from 'preact/hooks';
const GitHubProjects = ({ username, isOrganization }) => {
const [repos, setRepos] = useState([]);
const [error, setError] = useState(null);
+ const [isLoading, setIsLoading] = useState(true);
const [currentPage, setCurrentPage] = useState(1);
const reposPerPage = 10;
@@ -40,6 +41,7 @@ const GitHubProjects = ({ username, isOrganization }) => {
setRepos([]);
}
+ setIsLoading(false);
return allRepos;
};
@@ -47,34 +49,38 @@ const GitHubProjects = ({ username, isOrganization }) => {
fetchRepos().then(setRepos);
}, [username, isOrganization]);
- // Get current repos
const indexOfLastRepo = currentPage * reposPerPage;
const indexOfFirstRepo = indexOfLastRepo - reposPerPage;
const currentRepos = repos.slice(indexOfFirstRepo, indexOfLastRepo);
- // Change page
const nextPage = () => setCurrentPage(currentPage + 1);
const prevPage = () => setCurrentPage(currentPage - 1);
return (
- <div>
- {error && <div class="error">{error}</div>}
- <div class="grid">
- {currentRepos.map((repo) => (
- <article class="card">
- <h1>{repo.name}</h1>
- <p>{repo.description}</p>
- <div class="row">
- <a href={repo.html_url} target="_blank">Repository</a>
- </div>
- </article>
- ))}
- </div>
<div>
- {currentPage > 1 && <button class="button margin" onClick={prevPage}>Previous</button>}
- {currentPage < Math.ceil(repos.length / reposPerPage) && <button class="button margin" onClick={nextPage}>Next</button>}
+ {isLoading ? (
+ <div>Loading...</div>
+ ) : (
+ <>
+ {error && <div class="error">{error}</div>}
+ <div class="grid">
+ {currentRepos.map((repo) => (
+ <article class="card">
+ <h1>{repo.name}</h1>
+ <p>{repo.description}</p>
+ <div class="row">
+ <a href={repo.html_url} target="_blank">Repository</a>
+ </div>
+ </article>
+ ))}
+ </div>
+ <div>
+ {currentPage > 1 && <button class="button margin" onClick={prevPage}>Previous</button>}
+ {currentPage < Math.ceil(repos.length / reposPerPage) && <button class="button margin" onClick={nextPage}>Next</button>}
+ </div>
+ </>
+ )}
</div>
- </div>
);
};