diff --git a/src/app/projects/page.tsx b/src/app/projects/page.tsx index 9eb894f..50ffa4e 100644 --- a/src/app/projects/page.tsx +++ b/src/app/projects/page.tsx @@ -1,107 +1,108 @@ -"use client" +"use client"; import * as React from "react"; -import axios from 'axios'; -import Skeleton from 'react-loading-skeleton'; -import 'react-loading-skeleton/dist/skeleton.css'; -import Navbar from "@/components/Navbar/page"; + +import axios from "axios"; +import Skeleton from "react-loading-skeleton"; +import "react-loading-skeleton/dist/skeleton.css"; interface Project { - name: string; - stargazers_count: number; - html_url: string; + name: string; + stargazers_count: number; + html_url: string; } const skeletonStyle = { - marginBottom: '20px', // Adjust this value to increase the gap + marginBottom: "20px", // Adjust this value to increase the gap }; const Project: React.FC = () => { - const [query, setQuery] = React.useState(''); - const [searchResults, setSearchResults] = React.useState([]); - const [loading, setLoading] = React.useState(false); - const [error, setError] = React.useState(''); - - const handleSearch = async () => { - try { - setLoading(true); - setError(''); - const response = await axios.get('https://api.github.com/search/repositories', { - params: { - q: `${query}`, - sort: 'stars', - order: 'desc' - } - }); - setSearchResults(response.data.items); - } catch (error) { - setError('Failed to fetch data'); - } finally { - setLoading(false); - } - }; - - return ( - <> -
-

Search Open Source Projects

-
- setQuery(e.target.value)} - /> - -
- {error &&

{error}

} -
- {/* Adding skeletons for better user experience */} - {loading ? - Array(9).fill(0).map((_, index) => ( -
-

-

-

-
+ const [query, setQuery] = React.useState(""); + const [searchResults, setSearchResults] = React.useState([]); + const [loading, setLoading] = React.useState(false); + const [error, setError] = React.useState(""); - )): (searchResults.map((project, index) => ( -
-

{project.name}

-

{`Stars: ${project.stargazers_count}`}

-

URL: {`${project.html_url}`}

-
- ))) } + const handleSearch = async () => { + try { + setLoading(true); + setError(""); + const response = await axios.get("https://api.github.com/search/repositories", { + params: { + q: `${query}`, + sort: "stars", + order: "desc", + }, + }); + setSearchResults(response.data.items); + } catch (error) { + setError("Failed to fetch data"); + } finally { + setLoading(false); + } + }; + return ( +
+

Search Open Source Projects

+
+ { + if (e.key == "Enter") handleSearch(); + }} + onChange={(e) => setQuery(e.target.value)} + /> + +
+ {error &&

{error}

} +
+ {/* Adding skeletons for better user experience */} + {loading + ? Array(9) + .fill(0) + .map((_, index) => ( +
+

+ +

+

+ +

+

+ +

-
- - - ); -} + )) + : searchResults.map((project, index) => ( +
+

{project.name}

+

{`Stars: ${project.stargazers_count}`}

+

+ + URL: {`${project.html_url}`} + +

+
+ ))} +
+
+ ); +}; export default Project;