generated from muhtadeetaron/nextjs-template
chore: refactor code for type safety
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
// lib/resultViews.tsx
|
||||
// lib/gallery-views.tsx
|
||||
import { Link } from "lucide-react";
|
||||
import Image from "next/image";
|
||||
|
||||
interface ExamResults {
|
||||
@ -97,3 +98,34 @@ export const getResultViews = (examResults: ExamResults | null) => [
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
export const getLinkedViews = () => [
|
||||
{
|
||||
id: "1",
|
||||
content: (
|
||||
<Link
|
||||
href="https://www.facebook.com/share/g/15jdqESvWV/?mibextid=wwXIfr"
|
||||
className="w-full h-full block text-inherit box-border"
|
||||
>
|
||||
<div className="w-full h-full p-6 flex text-black bg-blue-50 rounded-4xl border-[0.5px] border-[#113768]/30">
|
||||
<div className="">
|
||||
<h3 className="text-2xl text-[#113768] font-black">
|
||||
Meet, Share, and Learn!
|
||||
</h3>
|
||||
<p className="font-bold text-sm text-[#113768] ">
|
||||
Join Facebook Community
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex justify-center items-center shrink-0">
|
||||
<Image
|
||||
src="/images/static/facebook-logo.png"
|
||||
alt="Facebook Logo"
|
||||
width={150}
|
||||
height={150}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
),
|
||||
},
|
||||
];
|
||||
32
lib/leaderboard.ts
Normal file
32
lib/leaderboard.ts
Normal file
@ -0,0 +1,32 @@
|
||||
export interface BoardData {
|
||||
id: string;
|
||||
name: string;
|
||||
points: number;
|
||||
}
|
||||
|
||||
export const getTopThree = (boardData: BoardData[]) => {
|
||||
if (!boardData || boardData.length === 0) return [];
|
||||
return boardData
|
||||
.slice()
|
||||
.sort((a, b) => b.points - a.points)
|
||||
.slice(0, 3)
|
||||
.map((player, index) => ({
|
||||
...player,
|
||||
rank: index + 1,
|
||||
height: index === 0 ? 250 : index === 1 ? 200 : 170,
|
||||
}));
|
||||
};
|
||||
|
||||
export const getLeaderboard = (boardData: BoardData[]) => {
|
||||
return boardData.slice().sort((a, b) => b.points - a.points);
|
||||
};
|
||||
|
||||
export const getUserData = (boardData: BoardData[], name: string) => {
|
||||
if (!boardData || !Array.isArray(boardData)) return [];
|
||||
const sortedData = boardData
|
||||
.filter((player) => player?.name && player?.points !== undefined)
|
||||
.sort((a, b) => b.points - a.points);
|
||||
|
||||
const result = sortedData.find((player) => player.name === name);
|
||||
return result ? [{ ...result, rank: sortedData.indexOf(result) + 1 }] : [];
|
||||
};
|
||||
Reference in New Issue
Block a user