From a1977aaf7d5aaa92934292b47d3036cd1b4b5394 Mon Sep 17 00:00:00 2001 From: Vansh Chaurasiya <114163734+vansh-codes@users.noreply.github.com> Date: Thu, 31 Oct 2024 00:34:01 +0530 Subject: [PATCH] Revert "Header, home icon, redirects to home page" --- components/Home.jsx | 68 +++----- src/app/[username]/page.jsx | 301 +++++++++++++++++------------------- 2 files changed, 158 insertions(+), 211 deletions(-) diff --git a/components/Home.jsx b/components/Home.jsx index 8b82ea3..94bd22c 100644 --- a/components/Home.jsx +++ b/components/Home.jsx @@ -1,9 +1,8 @@ -"use client"; +'use client'; import { useState } from "react"; import { useRouter } from "next/navigation"; -import toast, { Toaster } from "react-hot-toast"; +import toast, { Toaster } from 'react-hot-toast'; import Typewriter from "typewriter-effect"; -import Link from "next/link"; function Home() { const [username, setUsername] = useState(""); @@ -13,15 +12,15 @@ function Home() { e.preventDefault(); if (username.trim()) { try { - const response = await fetch("/api/user", { - method: "POST", + const response = await fetch('/api/user', { + method: 'POST', headers: { - "Content-Type": "application/json", + 'Content-Type': 'application/json', }, body: JSON.stringify({ username: username.trim() }), }); - console.log(response); + console.log(response) if (response.ok) { const data = await response.json(); @@ -29,16 +28,16 @@ function Home() { if (data.exists) { router.push(`/${username.trim()}`); } else { - toast.error("Username does not exist on GitHub"); + toast.error('Username does not exist on GitHub'); } } else { - toast.error("Error verifying username. Please try again."); + toast.error('Error verifying username. Please try again.'); } } catch (error) { - toast.error("An unexpected error occurred. Please try again."); + toast.error('An unexpected error occurred. Please try again.'); } } else { - toast.error("Please enter a username."); + toast.error('Please enter a username.'); } }; @@ -47,24 +46,11 @@ function Home() {
{/* Header */} -
- -
- - - -

Gityzer

-
- +
+ + + +

Gityzer

{/* Main Content */} @@ -72,8 +58,7 @@ function Home() {

|", + cursor: "|", }} onInit={(typewriter) => { const animate = () => { @@ -88,11 +73,9 @@ function Home() { animate(); }} /> +

-
+
{/* GitHub Logo inside search bar */}
@@ -130,11 +113,7 @@ function Home() { stroke="currentColor" strokeWidth="2" > - +
@@ -142,14 +121,7 @@ function Home() { {/* Footer */}
diff --git a/src/app/[username]/page.jsx b/src/app/[username]/page.jsx index e343267..8e64ba9 100644 --- a/src/app/[username]/page.jsx +++ b/src/app/[username]/page.jsx @@ -5,7 +5,6 @@ import axios from "axios"; import NotFound from "@/app/not-found"; import Image from "next/image"; import { FaMapPin, FaClock, FaGithub, FaLink } from "react-icons/fa"; -import Link from "next/link"; // Create a separate 404 error component function UserPage({ params }) { @@ -24,37 +23,35 @@ function UserPage({ params }) { useEffect(() => { const fetchUserData = async () => { - setIsLoading(true); // Start loading - setIs404(false); // Reset 404 state for each new fetch - - try { - const userResponse = await fetch( - `https://api.github.com/users/${username}` - ); - - if (userResponse.status === 404) { - setIs404(true); - setUserData(null); - setRepositories([]); - setIsLoading(false); - return; + setIsLoading(true); // Start loading + setIs404(false); // Reset 404 state for each new fetch + + try { + const userResponse = await fetch(`https://api.github.com/users/${username}`); + + if (userResponse.status === 404) { + setIs404(true); + setUserData(null); + setRepositories([]); + setIsLoading(false); + return; + } + + const userData = await userResponse.json(); + setUserData(userData); + + const reposResponse = await fetch(userData.repos_url); + const reposData = await reposResponse.json(); + setRepositories(reposData); + } catch (error) { + console.error("Fetch error:", error); + } finally { + setIsLoading(false); // End loading } - - const userData = await userResponse.json(); - setUserData(userData); - - const reposResponse = await fetch(userData.repos_url); - const reposData = await reposResponse.json(); - setRepositories(reposData); - } catch (error) { - console.error("Fetch error:", error); - } finally { - setIsLoading(false); // End loading - } }; if (username) fetchUserData(); - }, [username]); +}, [username]); const totalPages = Math.ceil(repositories.length / reposPerPage); const indexOfLastRepo = currentPage * reposPerPage; @@ -68,6 +65,9 @@ function UserPage({ params }) { const handlePreviousPage = () => { if (currentPage > 1) setCurrentPage(currentPage - 1); }; + + + const handleThemeChange = (e) => { const newTheme = e.target.value; @@ -103,156 +103,131 @@ function UserPage({ params }) { } return ( - <> -
- {/* Stylish Gradient Background */} -
- - {/* Header */} -
- -
- - - -

Gityzer

+
+ {/* Stylish Gradient Background */} +
+ + {/* User Profile Section */} + {userData && ( +
+
+ {/* Profile Image */} +
+ Profile
- -
- - {/* User Profile Section */} - {userData && ( -
-
- {/* Profile Image */} -
- Profile -
- {/* Profile Info */} -
-

- {userData.name || "Unknown User"} -

-

- @{userData.login || "username"} + {/* Profile Info */} +

+

+ {userData.name || "Unknown User"} +

+

+ @{userData.login || "username"} +

+ +
+

+ + {userData.location || "Unknown"}

+

+ + {new Date().toLocaleString("en-IN", { + timeZone: "Asia/Kolkata", + })} +

+
-
-

- - {userData.location || "Unknown"} -

-

- - {new Date().toLocaleString("en-IN", { - timeZone: "Asia/Kolkata", - })} -

+
+
+ + {userData.followers} followers
- -
-
- - {userData.followers} followers -
-
- - {userData.following} following -
+
+ + {userData.following} following
+
- {/* Repositories Section */} -
-

- {userData.login.toUpperCase()}'s Repositories -

-
- {currentRepos.map((repo) => ( -
-

- - {repo.name} - -

-

- {repo.description || "No description available."} -

-
- {repo.language || "Unknown"} - ★ {repo.stargazers_count || 0} -
+ {/* Repositories Section */} +
+

+ {userData.login.toUpperCase()}'s Repositories +

+
+ {currentRepos.map((repo) => ( +
+

+ + {repo.name} + +

+

+ {repo.description || "No description available."} +

+
+ {repo.language || "Unknown"} + ★ {repo.stargazers_count || 0}
- ))} -
+
+ ))} +
- {/* Pagination */} -
- - - Page {currentPage} of {totalPages} - - -
+ {/* Pagination */} +
+ + + Page {currentPage} of {totalPages} + +
-
-

- {tagline} -

-
-
- - -
+
+
+

{tagline}

+
+
+ +
- )} -
- +
+ )} +
); }