From c1b2794611548ef1fa30055a91926c4074f2f63e Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 8 Feb 2024 21:41:36 -0500 Subject: Fixed overflow for mobile, loading in gh projects --- src/components/GitHubProjects.jsx | 42 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'src/components/GitHubProjects.jsx') 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 ( -
- {error &&
{error}
} -
- {currentRepos.map((repo) => ( -
-

{repo.name}

-

{repo.description}

- -
- ))} -
- {currentPage > 1 && } - {currentPage < Math.ceil(repos.length / reposPerPage) && } + {isLoading ? ( +
Loading...
+ ) : ( + <> + {error &&
{error}
} +
+ {currentRepos.map((repo) => ( +
+

{repo.name}

+

{repo.description}

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