--- import BaseLayout from "../../layouts/BaseLayout.astro"; import { priceCollectionCards, type MyCardRecord, } from "../../lib/collection"; const { pb } = Astro.locals; if (!pb.authStore.isValid) { return Astro.redirect("/login"); } const { username } = Astro.params; if (!username) { return Astro.redirect("/friends"); } // Find the target user by username (same public view the friends API uses) let targetUser; try { targetUser = await pb .collection("public_users") .getFirstListItem(pb.filter("username = {:username}", { username })); } catch { return Astro.redirect("/friends"); } // Check visibility — Private users' collections are never visible if (targetUser.visibility === "Private") { return Astro.redirect("/friends"); } // Friends-only collections require an accepted friendship if (targetUser.visibility !== "Public") { const userId = pb.authStore.record!.id; const friendship = await pb.collection("friendships").getList(1, 1, { filter: pb.filter( "((requester = {:userId} && addressee = {:targetId}) || (requester = {:targetId} && addressee = {:userId})) && status = 'accepted'", { userId, targetId: targetUser.id }, ), }); if (friendship.items.length === 0) { return Astro.redirect("/friends"); } } // Fetch their collection const myCards = (await pb.collection("mycards").getFullList({ filter: pb.filter("user = {:userId}", { userId: targetUser.id }), sort: "-created", })) as unknown as MyCardRecord[]; const cardsWithPrice = await priceCollectionCards(myCards); const totalValue = cardsWithPrice.reduce((s, c) => s + c.totalPrice, 0); const totalCards = cardsWithPrice.reduce((s, c) => s + c.quantity, 0); --- ← Amis { ( targetUser.name || targetUser.username || targetUser.email || "??" ) .slice(0, 2) .toUpperCase() } {targetUser.name || "—"} @{targetUser.username || "—"} Cartes {totalCards} Valeur totale {totalValue.toFixed(2)} € { cardsWithPrice.length === 0 ? ( Collection vide {targetUser.name || targetUser.username} n'a pas encore de cartes dans sa collection. ) : ( {cardsWithPrice.map((card) => ( {card.card_image ? ( ) : ( )} {card.card_name} {card.set_name && ( {card.set_name} )} {card.variant} ×{card.quantity} {card.condition && ( {card.condition} )} {card.price.toFixed(2)} € {card.quantity > 1 && ( = {card.totalPrice.toFixed(2)} € )} ))} ) }
@{targetUser.username || "—"}
{targetUser.name || targetUser.username} n'a pas encore de cartes dans sa collection.