From dc6e36f13c8f94b148f6a3ec8378c66e5fd5034a Mon Sep 17 00:00:00 2001
From: Andrew Lee <alee14498@protonmail.com>
Date: Thu, 8 Feb 2024 14:29:38 -0500
Subject: Added personal repos; RSS icon on blog

---
 src/components/GitHubProjects.jsx | 62 +++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 28 deletions(-)

(limited to 'src/components/GitHubProjects.jsx')

diff --git a/src/components/GitHubProjects.jsx b/src/components/GitHubProjects.jsx
index b54dc9f..c4e805b 100644
--- a/src/components/GitHubProjects.jsx
+++ b/src/components/GitHubProjects.jsx
@@ -7,39 +7,45 @@ const GitHubProjects = ({ username, isOrganization }) => {
   const [currentPage, setCurrentPage] = useState(1);
   const reposPerPage = 10;
 
-  useEffect(() => {
-    const fetchRepos = async () => {
-      const baseUrl = 'https://api.github.com';
-      const url = isOrganization
-        ? `${baseUrl}/orgs/${username}/repos`
-        : `${baseUrl}/users/${username}/repos`;
-  
-      try {
-        const response = await fetch(url);
-        const data = await response.json();
-  
-        if (response.ok) {
-          if (Array.isArray(data)) {
-            setRepos(data.filter(repo => !repo.fork));
-          } else {
-            console.error('Unexpected data format:', data);
-            setError('Unexpected data format');
-            setRepos([]);
+  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('API error:', data);
-          setError(data.message);
+          console.error('Unexpected data format:', data);
+          setError('Unexpected data format');
           setRepos([]);
         }
-      } catch (err) {
-        console.error('Failed to fetch projects:', err);
-        setError(err.message);
+      } else {
+        console.error('API error:', data);
+        setError(data.message);
         setRepos([]);
       }
-    };
-  
-    fetchRepos();
-  }, [username, isOrganization]); // Don't forget to include dependencies
+    } catch (err) {
+      console.error('Failed to fetch projects:', err);
+      setError(err.message);
+      setRepos([]);
+    }
+
+    return allRepos;
+  };
+
+  useEffect(() => {
+    fetchRepos().then(setRepos);
+  }, [username, isOrganization]);
 
   // Get current repos
   const indexOfLastRepo = currentPage * reposPerPage;
@@ -72,4 +78,4 @@ const GitHubProjects = ({ username, isOrganization }) => {
   );
 };
 
-export default GitHubProjects;
\ No newline at end of file
+export default GitHubProjects;
-- 
cgit v1.2.3

