feat: add friends' results display for today's game
All checks were successful
Build Docker Image / build (push) Successful in 1m12s

This commit is contained in:
2026-03-06 19:34:46 +01:00
parent f35f4565b6
commit ce08329b2d
2 changed files with 89 additions and 5 deletions

View File

@@ -1,10 +1,10 @@
import { error } from '@sveltejs/kit';
import { db } from '$lib/server/db';
import { config } from '$lib/server/db/schema';
import { getDailyModeCharacters, getOrCreateTodayCharacter, getYesterdayCharacter, getTodayCharacterWinsCount } from '$lib/server/daily-character';
import { like } from 'drizzle-orm';
import { characterHistory, config, friendship, user, userCharacterHistory } from '$lib/server/db/schema';
import { getDailyModeCharacters, getOrCreateTodayCharacter, getYesterdayCharacter, getTodayCharacterWinsCount, getDateKey } from '$lib/server/daily-character';
import { and, eq, inArray, like, or } from 'drizzle-orm';
export async function load() {
export async function load(event) {
const characters = await getDailyModeCharacters();
const dailyCharacter = await getOrCreateTodayCharacter(characters);
@@ -17,6 +17,60 @@ export async function load() {
// Load the win count for today
const winCount = await getTodayCharacterWinsCount(dailyCharacter.id);
let friendsTodayResults: Array<{ userId: string; name: string; image: string | null; tryCount: number }> = [];
if (event.locals.user) {
const currentUserId = event.locals.user.id;
const acceptedFriendships = await db
.select({
requesterId: friendship.requesterId,
addresseeId: friendship.addresseeId
})
.from(friendship)
.where(
and(
eq(friendship.status, 'accepted'),
or(eq(friendship.requesterId, currentUserId), eq(friendship.addresseeId, currentUserId))
)
);
const friendIds = acceptedFriendships.map((relation) =>
relation.requesterId === currentUserId ? relation.addresseeId : relation.requesterId
);
if (friendIds.length > 0) {
const todayDate = getDateKey(new Date());
const [todayHistoryEntry] = await db
.select({ id: characterHistory.id })
.from(characterHistory)
.where(eq(characterHistory.date, todayDate))
.limit(1);
const todayCharacterHistoryId = todayHistoryEntry?.id;
if (todayCharacterHistoryId) {
friendsTodayResults = await db
.select({
userId: user.id,
name: user.name,
image: user.image,
tryCount: userCharacterHistory.tryCount
})
.from(userCharacterHistory)
.innerJoin(user, eq(userCharacterHistory.userId, user.id))
.where(
and(
eq(userCharacterHistory.characterHistoryId, todayCharacterHistoryId),
inArray(userCharacterHistory.userId, friendIds)
)
)
.orderBy(userCharacterHistory.tryCount);
}
}
}
// Load column visibility config
const columnConfig = await db
.select()
@@ -37,6 +91,7 @@ export async function load() {
dailyCharacter,
yesterdayCharacter,
columnVisibility,
winCount
winCount,
friendsTodayResults
};
}

View File

@@ -258,6 +258,35 @@
{columnVisibility}
/>
{#if data.friendsTodayResults && data.friendsTodayResults.length > 0}
<section class="mt-6 rounded-3xl border border-white/10 bg-white/5 p-6 shadow-[0_24px_60px_rgba(0,0,0,0.45)] backdrop-blur">
<p class="text-xs font-semibold uppercase tracking-[0.28em] text-amber-100 text-center">Tes amis aujourd'hui</p>
<div class="mt-4 space-y-2">
{#each data.friendsTodayResults as friendResult}
<div class="flex items-center justify-between rounded-lg border border-white/10 bg-slate-950/50 px-4 py-2">
<div class="flex items-center gap-3">
{#if friendResult.image}
<img
src={friendResult.image}
alt={friendResult.name}
class="h-8 w-8 rounded-full border border-white/20 object-cover"
/>
{:else}
<div class="flex h-8 w-8 items-center justify-center rounded-full bg-amber-300/20 text-xs font-semibold text-amber-100">
{friendResult.name?.charAt(0).toUpperCase() || 'U'}
</div>
{/if}
<p class="text-sm font-semibold text-slate-100">{friendResult.name}</p>
</div>
<p class="text-sm text-amber-300">
{friendResult.tryCount} {friendResult.tryCount > 1 ? 'coups' : 'coup'}
</p>
</div>
{/each}
</div>
</section>
{/if}
<YesterdayCharacter {yesterdayCharacter} />
</div>
</main>