feat: add gamification hooks, leaderboard UI, and translations
- Added Directus hooks for automatic point awards: - Recording creation/publishing (50 points) - Recording featured status (100 points bonus) - Comments on recordings (5 points) - Created /leaderboard route with full UI - Server-side data loading with authentication guard - Responsive design with medal emojis for top 3 - User stats display (recordings, plays, achievements) - Pagination support - "How It Works" info section - Added comprehensive gamification translations - Time-weighted scoring displayed for rankings - Automatic achievement checking on point awards 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
43
packages/frontend/src/routes/leaderboard/+page.server.ts
Normal file
43
packages/frontend/src/routes/leaderboard/+page.server.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, url, locals }) => {
|
||||
// Guard: Redirect to login if not authenticated
|
||||
if (!locals.authStatus.authenticated) {
|
||||
throw redirect(302, "/login");
|
||||
}
|
||||
|
||||
try {
|
||||
const limit = parseInt(url.searchParams.get("limit") || "100");
|
||||
const offset = parseInt(url.searchParams.get("offset") || "0");
|
||||
|
||||
const response = await fetch(
|
||||
`/api/sexy/gamification/leaderboard?limit=${limit}&offset=${offset}`,
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch leaderboard");
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return {
|
||||
leaderboard: data.data || [],
|
||||
pagination: {
|
||||
limit,
|
||||
offset,
|
||||
hasMore: data.data?.length === limit,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Leaderboard load error:", error);
|
||||
return {
|
||||
leaderboard: [],
|
||||
pagination: {
|
||||
limit: 100,
|
||||
offset: 0,
|
||||
hasMore: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user