Skip to content

Commit 6b3a653

Browse files
committed
feat(projects): update all pages to fetch projects data from data/repo_data.json
1 parent a8c5daf commit 6b3a653

File tree

5 files changed

+32
-58
lines changed

5 files changed

+32
-58
lines changed

src/components/GithubCard.tsx

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
1-
import React, { useEffect, useState } from "react";
1+
import React from "react";
22
import "../styles/components/RepoCard.css";
3-
import { RepoData } from "../utils/types";
4-
import { RepoMap } from "../utils/dummyData";
5-
6-
const RepoCard = ({ repoName }: { repoName: string }) => {
7-
const [repoData, setRepoData] = useState<RepoData>({
8-
description: "Find a place to chill during class hours in IIT KGP",
9-
language: "HTML",
10-
stars: 22,
11-
forks: 27,
12-
})
13-
14-
const fetchDummyData = () => {
15-
const data = JSON.parse(RepoMap[`${repoName}_data`])
16-
setRepoData(data);
17-
console.log("Fetched dummy data")
18-
}
19-
20-
useEffect(() => {
21-
fetchDummyData();
22-
});
3+
import { REPO_DATA_TYPE } from "../utils/types";
234

5+
const RepoCard = ({ repoData }: { repoData: REPO_DATA_TYPE }) => {
246
return (
257
<div className="gh-card-container">
268
<div className="gh-card-header">
@@ -29,7 +11,7 @@ const RepoCard = ({ repoName }: { repoName: string }) => {
2911
<path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path>
3012
</svg>
3113
</span>
32-
<span className="gh-repo-name">{repoName}</span>
14+
<span className="gh-repo-name">{repoData.name}</span>
3315
</div>
3416
<div className="gh-card-body">
3517
{repoData.description}

src/pages/About.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@ import React from 'react';
22
import { HeroSection } from "../sections/Hero";
33
import { StatsSection } from "../sections/Statistics";
44
import CardGrid from '../sections/CardGrid';
5+
import RepoData from "../data/repo_data.json";
6+
import { REPO_DATA_TYPE } from '../utils/types';
57

68
function About() {
9+
const Repos: REPO_DATA_TYPE[] = RepoData as REPO_DATA_TYPE[];
10+
const featuredReposList: string[] = ["iqps-go", "metakgp.org"];
11+
const featuredRepos: REPO_DATA_TYPE[] = Repos.filter(repo => featuredReposList.includes(repo.name)) ?? [{
12+
name: "ERROR",
13+
description: "You seem to have inputted a wrong repo name in the featured repos list, please check that your names are valid",
14+
stars: 69,
15+
forks: 420,
16+
language: "ERROR"
17+
}];
18+
719
return (
820
<div className="page-container">
921
<HeroSection />
1022
<StatsSection />
1123
<section className="topic-section">
1224
<h2 className="section-header-left">Featured Projects</h2>
13-
<CardGrid names={["iqps-go", "metakgp.org"]} displayMode='featured' />
25+
<CardGrid repos={featuredRepos} displayMode='featured' />
1426
</section>
1527
<section className="topic-section">
1628
<h2 className="section-header-left">About MetaKGP</h2>

src/pages/Projects.tsx

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
1-
import { useContext, useEffect, useState } from "react";
2-
import RepoCard from "../components/GithubCard";
1+
import { useState } from "react";
32
import CardGrid from "../sections/CardGrid";
4-
import { dummyRepoList, RepoMap } from "../utils/dummyData";
53
import "../styles/pages/Projects.css";
6-
import { RepoData } from "../utils/types";
4+
import { REPO_DATA_TYPE } from "../utils/types";
5+
import RepoData from '../data/repo_data.json';
76

87
const Projects = () => {
9-
const [repoList, setRepoList] = useState<string[]>([]);
10-
const [languages, setLanguages] = useState<string[]>([]);
11-
const [selectedLanguage, setSelectedLanguage] = useState<string[]>([]);
12-
13-
const fetchDummyData = () => {
14-
const data = JSON.parse(dummyRepoList)
15-
setRepoList(data)
16-
}
17-
18-
useEffect(() => {
19-
fetchDummyData();
20-
});
8+
const repoList: REPO_DATA_TYPE[] = RepoData as REPO_DATA_TYPE[]
219

22-
useEffect(() => {
23-
const repoData = repoList
24-
.map(name => JSON.parse(RepoMap[`${name}_data`]));
25-
26-
const allLanguages = [...new Set(repoData.map(repo => repo.language))];
10+
const languages = [...new Set(repoList.map(repo => repo.language))];
11+
const [selectedLanguage, setSelectedLanguage] = useState<string[]>([]);
2712

28-
setLanguages([...allLanguages]);
29-
}, [repoList]);
3013

3114
const toggleLanguage = (lang: string) => {
3215
setSelectedLanguage(prev => {
@@ -39,11 +22,10 @@ const Projects = () => {
3922
});
4023
};
4124

42-
const filteredRepos = repoList.filter(name => {
43-
const repoData: RepoData = JSON.parse(RepoMap[`${name}_data`]);
25+
const filteredRepos = repoList.filter(repo => {
4426
if (selectedLanguage.length === 0)
4527
return true;
46-
return selectedLanguage.includes(repoData.language);
28+
return selectedLanguage.includes(repo.language);
4729
})
4830

4931
return (
@@ -66,7 +48,7 @@ const Projects = () => {
6648
</button>
6749
))}
6850
</div>
69-
<CardGrid names={filteredRepos} displayMode="all" />
51+
<CardGrid repos={filteredRepos} displayMode="all" />
7052
</div>
7153
)
7254
}

src/sections/CardGrid.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import React from "react";
22
import RepoCard from "../components/GithubCard";
33
import "../styles/sections/CardGrid.css"
4+
import { REPO_DATA_TYPE } from "../utils/types";
45

56
type Props = {
6-
names: string[];
7+
repos: REPO_DATA_TYPE[];
78
displayMode: "all" | "featured";
89
}
910

1011
const CardGrid = (props: Props) => {
1112
return (
1213
<div className={`gh-card-grid ${props.displayMode}`}>
13-
{props.names.map((name, index) => (
14-
<RepoCard repoName={name} key={index} />
14+
{props.repos.map((repo, index) => (
15+
<RepoCard repoData={repo} key={index} />
1516
))}
1617
</div>
1718
)

src/utils/types.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
export interface RepoData {
1+
export interface REPO_DATA_TYPE {
2+
name: string;
23
description: string;
34
language: string;
45
stars: number;
56
forks: number;
67
}
7-
8-
export interface dummyData {
9-
[key: string]: string;
10-
}

0 commit comments

Comments
 (0)