Skip to content

Commit

Permalink
feat(leaderboard): show user's leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
tfkhdyt committed Jul 7, 2024
1 parent bc1c914 commit c818af5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/app/_components/sidebar/most-active-users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function MostActiveUsers({
</h2>

<ol className='space-y-5'>
{data.map(({ user }, index) => (
{data.map(({ user, score }, index) => (
<li key={user.id} className='flex space-x-2 items-center'>
<div className='text-[#696984] w-4 pr-2 font-medium text-lg'>
<span>{index + 1}.</span>
Expand All @@ -41,7 +41,7 @@ export function MostActiveUsers({
}}
/>
</Link>
<div className='text-[#696984]'>
<div className='text-[#696984] grow'>
<Link
className='max-w-[10rem] cursor-pointer truncate font-medium decoration-2 hover:underline md:max-w-[12rem] block text-base'
href={`/users/${user.username}`}
Expand All @@ -59,6 +59,12 @@ export function MostActiveUsers({
@{user.username}
</Link>
</div>
<p
className='ml-auto bg-orange-500 rounded-full text-white p-4 size-10 flex justify-center items-center font-medium'
title='Score, dihitung berdasarkan jumlah pertanyaan, jawaban, dan favorit'
>
{score}
</p>
</li>
))}
</ol>
Expand Down
3 changes: 3 additions & 0 deletions src/server/api/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export const userRouter = createTRPCRouter({
const data = await ctx.db
.select({
user: users,
score,
})
.from(users)
.leftJoin(questions, eq(questions.userId, users.id))
Expand Down Expand Up @@ -219,11 +220,13 @@ export const userRouter = createTRPCRouter({
gt(memberships.expiresAt, new Date()),
),
);

return data.map((dt) => ({
user: {
...dt.user,
membership: _memberships.find((mb) => mb.userId === dt.user.id),
},
score: dt.score,
}));
}),
});

0 comments on commit c818af5

Please sign in to comment.