Skip to content

Commit

Permalink
Replaced Player List Item with Leaderboard List Item
Browse files Browse the repository at this point in the history
  • Loading branch information
manish-singh-bisht committed May 4, 2024
1 parent dc649bf commit 92768b2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
40 changes: 24 additions & 16 deletions app/(dashboard)/repo-settings/[repositoryId]/players/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import UserProfileSummary from "@/components/ui/userProfileSummary";
import { getUsersForRepository } from "@/lib/repository/service";

export const metadata = {
Expand All @@ -9,27 +9,35 @@ export const metadata = {
export default async function RepoSettings({ params }) {
const players = await getUsersForRepository(params.repositoryId);

const arrayOfPlayersWithTheirTotalPoints = players.map((player) => {
const totalPointsForThisSinglePlayer = player.pointTransactions.reduce((acc, pt) => acc + pt.points, 0);
return {
...player,
totalPointsForThisSinglePlayer: totalPointsForThisSinglePlayer,
};
});

// Sort users by total points in descending order
const arrayOfUsersInRepoInDescendingOrder = arrayOfPlayersWithTheirTotalPoints.sort(
(a, b) => b.totalPointsForThisSinglePlayer - a.totalPointsForThisSinglePlayer
);

return (
<div>
{players.length === 0 ? (
<p>No players enrolled in this repository.</p>
) : (
// Replace with Leaderboard component
<div>
{players.map((player) => (
<div
className="flex w-full items-center justify-between border-b border-gray-200 py-4"
key={player.id}>
<div className="flex items-center gap-3">
<Avatar>
<AvatarImage src="https://github.com/shadcn.png" alt="@shadcn" />
<AvatarFallback>CN</AvatarFallback>
</Avatar>
<p>{player.name}</p>
</div>
<div className="flex items-center gap-3"></div>
</div>
))}{" "}
{arrayOfUsersInRepoInDescendingOrder.map((player, idx) => (
<UserProfileSummary
key={player.id}
name={player.name || player.login}
points={player.totalPointsForThisSinglePlayer}
avatarUrl={player.avatarUrl || ""}
userGitHubId={player.login}
index={idx + 1}
/>
))}
</div>
)}
</div>
Expand Down
1 change: 1 addition & 0 deletions lib/repository/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export const getUsersForRepository = async (repositoryId: string) => {
},
},
},
include: { pointTransactions: true },
});

return users;
Expand Down

0 comments on commit 92768b2

Please sign in to comment.