{renderCellContent(stat, column, index)}
{columnIndex === 0 && (
@@ -371,4 +415,4 @@ const PlayerStatsTable = ({ playerStats }: PlayerStatsTableProps) => {
);
};
-export default PlayerStatsTable;
\ No newline at end of file
+export default PlayerStatsTable;
diff --git a/src/features/players/components/profile/index.tsx b/src/features/players/components/profile/index.tsx
index b320b2e..d0af634 100644
--- a/src/features/players/components/profile/index.tsx
+++ b/src/features/players/components/profile/index.tsx
@@ -1,10 +1,11 @@
-import { Box, Text } from "@mantine/core";
+import { Box } from "@mantine/core";
import Header from "./header";
import { Player } from "@/features/players/types";
import SwipeableTabs from "@/components/swipeable-tabs";
-import { usePlayer } from "../../queries";
+import { usePlayer, usePlayerMatches } from "../../queries";
import TeamList from "@/features/teams/components/team-list";
import StatsOverview from "../stats-overview";
+import MatchList from "@/features/matches/components/match-list";
interface ProfileProps {
id: string;
@@ -12,6 +13,8 @@ interface ProfileProps {
const Profile = ({ id }: ProfileProps) => {
const { data: player } = usePlayer(id);
+ const { data: matches } = usePlayerMatches(id);
+
const tabs = [
{
label: "Overview",
@@ -19,7 +22,7 @@ const Profile = ({ id }: ProfileProps) => {
},
{
label: "Matches",
- content:
Matches feed will go here,
+ content:
,
},
{
label: "Teams",
diff --git a/src/features/players/queries.ts b/src/features/players/queries.ts
index b5100ac..a17819c 100644
--- a/src/features/players/queries.ts
+++ b/src/features/players/queries.ts
@@ -1,5 +1,5 @@
import { useServerSuspenseQuery } from "@/lib/tanstack-query/hooks";
-import { listPlayers, getPlayer, getUnassociatedPlayers, fetchMe, getPlayerStats, getAllPlayerStats } from "./server";
+import { listPlayers, getPlayer, getUnassociatedPlayers, fetchMe, getPlayerStats, getAllPlayerStats, getPlayerMatches } from "./server";
export const playerKeys = {
auth: ['auth'],
@@ -8,6 +8,7 @@ export const playerKeys = {
unassociated: ['players','unassociated'],
stats: (id: string) => ['players', 'stats', id],
allStats: ['players', 'stats', 'all'],
+ matches: (id: string) => ['players', 'matches', id],
};
export const playerQueries = {
@@ -35,6 +36,10 @@ export const playerQueries = {
queryKey: playerKeys.allStats,
queryFn: async () => await getAllPlayerStats()
}),
+ matches: (id: string) => ({
+ queryKey: playerKeys.matches(id),
+ queryFn: async () => await getPlayerMatches({ data: id })
+ }),
};
export const useMe = () => {
@@ -73,4 +78,7 @@ export const usePlayerStats = (id: string) =>
useServerSuspenseQuery(playerQueries.stats(id));
export const useAllPlayerStats = () =>
- useServerSuspenseQuery(playerQueries.allStats());
\ No newline at end of file
+ useServerSuspenseQuery(playerQueries.allStats());
+
+export const usePlayerMatches = (id: string) =>
+ useServerSuspenseQuery(playerQueries.matches(id));
\ No newline at end of file
diff --git a/src/features/players/server.ts b/src/features/players/server.ts
index 0415379..785beca 100644
--- a/src/features/players/server.ts
+++ b/src/features/players/server.ts
@@ -1,6 +1,7 @@
import { setUserMetadata, superTokensFunctionMiddleware, getSessionContext } from "@/utils/supertokens";
import { createServerFn } from "@tanstack/react-start";
import { Player, playerInputSchema, playerUpdateSchema, PlayerStats } from "@/features/players/types";
+import { Match } from "@/features/matches/types";
import { pbAdmin } from "@/lib/pocketbase/client";
import { z } from "zod";
import { logger } from ".";
@@ -131,4 +132,11 @@ export const getAllPlayerStats = createServerFn()
.middleware([superTokensFunctionMiddleware])
.handler(async () =>
toServerResult
(async () => await pbAdmin.getAllPlayerStats())
+ );
+
+export const getPlayerMatches = createServerFn()
+ .validator(z.string())
+ .middleware([superTokensFunctionMiddleware])
+ .handler(async ({ data }) =>
+ toServerResult(async () => await pbAdmin.getPlayerMatches(data))
);
\ No newline at end of file
diff --git a/src/features/tournaments/components/tournament-list.tsx b/src/features/tournaments/components/tournament-list.tsx
index c32111d..5cbd99c 100644
--- a/src/features/tournaments/components/tournament-list.tsx
+++ b/src/features/tournaments/components/tournament-list.tsx
@@ -3,7 +3,7 @@ import { useNavigate } from "@tanstack/react-router";
import Avatar from "@/components/avatar";
import { TournamentInfo } from "../types";
import { useCallback } from "react";
-import { motion } from "framer-motion";
+import { motion, AnimatePresence } from "framer-motion";
import { TrophyIcon, CalendarIcon, MapPinIcon } from "@phosphor-icons/react";
interface TournamentListProps {
@@ -51,15 +51,17 @@ const TournamentList = ({ tournaments, loading = false }: TournamentListProps) =
return (
- {tournaments.map((tournament, index) => {
+
+ {tournaments.map((tournament, index) => {
const startDate = tournament.start_time ? new Date(tournament.start_time) : null;
return (
@@ -135,7 +137,8 @@ const TournamentList = ({ tournaments, loading = false }: TournamentListProps) =
);
- })}
+ })}
+
);
}
diff --git a/src/lib/pocketbase/services/players.ts b/src/lib/pocketbase/services/players.ts
index 74d2d2d..ca8680c 100644
--- a/src/lib/pocketbase/services/players.ts
+++ b/src/lib/pocketbase/services/players.ts
@@ -5,7 +5,8 @@ import type {
PlayerUpdateInput,
PlayerStats,
} from "@/features/players/types";
-import { transformPlayer, transformPlayerInfo } from "@/lib/pocketbase/util/transform-types";
+import type { Match } from "@/features/matches/types";
+import { transformPlayer, transformPlayerInfo, transformMatch } from "@/lib/pocketbase/util/transform-types";
import PocketBase from "pocketbase";
import { DataFetchOptions } from "./base";
@@ -77,5 +78,29 @@ export function createPlayersService(pb: PocketBase) {
});
return result;
},
+
+ async getPlayerMatches(playerId: string): Promise {
+ const player = await pb.collection("players").getOne(playerId, {
+ expand: "teams",
+ });
+
+ if (!player.expand?.teams || player.expand.teams.length === 0) {
+ return [];
+ }
+
+ const teamIds = Array.isArray(player.expand.teams)
+ ? player.expand.teams.map((team: any) => team.id)
+ : [player.expand.teams.id];
+
+ const teamFilter = teamIds.map(teamId => `home = "${teamId}" || away = "${teamId}"`).join(" || ");
+
+ const result = await pb.collection("matches").getFullList({
+ filter: `(${teamFilter}) && (status = "ended" || status = "started")`,
+ sort: "-created",
+ expand: "tournament,home,away",
+ });
+
+ return result.map(transformMatch);
+ },
};
}