From 64cd7fc83d43a0ad7db1b51214291736bd245b44 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Fri, 28 Jun 2024 20:31:02 -0400 Subject: Guestbook overhaul; Comments; New post; Updated packages --- src/components/GitHubProjects.jsx | 86 --------------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 src/components/GitHubProjects.jsx (limited to 'src/components/GitHubProjects.jsx') diff --git a/src/components/GitHubProjects.jsx b/src/components/GitHubProjects.jsx deleted file mode 100644 index 33b4e64..0000000 --- a/src/components/GitHubProjects.jsx +++ /dev/null @@ -1,86 +0,0 @@ -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; - - const fetchRepos = async (page = 1, allRepos = []) => { - const baseUrl = 'https://api.github.com'; - const url = isOrganization - ? `${baseUrl}/orgs/${username}/repos?page=${page}&per_page=100` - : `${baseUrl}/users/${username}/repos?page=${page}&per_page=100`; - - try { - const response = await fetch(url); - const data = await response.json(); - - if (response.ok) { - if (Array.isArray(data)) { - allRepos = allRepos.concat(data.filter(repo => !repo.fork)); - // If the data length is 100, there might be more repositories to fetch - if (data.length === 100) { - return fetchRepos(page + 1, allRepos); - } - } else { - console.error('Unexpected data format:', data); - setError('Unexpected data format'); - setRepos([]); - } - } else { - console.error('API error:', data); - setError(data.message); - setRepos([]); - } - } catch (err) { - console.error('Failed to fetch projects:', err); - setError(err.message); - setRepos([]); - } - - setIsLoading(false); - return allRepos; - }; - - useEffect(() => { - fetchRepos().then(setRepos); - }, [username, isOrganization]); - - const indexOfLastRepo = currentPage * reposPerPage; - const indexOfFirstRepo = indexOfLastRepo - reposPerPage; - const currentRepos = repos.slice(indexOfFirstRepo, indexOfLastRepo); - - const nextPage = () => setCurrentPage(currentPage + 1); - const prevPage = () => setCurrentPage(currentPage - 1); - - return ( -
- {isLoading ? ( -
Loading...
- ) : ( - <> - {error &&
{error}
} -
- {currentRepos.map((repo) => ( -
-

{repo.name}

-

{repo.description}

- -
- ))} -
-
- {currentPage > 1 && } - {currentPage < Math.ceil(repos.length / reposPerPage) && } -
- - )} -
- ); -}; - -export default GitHubProjects; -- cgit v1.2.3