Skip to content

Commit

Permalink
vital upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshayGMZ committed Jun 15, 2024
1 parent a4c31b4 commit c7faced
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 99 deletions.
5 changes: 5 additions & 0 deletions .zed/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Folder-specific settings
//
// For a full list of overridable settings, and general information on folder-specific settings,
// see the documentation: https://zed.dev/docs/configuring-zed#folder-specific-settings
{}
15 changes: 3 additions & 12 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BGGradient from "@/components/index/BGGradient";
import Counter from "@/components/index/Counter";
import HomePageGraphs from "@/components/index/Graphs";
import { Metadata } from "next";
import { Suspense } from "react";

export const runtime = "edge";

Expand All @@ -27,7 +28,7 @@ export const metadata: Metadata = {
};

export default async function Page() {
const counterStats = await customFetch<CounterType>("/count");
// const counterStats = await customFetch<CounterType>("/count");
const studentCountBy = await customFetch<StudentCountBy>("/count/by");

return (
Expand All @@ -54,17 +55,7 @@ export default async function Page() {

<Divider className={"my-6"} variant="middle" />

<div className={"grid grid-cols-1 md:grid-cols-2"}>
<Counter counterStats={counterStats} />
</div>

<div className="text-center mt-4">
<p className="text-[0.75rem] text-neutral-400 dark:text-neutral-500">
Note: The actual number of results is {counterStats.actualResult}.
The number of results shown here is the number of result rows
expanded in the database per subject.
</p>
</div>
<Counter />

<Divider className={"my-6"} variant="middle" />

Expand Down
203 changes: 116 additions & 87 deletions components/index/Counter.tsx
Original file line number Diff line number Diff line change
@@ -1,98 +1,127 @@
"use client"
"use client";

import {AnimatePresence, motion} from "framer-motion";
import {Card, CardContent, CardHeader, CardTitle} from "@/components/ui/card";
import {useEffect, useState} from "react";
import {CounterType} from "@/types/types";
import {CountUp} from "countup.js";
import { AnimatePresence, motion } from "framer-motion";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { use, useEffect, useRef, useState } from "react";
import { CounterType } from "@/types/types";
import { CountUp } from "countup.js";
import { customFetch } from "@/app/lib/dataFetchServer";

const options = {
startVal: 0,
duration: 3,
suffix: '+',
startVal: 0,
duration: 3,
suffix: "+",
};


export default function Counter(
{
counterStats
}:{
counterStats: CounterType
}
{
// counterStats
}: {
// counterStats: CounterType
},
) {
const [hoveredIndex, setHoveredIndex] = useState<number | null>(null);
const [counterStats, setCounterStats] = useState<CounterType>({
student: 0,
programme: 0,
institute: 0,
result: 0,
actualResult: 0,
});

const [hoveredIndex, setHoveredIndex] = useState<number | null>(null);

useEffect(() => {
new CountUp("studentCounter", counterStats.student, options).start();
new CountUp("programmeCounter", counterStats.programme, options).start();
new CountUp("instituteCounter", counterStats.institute, options).start();
new CountUp("resultCounter", counterStats.result, options).start();
}, [])
useEffect(() => {
(async () => {
const data = await customFetch<CounterType>("/count");
setCounterStats(data);
})();
}, []);

return (
<>
{
[
{
title: "Institutes",
id: "instituteCounter",
description: counterStats.institute
},
{
title: "Students",
id: "studentCounter",
description: counterStats.student
},
{
title: "Programmes",
id: "programmeCounter",
description: counterStats.programme
},
{
title: "Results",
id: "resultCounter",
description: counterStats.result
}
].map((item: {
title: string;
id: string;
description: number;
}, idx) => (
<div
key={idx + 1}
className="relative group block p-2 h-full w-full"
onMouseEnter={() => setHoveredIndex(idx)}
onMouseLeave={() => setHoveredIndex(null)}
>
<AnimatePresence>
{hoveredIndex === idx && (
<motion.span
className="absolute z-[-1] inset-0 h-full w-full bg-neutral-200 dark:bg-slate-800/[0.8] block rounded-lg"
layoutId="hoverBackground"
initial={{ opacity: 0 }}
animate={{
opacity: 1,
transition: { duration: 0.15 },
}}
exit={{
opacity: 0,
transition: { duration: 0.15, delay: 0.2 },
}}
/>
)}
</AnimatePresence>
<Card className={"hover:scale-100"}>
<CardHeader>
<CardTitle>{item.title}</CardTitle>
</CardHeader>
useEffect(() => {
new CountUp("studentCounter", counterStats.student, options).start();
new CountUp("programmeCounter", counterStats.programme, options).start();
new CountUp("instituteCounter", counterStats.institute, options).start();
new CountUp("resultCounter", counterStats.result, options).start();
}, [counterStats]);

<CardContent>
<h2 id={item.id} className={"text-4xl font-medium"}>{item.description}</h2>
</CardContent>
return (
<>
<div className={"grid grid-cols-1 md:grid-cols-2"}>
{[
{
title: "Institutes",
id: "instituteCounter",
description: counterStats.institute,
},
{
title: "Students",
id: "studentCounter",
description: counterStats.student,
},
{
title: "Programmes",
id: "programmeCounter",
description: counterStats.programme,
},
{
title: "Results",
id: "resultCounter",
description: counterStats.result,
},
].map(
(
item: {
title: string;
id: string;
description: number;
},
idx,
) => (
<div
key={idx + 1}
className="relative group block p-2 h-full w-full"
onMouseEnter={() => setHoveredIndex(idx)}
onMouseLeave={() => setHoveredIndex(null)}
>
<AnimatePresence>
{hoveredIndex === idx && (
<motion.span
className="absolute z-[-1] inset-0 h-full w-full bg-neutral-200 dark:bg-slate-800/[0.8] block rounded-lg"
layoutId="hoverBackground"
initial={{ opacity: 0 }}
animate={{
opacity: 1,
transition: { duration: 0.15 },
}}
exit={{
opacity: 0,
transition: { duration: 0.15, delay: 0.2 },
}}
/>
)}
</AnimatePresence>
<Card className={"hover:scale-100"}>
<CardHeader>
<CardTitle>{item.title}</CardTitle>
</CardHeader>

</Card>
</div>
))}
</>
)
}
<CardContent>
<h2 id={item.id} className={"text-4xl font-medium"}>
{item.description}
</h2>
</CardContent>
</Card>
</div>
),
)}
</div>
<div className="text-center mt-4">
<p className="text-[0.75rem] text-neutral-400 dark:text-neutral-500">
Note: The actual number of results is {counterStats.actualResult}. The
number of results shown here is the number of result rows expanded in
the database per subject.
</p>
</div>
</>
);
}

0 comments on commit c7faced

Please sign in to comment.