Skip to content

Commit 16df4cc

Browse files
Merge pull request #34 from cameroncuster/show-user-solves
show user solves from the leaderboard
2 parents 36e9131 + d4969e6 commit 16df4cc

File tree

8 files changed

+633
-517
lines changed

8 files changed

+633
-517
lines changed

sql/init.sql

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@
22
-- This file includes all the necessary SQL files to set up the database schema
33
-- Enable UUID extension if not already enabled
44
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
5-
65
-- Common utility functions
76
\ i common / utility_functions.sql -- Authentication and user management
87
\ i auth / user_roles.sql \ i auth / user_triggers.sql \ i auth / user_preferences.sql -- Problem-related tables and functions
9-
\ i problems / problems.sql \ i problems / user_problem_feedback.sql \ i problems / user_solved_problems.sql \ i problems / problem_functions.sql -- Contest-related tables and functions
8+
\ i problems / problems.sql \ i problems / user_problem_feedback.sql \ i problems / user_solved_problems.sql \ i problems / problem_functions.sql \ i problems / get_user_solved_problems.sql -- Contest-related tables and functions
109
\ i contests / contests.sql \ i contests / user_contest_participation.sql \ i contests / user_contest_feedback.sql \ i contests / contest_functions.sql -- Leaderboard functions
1110
\ i leaderboard / leaderboard_functions.sql -- Grant necessary permissions
12-
1311
GRANT USAGE ON SCHEMA public TO anon,
1412
authenticated,
1513
service_role;
16-
1714
GRANT ALL ON ALL TABLES IN SCHEMA public TO anon,
1815
authenticated,
1916
service_role;
20-
2117
GRANT ALL ON ALL FUNCTIONS IN SCHEMA public TO anon,
2218
authenticated,
2319
service_role;
24-
2520
GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO anon,
2621
authenticated,
2722
service_role;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Function to get solved problems for a specific user
2+
CREATE OR REPLACE FUNCTION get_user_solved_problems(p_user_id UUID)
3+
RETURNS TABLE (problem_id UUID) AS $$
4+
BEGIN
5+
RETURN QUERY
6+
SELECT usp.problem_id
7+
FROM user_solved_problems usp
8+
JOIN auth.users u ON usp.user_id = u.id
9+
LEFT JOIN user_preferences up ON u.id = up.user_id
10+
WHERE usp.user_id = p_user_id
11+
AND COALESCE(up.hide_from_leaderboard, false) = false;
12+
END;
13+
$$ LANGUAGE plpgsql SECURITY DEFINER;
14+
15+
-- Grant permissions
16+
GRANT EXECUTE ON FUNCTION get_user_solved_problems TO authenticated, anon;

src/lib/components/LeaderboardTable.svelte

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,39 @@ function getRankTierName(rank: number): string {
111111
{entry.username.substring(0, 2).toUpperCase()}
112112
</div>
113113
{/if}
114-
<a
115-
href={entry.githubUrl}
116-
target="_blank"
117-
rel="noopener noreferrer"
118-
class="text-[var(--color-username)] hover:text-[color-mix(in_oklab,var(--color-username)_80%,white)] hover:underline"
119-
title={"@" + entry.username}
120-
>
121-
@{entry.username}
122-
</a>
114+
<div class="flex items-center gap-2">
115+
<a
116+
href={`/user/${entry.userId}`}
117+
class="text-[var(--color-username)] hover:text-[color-mix(in_oklab,var(--color-username)_80%,white)] hover:underline"
118+
title={"View @" + entry.username + "'s solved problems"}
119+
>
120+
@{entry.username}
121+
</a>
122+
<a
123+
href={entry.githubUrl}
124+
target="_blank"
125+
rel="noopener noreferrer"
126+
class="text-[var(--color-text-muted)] hover:text-[var(--color-text)] hover:underline"
127+
title={"View @" + entry.username + "'s GitHub profile"}
128+
aria-label={"View @" + entry.username + "'s GitHub profile"}
129+
>
130+
<svg
131+
xmlns="http://www.w3.org/2000/svg"
132+
width="14"
133+
height="14"
134+
viewBox="0 0 24 24"
135+
fill="none"
136+
stroke="currentColor"
137+
stroke-width="2"
138+
stroke-linecap="round"
139+
stroke-linejoin="round"
140+
>
141+
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path>
142+
<polyline points="15 3 21 3 21 9"></polyline>
143+
<line x1="10" y1="14" x2="21" y2="3"></line>
144+
</svg>
145+
</a>
146+
</div>
123147
</div>
124148
</td>
125149
<td class="p-2 text-center font-medium sm:p-3">
@@ -182,11 +206,11 @@ function getRankTierName(rank: number): string {
182206
}
183207
184208
/* Ensure username is always purple */
185-
a[href*='github.com'] {
209+
a[href^='/user/'] {
186210
color: var(--color-username) !important;
187211
}
188212
189-
a[href*='github.com']:hover {
213+
a[href^='/user/']:hover {
190214
color: color-mix(in oklab, var(--color-username) 80%, white) !important;
191215
}
192216
</style>

0 commit comments

Comments
 (0)