From a51efa657c976ee1e68d1c126b1a63674476b4df Mon Sep 17 00:00:00 2001 From: Ankit Kumar Date: Mon, 4 Apr 2022 12:27:51 +0530 Subject: [PATCH 1/2] feat: add dynamic git projects --- components/homepage/index.tsx | 4 ++-- components/projects/index.tsx | 2 +- components/projects/project-card.tsx | 17 +++-------------- components/projects/search-project.tsx | 14 +++++++++++++- lib/get-all-github-stars.ts | 13 ++++++++++++- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/components/homepage/index.tsx b/components/homepage/index.tsx index d225dc1..471f03f 100644 --- a/components/homepage/index.tsx +++ b/components/homepage/index.tsx @@ -4,10 +4,10 @@ import Navbar from '@/components/navbar'; import RecentBlog from '@/components/homepage/recent-blog-card'; import RecentProject from '@/components/homepage/recent-project-card'; import Footer from '@/components/footer'; -import getAllGithubStars from '@/lib/get-all-github-stars'; +import { getAllGithubStars } from '@/lib/get-all-github-stars'; import { AiOutlineGithub } from 'react-icons/ai'; import projects from '@/data/projects'; -import router, { useRouter } from 'next/router'; +import router from 'next/router'; const Profile = ({ posts }) => { useEffect(() => { diff --git a/components/projects/index.tsx b/components/projects/index.tsx index 25b7722..ab8dec6 100644 --- a/components/projects/index.tsx +++ b/components/projects/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import Navbar from '@/components/navbar'; import SearchProject from '@/components/projects/search-project'; import { Box } from '@chakra-ui/react'; diff --git a/components/projects/project-card.tsx b/components/projects/project-card.tsx index 9ec2e96..0b4146d 100644 --- a/components/projects/project-card.tsx +++ b/components/projects/project-card.tsx @@ -1,12 +1,13 @@ import React from 'react'; import { Box, Heading, Text, Stack, useColorModeValue } from '@chakra-ui/react'; -import { AiFillGithub } from 'react-icons/ai'; import Link from 'next/link'; const ProjectCard = ({ project }) => { + if(project.fork) return <> + return ( - + { {project.name} {project.description} - - {project.demo && ( - - Preview - - )} - {project.github && ( - - - - )} - diff --git a/components/projects/search-project.tsx b/components/projects/search-project.tsx index 13d545b..c85bda6 100644 --- a/components/projects/search-project.tsx +++ b/components/projects/search-project.tsx @@ -1,13 +1,25 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import ProjectCard from '@/components/projects/project-card'; import { Box, InputGroup, InputRightElement, Input } from '@chakra-ui/react'; import projects from '@/data/projects'; +import { getRepos } from '@/lib/get-all-github-stars'; import { AiOutlineSearch } from 'react-icons/ai'; const SearchProject = () => { const [filteredList, setFilteredList] = useState(projects); const [searchText, setSearchText] = useState(''); + useEffect(() => { + async function fetchMyAPI() { + const data = await getRepos(); + + const sortedData = data.sort((a, b) => b['stargazers_count'] - a['stargazers_count']) + setFilteredList(sortedData) + } + + fetchMyAPI(); + }, []); + const handleChange = (e) => { const inputValue = e.target.value; setSearchText(inputValue); diff --git a/lib/get-all-github-stars.ts b/lib/get-all-github-stars.ts index 74456c9..d9b47b6 100644 --- a/lib/get-all-github-stars.ts +++ b/lib/get-all-github-stars.ts @@ -12,4 +12,15 @@ const getAllGithubStars = async () => { return stars; }; -export default getAllGithubStars; +const getRepos = async () => { + const URL = 'https://api.github.com/users/knowankit/repos'; + const response = await fetch(URL); + const data = await response.json(); + + + return data; +}; + + + +export { getAllGithubStars, getRepos } ; From 74b0e5c3556a1e8396a7778a409f5c6c1b0e5b36 Mon Sep 17 00:00:00 2001 From: knowankit <44323532+knowankit@users.noreply.github.com> Date: Sat, 9 Apr 2022 11:37:43 +0530 Subject: [PATCH 2/2] fix: lint errors --- README.md | 1 + components/projects/index.tsx | 2 +- components/projects/project-card.tsx | 2 +- components/projects/search-project.tsx | 6 +++--- lib/get-all-github-stars.ts | 5 +---- lib/mdx.ts | 2 ++ next-env.d.ts | 1 - tsconfig.json | 16 +++------------- 8 files changed, 12 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 282ed11..1595e0f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ ![Portfolio demo](https://github.com/knowankit/knowankit.com/blob/develop/demo.gif) +

Twitter: Ankit Kumar diff --git a/components/projects/index.tsx b/components/projects/index.tsx index ab8dec6..25b7722 100644 --- a/components/projects/index.tsx +++ b/components/projects/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React from 'react'; import Navbar from '@/components/navbar'; import SearchProject from '@/components/projects/search-project'; import { Box } from '@chakra-ui/react'; diff --git a/components/projects/project-card.tsx b/components/projects/project-card.tsx index 0b4146d..ccff2c8 100644 --- a/components/projects/project-card.tsx +++ b/components/projects/project-card.tsx @@ -4,7 +4,7 @@ import { Box, Heading, Text, Stack, useColorModeValue } from '@chakra-ui/react'; import Link from 'next/link'; const ProjectCard = ({ project }) => { - if(project.fork) return <> + if (project.fork) return <>; return ( diff --git a/components/projects/search-project.tsx b/components/projects/search-project.tsx index c85bda6..5681cf3 100644 --- a/components/projects/search-project.tsx +++ b/components/projects/search-project.tsx @@ -12,9 +12,9 @@ const SearchProject = () => { useEffect(() => { async function fetchMyAPI() { const data = await getRepos(); - - const sortedData = data.sort((a, b) => b['stargazers_count'] - a['stargazers_count']) - setFilteredList(sortedData) + + const sortedData = data.sort((a, b) => b['stargazers_count'] - a['stargazers_count']); + setFilteredList(sortedData); } fetchMyAPI(); diff --git a/lib/get-all-github-stars.ts b/lib/get-all-github-stars.ts index d9b47b6..d982ce3 100644 --- a/lib/get-all-github-stars.ts +++ b/lib/get-all-github-stars.ts @@ -17,10 +17,7 @@ const getRepos = async () => { const response = await fetch(URL); const data = await response.json(); - return data; }; - - -export { getAllGithubStars, getRepos } ; +export { getAllGithubStars, getRepos }; diff --git a/lib/mdx.ts b/lib/mdx.ts index 72a7471..776c0cb 100644 --- a/lib/mdx.ts +++ b/lib/mdx.ts @@ -1,3 +1,5 @@ +/* eslint-disable */ + import fs from 'fs'; import matter from 'gray-matter'; import path from 'path'; diff --git a/next-env.d.ts b/next-env.d.ts index 9bc3dd4..4f11a03 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,5 +1,4 @@ /// -/// /// // NOTE: This file should not be edited diff --git a/tsconfig.json b/tsconfig.json index cc568d8..7d5be48 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,7 @@ { "compilerOptions": { "target": "es5", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], + "lib": ["dom", "dom.iterable", "esnext"], "baseUrl": ".", "paths": { "@/src/*": ["src/*"], @@ -29,12 +25,6 @@ "isolatedModules": true, "jsx": "preserve" }, - "include": [ - "next-env.d.ts", - "**/*.ts", - "**/*.tsx" - ], - "exclude": [ - "node_modules" - ] + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], + "exclude": ["node_modules"] }