Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions sql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@
-- This file includes all the necessary SQL files to set up the database schema
-- Enable UUID extension if not already enabled
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- Common utility functions
\ i common / utility_functions.sql -- Authentication and user management
\ i auth / user_roles.sql \ i auth / user_triggers.sql \ i auth / user_preferences.sql -- Problem-related tables and functions
\ 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
\ 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
\ i contests / contests.sql \ i contests / user_contest_participation.sql \ i contests / user_contest_feedback.sql \ i contests / contest_functions.sql -- Leaderboard functions
\ i leaderboard / leaderboard_functions.sql -- Grant necessary permissions

GRANT USAGE ON SCHEMA public TO anon,
authenticated,
service_role;

GRANT ALL ON ALL TABLES IN SCHEMA public TO anon,
authenticated,
service_role;

GRANT ALL ON ALL FUNCTIONS IN SCHEMA public TO anon,
authenticated,
service_role;

GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO anon,
authenticated,
service_role;
16 changes: 16 additions & 0 deletions sql/problems/get_user_solved_problems.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Function to get solved problems for a specific user
CREATE OR REPLACE FUNCTION get_user_solved_problems(p_user_id UUID)
RETURNS TABLE (problem_id UUID) AS $$
BEGIN
RETURN QUERY
SELECT usp.problem_id
FROM user_solved_problems usp
JOIN auth.users u ON usp.user_id = u.id
LEFT JOIN user_preferences up ON u.id = up.user_id
WHERE usp.user_id = p_user_id
AND COALESCE(up.hide_from_leaderboard, false) = false;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

-- Grant permissions
GRANT EXECUTE ON FUNCTION get_user_solved_problems TO authenticated, anon;
46 changes: 35 additions & 11 deletions src/lib/components/LeaderboardTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,39 @@ function getRankTierName(rank: number): string {
{entry.username.substring(0, 2).toUpperCase()}
</div>
{/if}
<a
href={entry.githubUrl}
target="_blank"
rel="noopener noreferrer"
class="text-[var(--color-username)] hover:text-[color-mix(in_oklab,var(--color-username)_80%,white)] hover:underline"
title={"@" + entry.username}
>
@{entry.username}
</a>
<div class="flex items-center gap-2">
<a
href={`/user/${entry.userId}`}
class="text-[var(--color-username)] hover:text-[color-mix(in_oklab,var(--color-username)_80%,white)] hover:underline"
title={"View @" + entry.username + "'s solved problems"}
>
@{entry.username}
</a>
<a
href={entry.githubUrl}
target="_blank"
rel="noopener noreferrer"
class="text-[var(--color-text-muted)] hover:text-[var(--color-text)] hover:underline"
title={"View @" + entry.username + "'s GitHub profile"}
aria-label={"View @" + entry.username + "'s GitHub profile"}
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path>
<polyline points="15 3 21 3 21 9"></polyline>
<line x1="10" y1="14" x2="21" y2="3"></line>
</svg>
</a>
</div>
</div>
</td>
<td class="p-2 text-center font-medium sm:p-3">
Expand Down Expand Up @@ -182,11 +206,11 @@ function getRankTierName(rank: number): string {
}

/* Ensure username is always purple */
a[href*='github.com'] {
a[href^='/user/'] {
color: var(--color-username) !important;
}

a[href*='github.com']:hover {
a[href^='/user/']:hover {
color: color-mix(in oklab, var(--color-username) 80%, white) !important;
}
</style>
Loading