Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 244 - update KPI numbers on the website #250

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
44 changes: 35 additions & 9 deletions frontend/src/components/DataCard/DataCard.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';
import React, { useEffect, useState } from 'react';

import { FaCity, FaGithub, FaUsers } from 'react-icons/fa';
import { useInView } from 'react-intersection-observer';
import { url, requestOptions } from './apiDataCard';

// Define props type for StatCard component
interface StatCardProps {
Expand All @@ -14,27 +14,53 @@ interface StatCardProps {
}

export const DataCard = () => {
const [dataCount, setDataCount] = useState({stargazers_count: Number, subscribers_count: Number, contributors_count: Number});
const [loading, setLoading] = useState(true);
useEffect(() => {
//Set up use effect so API runs on component load and stops once loading is set to false.
async function fetchDataCount(url1: string, url2: string, options: object): Promise<any> {
try {
if (url1 && url2) {
let res = await fetch(url1, options);
let res2 = await fetch(url2, options);
let data = await res.json();
let data2 = await res2.json();
setDataCount({stargazers_count: Number(data.stargazers_count), subscribers_count: 250, contributors_count: Number(data2.length)});
setLoading(false);
}

}
catch(err){
console.log('Error:', err)
}
}
if (loading){
fetchDataCount(url.stargazers_count, url.contributors, requestOptions.options);
}

},[])

return (
<div className='grid w-full items-center justify-center gap-6 p-8 md:grid-cols-2 lg:grid-cols-3'>
<StatCard
title='Active Contributors'
subText='& counting till date'
subText='& counting to date'
startCount={0}
count={20}
count={dataCount.contributors_count}
icon={<FaCity className='text-[2rem]' />}
/>
<StatCard
title='Subscribers'
subText='loving Django India'
startCount={10}
count={100}
startCount={0}
count={dataCount.subscribers_count}
icon={<FaUsers className='text-[3rem]' />}
/>
<StatCard
title='GitHub Stars'
subText='till date'
subText='to date'
startCount={0}
count={70}
count={dataCount.stargazers_count}
icon={<FaGithub className='text-[2rem]' />}
/>
</div>
Expand All @@ -54,7 +80,7 @@ const StatCard: React.FC<StatCardProps> = ({
threshold: 0.4,
});
const intervalTime = count === 31818 ? 1 : 100;

useEffect(() => {
let start = startCount;
const interval = setInterval(() => {
Expand All @@ -81,7 +107,7 @@ const StatCard: React.FC<StatCardProps> = ({
<div className='ml-4 flex grow flex-col'>
<span className='text-4xl font-bold'>
{count === 50 ? '' : ''}
{inView ? number : 0}+
{inView ? number : 0}
</span>
<span className='text-xl font-bold'>{title}</span>
<div className='flex items-center justify-between'>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/components/DataCard/apiDataCard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//API URL and Headers exported for DataCard.tsx
export const requestOptions = {
options: {method: "GET", headers: {'X-GitHub-Api-Version': '2022-11-28'}},
};
export const url = {
stargazers_count: "https://api.github.com/repos/djangoindia/djangoindia.org",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use env for these

contributors: "https://api.github.com/repos/djangoindia/djangoindia.org/contributors",
};
ehemp marked this conversation as resolved.
Show resolved Hide resolved
Loading