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

Feature Update: Counters Added WhatIsDjango Section #149

Merged
merged 10 commits into from
Sep 20, 2024
91 changes: 91 additions & 0 deletions frontend/src/components/DataCard/datacard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React, { useState, useEffect } from "react";
import { useInView } from "react-intersection-observer";
engagepy marked this conversation as resolved.
Show resolved Hide resolved
import { FaCity, FaGithub } from "react-icons/fa";
import { FaUsers } from "react-icons/fa";
import { RiLandscapeFill } from "react-icons/ri";
engagepy marked this conversation as resolved.
Show resolved Hide resolved

// Define props type for StatCard component
interface StatCardProps {
title: string;
subText: string;
engagepy marked this conversation as resolved.
Show resolved Hide resolved
startCount: number;
count: number;
icon: React.ReactNode;
}

function DataCard() {
engagepy marked this conversation as resolved.
Show resolved Hide resolved
return (
<div className="grid justify-center items-center lg:grid-cols-3 md:grid-cols-2 gap-6 w-full p-8">
<StatCard
title="Member Cities"
subText="& counting till date"
startCount={0}
count={5}
icon={<FaCity className="text-[2rem]" />}
/>
<StatCard
title="Subscribers"
subText="building Django India"
startCount={10}
count={100}
icon={<FaUsers className="text-[3rem]" />}
/>
<StatCard
title="GitHub Stars"
subText="till date"
startCount={0}
count={50}
icon={<FaGithub className="text-[2rem]" />}
/>
</div>
);
}

// Define StatCard component with props typed
const StatCard: React.FC<StatCardProps> = ({ title, subText, count, startCount, icon }) => {
const [number, setNumber] = useState(startCount);
const { ref, inView } = useInView({
threshold: 0.4,
});
const intervalTime = count === 31818 ? 1 : 100;

useEffect(() => {
let start = startCount;
const interval = setInterval(() => {
if (start <= count) {
setNumber(start);
start += 1;
} else {
clearInterval(interval);
}
}, intervalTime);
return () => {
clearInterval(interval);
};
}, [inView, startCount, count, intervalTime]);

return (
<div
ref={ref}
className="flex items-center p-4 border border-gray-400 rounded-lg"
>
<div className="flex flex-shrink-0 items-center justify-center bg-green-500 h-16 w-16 rounded">
{icon}
</div>
<div className="flex-grow flex flex-col ml-4">
<span className="text-4xl font-bold">
{count === 50 ? "" : ""}
{inView ? number : 0}+
</span>
<span className="text-xl font-bold">
{title === count ? " " : title}
engagepy marked this conversation as resolved.
Show resolved Hide resolved
</span>
<div className="flex items-center justify-between">
<span className="gradient font-bold">{subText}</span>
</div>
</div>
</div>
);
};

export default DataCard;
engagepy marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion frontend/src/sections/WhatIsDjango/WhatIsDjango.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Image from 'next/image'
import { Button } from '@components'
import useWidth from '@/hooks/useWidth'
import DataCard from '@/components/DataCard/datacard'
engagepy marked this conversation as resolved.
Show resolved Hide resolved

const WhatIsDjango = () => {
const width = useWidth()
Expand Down Expand Up @@ -70,8 +71,9 @@ const WhatIsDjango = () => {
</div>
</div>
</section>
<DataCard />
</section>
)
}

export default WhatIsDjango
export default WhatIsDjango
engagepy marked this conversation as resolved.
Show resolved Hide resolved