regionals
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { playerQueries } from "@/features/players/queries";
|
||||
import PlayerStatsTable from "@/features/players/components/player-stats-table";
|
||||
import { Suspense } from "react";
|
||||
import { Suspense, useState, useDeferredValue } from "react";
|
||||
import PlayerStatsTableSkeleton from "@/features/players/components/player-stats-table-skeleton";
|
||||
import { prefetchServerQuery } from "@/lib/tanstack-query/utils/prefetch";
|
||||
import LeagueHeadToHead from "@/features/players/components/league-head-to-head";
|
||||
import { Box, Loader, Tabs } from "@mantine/core";
|
||||
import { Box, Loader, Tabs, Button, Group, Container, Stack } from "@mantine/core";
|
||||
|
||||
export const Route = createFileRoute("/_authed/stats")({
|
||||
component: Stats,
|
||||
beforeLoad: ({ context }) => {
|
||||
const queryClient = context.queryClient;
|
||||
prefetchServerQuery(queryClient, playerQueries.allStats());
|
||||
prefetchServerQuery(queryClient, playerQueries.allStats('all'));
|
||||
prefetchServerQuery(queryClient, playerQueries.allStats('mainline'));
|
||||
prefetchServerQuery(queryClient, playerQueries.allStats('regional'));
|
||||
},
|
||||
loader: () => ({
|
||||
withPadding: false,
|
||||
@@ -24,6 +26,10 @@ export const Route = createFileRoute("/_authed/stats")({
|
||||
});
|
||||
|
||||
function Stats() {
|
||||
const [viewType, setViewType] = useState<'all' | 'mainline' | 'regional'>('all');
|
||||
const deferredViewType = useDeferredValue(viewType);
|
||||
const isStale = viewType !== deferredViewType;
|
||||
|
||||
return (
|
||||
<Tabs defaultValue="stats">
|
||||
<Tabs.List grow>
|
||||
@@ -32,9 +38,38 @@ function Stats() {
|
||||
</Tabs.List>
|
||||
|
||||
<Tabs.Panel value="stats">
|
||||
<Suspense fallback={<PlayerStatsTableSkeleton />}>
|
||||
<PlayerStatsTable />
|
||||
</Suspense>
|
||||
<Container size="100%" px={0} mt="md">
|
||||
<Stack gap="xs">
|
||||
<Group gap="xs" px="md" justify="center">
|
||||
<Button
|
||||
variant={viewType === 'all' ? 'filled' : 'light'}
|
||||
size="compact-xs"
|
||||
onClick={() => setViewType('all')}
|
||||
>
|
||||
All
|
||||
</Button>
|
||||
<Button
|
||||
variant={viewType === 'mainline' ? 'filled' : 'light'}
|
||||
size="compact-xs"
|
||||
onClick={() => setViewType('mainline')}
|
||||
>
|
||||
Mainline
|
||||
</Button>
|
||||
<Button
|
||||
variant={viewType === 'regional' ? 'filled' : 'light'}
|
||||
size="compact-xs"
|
||||
onClick={() => setViewType('regional')}
|
||||
>
|
||||
Regional
|
||||
</Button>
|
||||
</Group>
|
||||
<Box style={{ opacity: isStale ? 0.6 : 1, transition: 'opacity 150ms' }}>
|
||||
<Suspense key={deferredViewType} fallback={<PlayerStatsTableSkeleton hideFilters />}>
|
||||
<PlayerStatsTable viewType={deferredViewType} />
|
||||
</Suspense>
|
||||
</Box>
|
||||
</Stack>
|
||||
</Container>
|
||||
</Tabs.Panel>
|
||||
|
||||
<Tabs.Panel value="h2h">
|
||||
|
||||
@@ -20,6 +20,7 @@ const MatchCard = ({ match, hideH2H = false }: MatchCardProps) => {
|
||||
const isHomeWin = match.home_cups > match.away_cups;
|
||||
const isAwayWin = match.away_cups > match.home_cups;
|
||||
const isStarted = match.status === "started";
|
||||
const hasPrivate = match.home?.private || match.away?.private;
|
||||
|
||||
const handleHomeTeamClick = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
@@ -65,13 +66,17 @@ const MatchCard = ({ match, hideH2H = false }: MatchCardProps) => {
|
||||
<Text size="xs" fw={600} lineClamp={1} c="dimmed">
|
||||
{match.tournament.name}
|
||||
</Text>
|
||||
<Text c="dimmed">-</Text>
|
||||
<Text size="xs" c="dimmed">
|
||||
Round {match.round + 1}
|
||||
{match.is_losers_bracket && " (Losers)"}
|
||||
</Text>
|
||||
{!match.tournament.regional && (
|
||||
<>
|
||||
<Text c="dimmed">-</Text>
|
||||
<Text size="xs" c="dimmed">
|
||||
Round {match.round + 1}
|
||||
{match.is_losers_bracket && " (Losers)"}
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
</Group>
|
||||
{match.home && match.away && !hideH2H && (
|
||||
{match.home && match.away && !hideH2H && !hasPrivate && (
|
||||
<Tooltip label="Head to Head" withArrow position="left">
|
||||
<ActionIcon
|
||||
variant="subtle"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Stack } from "@mantine/core";
|
||||
import { Stack, Text } from "@mantine/core";
|
||||
import { Match } from "../types";
|
||||
import MatchCard from "./match-card";
|
||||
|
||||
@@ -16,8 +16,15 @@ const MatchList = ({ matches, hideH2H = false }: MatchListProps) => {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const isRegional = filteredMatches[0]?.tournament?.regional;
|
||||
|
||||
return (
|
||||
<Stack p="md" gap="sm">
|
||||
{isRegional && (
|
||||
<Text size="xs" c="dimmed" ta="center" px="md">
|
||||
Matches for regionals are unordered
|
||||
</Text>
|
||||
)}
|
||||
{filteredMatches.map((match, index) => (
|
||||
<div
|
||||
key={`match-${match.id}-${index}`}
|
||||
|
||||
@@ -70,7 +70,11 @@ const PlayerListItemSkeleton = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const PlayerStatsTableSkeleton = () => {
|
||||
interface PlayerStatsTableSkeletonProps {
|
||||
hideFilters?: boolean;
|
||||
}
|
||||
|
||||
const PlayerStatsTableSkeleton = ({ hideFilters = false }: PlayerStatsTableSkeletonProps) => {
|
||||
return (
|
||||
<Container size="100%" px={0}>
|
||||
<Stack gap="xs">
|
||||
|
||||
@@ -142,8 +142,12 @@ const PlayerListItem = memo(({ stat, onPlayerClick, mmr, onRegisterViewport, onU
|
||||
);
|
||||
});
|
||||
|
||||
const PlayerStatsTable = () => {
|
||||
const { data: playerStats } = useAllPlayerStats();
|
||||
interface PlayerStatsTableProps {
|
||||
viewType?: 'all' | 'mainline' | 'regional';
|
||||
}
|
||||
|
||||
const PlayerStatsTable = ({ viewType = 'all' }: PlayerStatsTableProps) => {
|
||||
const { data: playerStats } = useAllPlayerStats(viewType);
|
||||
const navigate = useNavigate();
|
||||
const [search, setSearch] = useState("");
|
||||
const [sortConfig, setSortConfig] = useState<SortConfig>({
|
||||
@@ -292,21 +296,19 @@ const PlayerStatsTable = () => {
|
||||
|
||||
if (playerStats.length === 0) {
|
||||
return (
|
||||
<Container px={0} size="md">
|
||||
<Stack align="center" gap="md" py="xl">
|
||||
<ThemeIcon size="xl" variant="light" radius="md">
|
||||
<ChartBarIcon size={32} />
|
||||
</ThemeIcon>
|
||||
<Title order={3} c="dimmed">
|
||||
No Stats Available
|
||||
</Title>
|
||||
</Stack>
|
||||
</Container>
|
||||
<Stack align="center" gap="md" py="xl">
|
||||
<ThemeIcon size="xl" variant="light" radius="md">
|
||||
<ChartBarIcon size={32} />
|
||||
</ThemeIcon>
|
||||
<Title order={3} c="dimmed">
|
||||
No Stats Available
|
||||
</Title>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container size="100%" px={0} mt="md">
|
||||
<Container size="100%" px={0}>
|
||||
<Stack gap="xs">
|
||||
<Text px="md" size="10px" lh={0} c="dimmed">
|
||||
Showing {filteredAndSortedStats.length} of {playerStats.length} players
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Box, Stack, Text, Divider } from "@mantine/core";
|
||||
import { Suspense } from "react";
|
||||
import { Box, Stack, Text, Divider, Group, Button } from "@mantine/core";
|
||||
import { Suspense, useState, useDeferredValue } from "react";
|
||||
import Header from "./header";
|
||||
import SwipeableTabs from "@/components/swipeable-tabs";
|
||||
import { usePlayer, usePlayerMatches, usePlayerStats } from "../../queries";
|
||||
import TeamList from "@/features/teams/components/team-list";
|
||||
import StatsOverview from "@/components/stats-overview";
|
||||
import StatsOverview, { StatsSkeleton } from "@/components/stats-overview";
|
||||
import MatchList from "@/features/matches/components/match-list";
|
||||
import BadgeShowcase from "@/features/badges/components/badge-showcase";
|
||||
import BadgeShowcaseSkeleton from "@/features/badges/components/badge-showcase-skeleton";
|
||||
@@ -13,10 +13,38 @@ interface ProfileProps {
|
||||
id: string;
|
||||
}
|
||||
|
||||
const StatsWithFilter = ({ id }: { id: string }) => {
|
||||
const [viewType, setViewType] = useState<'all' | 'mainline' | 'regional'>('all');
|
||||
const deferredViewType = useDeferredValue(viewType);
|
||||
const isStale = viewType !== deferredViewType;
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
<Group gap="xs" px="md" justify="space-between" align="center">
|
||||
<Text size="md" fw={700}>Statistics</Text>
|
||||
<Group gap="xs">
|
||||
<Button variant={viewType === 'all' ? 'filled' : 'light'} size="compact-xs" onClick={() => setViewType('all')}>All</Button>
|
||||
<Button variant={viewType === 'mainline' ? 'filled' : 'light'} size="compact-xs" onClick={() => setViewType('mainline')}>Mainline</Button>
|
||||
<Button variant={viewType === 'regional' ? 'filled' : 'light'} size="compact-xs" onClick={() => setViewType('regional')}>Regional</Button>
|
||||
</Group>
|
||||
</Group>
|
||||
<Box style={{ opacity: isStale ? 0.6 : 1, transition: 'opacity 150ms' }}>
|
||||
<Suspense key={deferredViewType} fallback={<StatsSkeleton />}>
|
||||
<StatsContent id={id} viewType={deferredViewType} />
|
||||
</Suspense>
|
||||
</Box>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
const StatsContent = ({ id, viewType }: { id: string; viewType: 'all' | 'mainline' | 'regional' }) => {
|
||||
const { data: stats, isLoading: statsLoading } = usePlayerStats(id, viewType);
|
||||
return <StatsOverview statsData={stats} isLoading={statsLoading} />;
|
||||
};
|
||||
|
||||
const Profile = ({ id }: ProfileProps) => {
|
||||
const { data: player } = usePlayer(id);
|
||||
const { data: matches } = usePlayerMatches(id);
|
||||
const { data: stats, isLoading: statsLoading } = usePlayerStats(id);
|
||||
|
||||
const tabs = [
|
||||
{
|
||||
@@ -29,10 +57,7 @@ const Profile = ({ id }: ProfileProps) => {
|
||||
</Suspense>
|
||||
</Stack>
|
||||
<Divider my="md" />
|
||||
<Stack>
|
||||
<Text px="md" size="md" fw={700}>Statistics</Text>
|
||||
<StatsOverview statsData={stats} isLoading={statsLoading} />
|
||||
</Stack>
|
||||
<StatsWithFilter id={id} />
|
||||
</>,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -7,8 +7,8 @@ export const playerKeys = {
|
||||
details: (id: string) => ['players', 'details', id],
|
||||
unassociated: ['players','unassociated'],
|
||||
unenrolled: (tournamentId: string) => ['players', 'unenrolled', tournamentId],
|
||||
stats: (id: string) => ['players', 'stats', id],
|
||||
allStats: ['players', 'stats', 'all'],
|
||||
stats: (id: string, viewType?: 'all' | 'mainline' | 'regional') => ['players', 'stats', id, viewType ?? 'all'],
|
||||
allStats: (viewType?: 'all' | 'mainline' | 'regional') => ['players', 'stats', 'all', viewType ?? 'all'],
|
||||
matches: (id: string) => ['players', 'matches', id],
|
||||
activity: ['players', 'activity'],
|
||||
};
|
||||
@@ -34,13 +34,13 @@ export const playerQueries = {
|
||||
queryKey: playerKeys.unenrolled(tournamentId),
|
||||
queryFn: async () => await getUnenrolledPlayers({ data: tournamentId })
|
||||
}),
|
||||
stats: (id: string) => ({
|
||||
queryKey: playerKeys.stats(id),
|
||||
queryFn: async () => await getPlayerStats({ data: id })
|
||||
stats: (id: string, viewType?: 'all' | 'mainline' | 'regional') => ({
|
||||
queryKey: playerKeys.stats(id, viewType),
|
||||
queryFn: async () => await getPlayerStats({ data: { playerId: id, viewType } })
|
||||
}),
|
||||
allStats: () => ({
|
||||
queryKey: playerKeys.allStats,
|
||||
queryFn: async () => await getAllPlayerStats()
|
||||
allStats: (viewType?: 'all' | 'mainline' | 'regional') => ({
|
||||
queryKey: playerKeys.allStats(viewType),
|
||||
queryFn: async () => await getAllPlayerStats({ data: viewType })
|
||||
}),
|
||||
matches: (id: string) => ({
|
||||
queryKey: playerKeys.matches(id),
|
||||
@@ -84,11 +84,11 @@ export const usePlayers = () =>
|
||||
export const useUnassociatedPlayers = () =>
|
||||
useServerSuspenseQuery(playerQueries.unassociated());
|
||||
|
||||
export const usePlayerStats = (id: string) =>
|
||||
useServerSuspenseQuery(playerQueries.stats(id));
|
||||
export const usePlayerStats = (id: string, viewType?: 'all' | 'mainline' | 'regional') =>
|
||||
useServerSuspenseQuery(playerQueries.stats(id, viewType));
|
||||
|
||||
export const useAllPlayerStats = () =>
|
||||
useServerSuspenseQuery(playerQueries.allStats());
|
||||
export const useAllPlayerStats = (viewType?: 'all' | 'mainline' | 'regional') =>
|
||||
useServerSuspenseQuery(playerQueries.allStats(viewType));
|
||||
|
||||
export const usePlayerMatches = (id: string) =>
|
||||
useServerSuspenseQuery(playerQueries.matches(id));
|
||||
|
||||
@@ -136,16 +136,20 @@ export const getUnassociatedPlayers = createServerFn()
|
||||
);
|
||||
|
||||
export const getPlayerStats = createServerFn()
|
||||
.inputValidator(z.string())
|
||||
.inputValidator(z.object({
|
||||
playerId: z.string(),
|
||||
viewType: z.enum(['all', 'mainline', 'regional']).optional()
|
||||
}))
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
.handler(async ({ data }) =>
|
||||
toServerResult<PlayerStats>(async () => await pbAdmin.getPlayerStats(data))
|
||||
toServerResult<PlayerStats>(async () => await pbAdmin.getPlayerStats(data.playerId, data.viewType))
|
||||
);
|
||||
|
||||
export const getAllPlayerStats = createServerFn()
|
||||
.inputValidator(z.enum(['all', 'mainline', 'regional']).optional())
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
.handler(async () =>
|
||||
toServerResult<PlayerStats[]>(async () => await pbAdmin.getAllPlayerStats())
|
||||
.handler(async ({ data }) =>
|
||||
toServerResult<PlayerStats[]>(async () => await pbAdmin.getAllPlayerStats(data))
|
||||
);
|
||||
|
||||
export const getPlayerMatches = createServerFn()
|
||||
|
||||
@@ -55,10 +55,10 @@ const TeamList = ({ teams, loading = false, onTeamClick }: TeamListProps) => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleClick = useCallback(
|
||||
(teamId: string) => {
|
||||
(teamId: string, priv: boolean) => {
|
||||
if (onTeamClick) {
|
||||
onTeamClick(teamId);
|
||||
} else {
|
||||
} else if (!priv) {
|
||||
navigate({ to: `/teams/${teamId}` });
|
||||
}
|
||||
},
|
||||
@@ -100,7 +100,7 @@ const TeamList = ({ teams, loading = false, onTeamClick }: TeamListProps) => {
|
||||
/>
|
||||
}
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() => handleClick(team.id)}
|
||||
onClick={() => handleClick(team.id, team.private)}
|
||||
styles={{
|
||||
itemWrapper: { width: "100%" },
|
||||
itemLabel: { width: "100%" },
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface Team {
|
||||
updated: string;
|
||||
players: PlayerInfo[];
|
||||
tournaments: TournamentInfo[];
|
||||
private: boolean;
|
||||
}
|
||||
|
||||
export interface TeamInfo {
|
||||
@@ -28,6 +29,7 @@ export interface TeamInfo {
|
||||
accent_color: string;
|
||||
logo?: string;
|
||||
players: PlayerInfo[];
|
||||
private: boolean;
|
||||
}
|
||||
|
||||
export const teamInputSchema = z
|
||||
|
||||
@@ -58,7 +58,7 @@ export const TournamentCard = ({ tournament }: TournamentCardProps) => {
|
||||
<Title mb={-6} order={3} lineClamp={2}>
|
||||
{tournament.name}
|
||||
</Title>
|
||||
{(tournament.first_place || tournament.second_place || tournament.third_place) && (
|
||||
{((tournament.first_place || tournament.second_place || tournament.third_place) && !tournament.regional) && (
|
||||
<Stack gap={6} >
|
||||
{tournament.first_place && (
|
||||
<Badge
|
||||
|
||||
@@ -9,9 +9,10 @@ import {
|
||||
Center,
|
||||
ThemeIcon,
|
||||
Divider,
|
||||
Alert,
|
||||
} from "@mantine/core";
|
||||
import { Tournament } from "@/features/tournaments/types";
|
||||
import { CrownIcon, MedalIcon, TreeStructureIcon } from "@phosphor-icons/react";
|
||||
import { CrownIcon, TreeStructureIcon, InfoIcon } from "@phosphor-icons/react";
|
||||
import Avatar from "@/components/avatar";
|
||||
import ListLink from "@/components/list-link";
|
||||
import { Podium } from "./podium";
|
||||
@@ -156,7 +157,12 @@ export const TournamentStats = memo(({ tournament }: TournamentStatsProps) => {
|
||||
return (
|
||||
<Container size="100%" px={0}>
|
||||
<Stack gap="md">
|
||||
<Podium tournament={tournament} />
|
||||
{tournament.regional && (
|
||||
<Alert px="md" variant="light" title="Regional Tournament" icon={<InfoIcon size={16} />}>
|
||||
Regional tournaments are a work in progress. Some features might not work as expected.
|
||||
</Alert>
|
||||
)}
|
||||
{!tournament.regional && <Podium tournament={tournament} />}
|
||||
<ListLink
|
||||
label={`View Bracket`}
|
||||
to={`/tournaments/${tournament.id}/bracket`}
|
||||
|
||||
@@ -29,6 +29,7 @@ export interface TournamentInfo {
|
||||
first_place?: TeamInfo;
|
||||
second_place?: TeamInfo;
|
||||
third_place?: TeamInfo;
|
||||
regional?: boolean;
|
||||
}
|
||||
|
||||
export interface Tournament {
|
||||
@@ -50,6 +51,7 @@ export interface Tournament {
|
||||
second_place?: TeamInfo;
|
||||
third_place?: TeamInfo;
|
||||
team_stats?: TournamentTeamStats[];
|
||||
regional?: boolean;
|
||||
}
|
||||
|
||||
export const tournamentInputSchema = z.object({
|
||||
|
||||
@@ -91,7 +91,7 @@ export function createBadgesService(pb: PocketBase) {
|
||||
async calculateMatchBadgeProgress(playerId: string, badge: Badge): Promise<number> {
|
||||
const criteria = badge.criteria;
|
||||
|
||||
const stats = await pb.collection("player_stats").getFirstListItem<PlayerStats>(
|
||||
const stats = await pb.collection("player_mainline_stats").getFirstListItem<PlayerStats>(
|
||||
`player_id = "${playerId}"`
|
||||
).catch(() => null);
|
||||
|
||||
@@ -103,8 +103,8 @@ export function createBadgesService(pb: PocketBase) {
|
||||
|
||||
if (criteria.overtime_matches !== undefined || criteria.overtime_wins !== undefined) {
|
||||
const matches = await pb.collection("matches").getFullList({
|
||||
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended" && ot_count > 0`,
|
||||
expand: 'home,away,home.players,away.players',
|
||||
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended" && ot_count > 0 && (tournament.regional = false || tournament.regional = null)`,
|
||||
expand: 'tournament,home,away,home.players,away.players',
|
||||
});
|
||||
|
||||
if (criteria.overtime_matches !== undefined) {
|
||||
@@ -131,8 +131,8 @@ export function createBadgesService(pb: PocketBase) {
|
||||
|
||||
if (criteria.margin_of_victory !== undefined) {
|
||||
const matches = await pb.collection("matches").getFullList({
|
||||
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended"`,
|
||||
expand: 'home,away,home.players,away.players',
|
||||
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended" && (tournament.regional = false || tournament.regional = null)`,
|
||||
expand: 'tournament,home,away,home.players,away.players',
|
||||
});
|
||||
|
||||
const bigWins = matches.filter(m => {
|
||||
@@ -159,7 +159,7 @@ export function createBadgesService(pb: PocketBase) {
|
||||
const criteria = badge.criteria;
|
||||
|
||||
const matches = await pb.collection("matches").getFullList({
|
||||
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended"`,
|
||||
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended" && (tournament.regional = false || tournament.regional = null)`,
|
||||
expand: 'tournament,home,away,home.players,away.players',
|
||||
});
|
||||
|
||||
@@ -209,8 +209,8 @@ export function createBadgesService(pb: PocketBase) {
|
||||
|
||||
for (const tournamentId of tournamentIds) {
|
||||
const tournamentMatches = await pb.collection("matches").getFullList({
|
||||
filter: `tournament = "${tournamentId}" && status = "ended"`,
|
||||
expand: 'home,away,home.players,away.players',
|
||||
filter: `tournament = "${tournamentId}" && status = "ended" && (tournament.regional = false || tournament.regional = null)`,
|
||||
expand: 'tournament,home,away,home.players,away.players',
|
||||
});
|
||||
|
||||
const winnersMatches = tournamentMatches.filter(m => !m.is_losers_bracket);
|
||||
@@ -241,8 +241,8 @@ export function createBadgesService(pb: PocketBase) {
|
||||
|
||||
for (const tournamentId of tournamentIds) {
|
||||
const tournamentMatches = await pb.collection("matches").getFullList({
|
||||
filter: `tournament = "${tournamentId}" && status = "ended"`,
|
||||
expand: 'home,away,home.players,away.players',
|
||||
filter: `tournament = "${tournamentId}" && status = "ended" && (tournament.regional = false || tournament.regional = null)`,
|
||||
expand: 'tournament,home,away,home.players,away.players',
|
||||
});
|
||||
|
||||
if (criteria.placement === 2) {
|
||||
@@ -293,6 +293,7 @@ export function createBadgesService(pb: PocketBase) {
|
||||
|
||||
if (criteria.tournament_record !== undefined) {
|
||||
const tournaments = await pb.collection("tournaments").getFullList({
|
||||
filter: 'regional = false || regional = null',
|
||||
sort: 'start_time',
|
||||
});
|
||||
|
||||
@@ -344,6 +345,7 @@ export function createBadgesService(pb: PocketBase) {
|
||||
|
||||
if (criteria.consecutive_wins !== undefined) {
|
||||
const tournaments = await pb.collection("tournaments").getFullList({
|
||||
filter: 'regional = false || regional = null',
|
||||
sort: 'start_time',
|
||||
});
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ export function createMatchesService(pb: PocketBase) {
|
||||
},
|
||||
|
||||
async createMatch(data: MatchInput): Promise<Match> {
|
||||
logger.info("PocketBase | Creating match", data);
|
||||
// logger.info("PocketBase | Creating match", data);
|
||||
const result = await pb.collection("matches").create<Match>(data);
|
||||
return result;
|
||||
},
|
||||
@@ -92,23 +92,40 @@ export function createMatchesService(pb: PocketBase) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const filterConditions: string[] = [];
|
||||
player1TeamIds.forEach(team1Id => {
|
||||
player2TeamIds.forEach(team2Id => {
|
||||
filterConditions.push(`(home="${team1Id}" && away="${team2Id}")`);
|
||||
filterConditions.push(`(home="${team2Id}" && away="${team1Id}")`);
|
||||
const allTeamIds = [...new Set([...player1TeamIds, ...player2TeamIds])];
|
||||
const batchSize = 10;
|
||||
const allMatches: any[] = [];
|
||||
|
||||
for (let i = 0; i < allTeamIds.length; i += batchSize) {
|
||||
const batch = allTeamIds.slice(i, i + batchSize);
|
||||
const teamFilters = batch.map(id => `home="${id}" || away="${id}"`).join(' || ');
|
||||
|
||||
const results = await pb.collection("matches").getFullList({
|
||||
filter: teamFilters,
|
||||
expand: "tournament, home, away, home.players, away.players",
|
||||
sort: "-created",
|
||||
});
|
||||
});
|
||||
|
||||
const filter = filterConditions.join(" || ");
|
||||
allMatches.push(...results);
|
||||
}
|
||||
|
||||
const results = await pb.collection("matches").getFullList({
|
||||
filter,
|
||||
expand: "tournament, home, away, home.players, away.players",
|
||||
sort: "-created",
|
||||
});
|
||||
const uniqueMatches = Array.from(
|
||||
new Map(allMatches.map(m => [m.id, m])).values()
|
||||
);
|
||||
|
||||
return results.map(match => transformMatch(match));
|
||||
return uniqueMatches
|
||||
.filter(match => {
|
||||
const homeTeamId = typeof match.home === 'string' ? match.home : match.home?.id;
|
||||
const awayTeamId = typeof match.away === 'string' ? match.away : match.away?.id;
|
||||
|
||||
const player1InHome = player1TeamIds.includes(homeTeamId);
|
||||
const player1InAway = player1TeamIds.includes(awayTeamId);
|
||||
const player2InHome = player2TeamIds.includes(homeTeamId);
|
||||
const player2InAway = player2TeamIds.includes(awayTeamId);
|
||||
|
||||
return (player1InHome && player2InAway) || (player1InAway && player2InHome);
|
||||
})
|
||||
.map(match => transformMatch(match));
|
||||
},
|
||||
|
||||
async getMatchesBetweenTeams(team1Id: string, team2Id: string): Promise<Match[]> {
|
||||
|
||||
@@ -8,7 +8,6 @@ import type {
|
||||
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";
|
||||
|
||||
export function createPlayersService(pb: PocketBase) {
|
||||
return {
|
||||
@@ -65,9 +64,15 @@ export function createPlayersService(pb: PocketBase) {
|
||||
return result.map(transformPlayer);
|
||||
},
|
||||
|
||||
async getPlayerStats(playerId: string): Promise<PlayerStats> {
|
||||
async getPlayerStats(playerId: string, viewType: 'all' | 'mainline' | 'regional' = 'all'): Promise<PlayerStats> {
|
||||
try {
|
||||
const result = await pb.collection("player_stats").getFirstListItem<PlayerStats>(
|
||||
const collectionMap = {
|
||||
all: 'player_stats',
|
||||
mainline: 'player_mainline_stats',
|
||||
regional: 'player_regional_stats',
|
||||
};
|
||||
|
||||
const result = await pb.collection(collectionMap[viewType]).getFirstListItem<PlayerStats>(
|
||||
`player_id = "${playerId}"`
|
||||
);
|
||||
return result;
|
||||
@@ -90,8 +95,14 @@ export function createPlayersService(pb: PocketBase) {
|
||||
}
|
||||
},
|
||||
|
||||
async getAllPlayerStats(): Promise<PlayerStats[]> {
|
||||
const result = await pb.collection("player_stats").getFullList<PlayerStats>({
|
||||
async getAllPlayerStats(viewType: 'all' | 'mainline' | 'regional' = 'all'): Promise<PlayerStats[]> {
|
||||
const collectionMap = {
|
||||
all: 'player_stats',
|
||||
mainline: 'player_mainline_stats',
|
||||
regional: 'player_regional_stats',
|
||||
};
|
||||
|
||||
const result = await pb.collection(collectionMap[viewType]).getFullList<PlayerStats>({
|
||||
sort: "-win_percentage,-total_cups_made",
|
||||
});
|
||||
return result;
|
||||
|
||||
@@ -34,7 +34,7 @@ export function createTournamentsService(pb: PocketBase) {
|
||||
.getFirstListItem('',
|
||||
{
|
||||
expand: "teams, teams.players, matches, matches.tournament, matches.home, matches.away, matches.home.players, matches.away.players",
|
||||
sort: "-created",
|
||||
sort: "-start_time",
|
||||
}
|
||||
);
|
||||
|
||||
@@ -52,7 +52,7 @@ export function createTournamentsService(pb: PocketBase) {
|
||||
.collection("tournaments")
|
||||
.getFullList({
|
||||
expand: "teams,teams.players,matches",
|
||||
sort: "-created",
|
||||
sort: "-start_time",
|
||||
});
|
||||
|
||||
const tournamentsWithStats = await Promise.all(result.map(async (tournament) => {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Reaction } from "@/features/matches/server";
|
||||
import { Match } from "@/features/matches/types";
|
||||
import { Player, PlayerInfo } from "@/features/players/types";
|
||||
import { Team, TeamInfo } from "@/features/teams/types";
|
||||
@@ -25,7 +24,8 @@ export function transformTeamInfo(record: any): TeamInfo {
|
||||
primary_color: record.primary_color,
|
||||
accent_color: record.accent_color,
|
||||
players,
|
||||
logo: record.logo
|
||||
logo: record.logo,
|
||||
private: record.private || false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@ export const transformTournamentInfo = (record: any): TournamentInfo => {
|
||||
end_time: record.end_time,
|
||||
logo: record.logo,
|
||||
glitch_logo: record.glitch_logo,
|
||||
regional: record.regional || false,
|
||||
first_place,
|
||||
second_place,
|
||||
third_place,
|
||||
@@ -116,6 +117,7 @@ export const transformTournamentInfo = (record: any): TournamentInfo => {
|
||||
export function transformPlayer(record: any): Player {
|
||||
const teams =
|
||||
record.expand?.teams
|
||||
?.filter((team: any) => !team.private)
|
||||
?.sort((a: any, b: any) =>
|
||||
new Date(a.created) < new Date(b.created) ? -1 : 0
|
||||
)
|
||||
@@ -135,13 +137,6 @@ export function transformPlayer(record: any): Player {
|
||||
|
||||
export function transformFreeAgent(record: any) {
|
||||
const player = record.expand?.player ? transformPlayerInfo(record.expand.player) : undefined;
|
||||
const tournaments =
|
||||
record.expand?.tournaments
|
||||
?.sort((a: any, b: any) =>
|
||||
new Date(a.created!) < new Date(b.created!) ? -1 : 0
|
||||
)
|
||||
?.map(transformTournamentInfo) ?? [];
|
||||
|
||||
return {
|
||||
id: record.id as string,
|
||||
phone: record.phone as string,
|
||||
@@ -180,6 +175,7 @@ export function transformTeam(record: any): Team {
|
||||
updated: record.updated,
|
||||
players,
|
||||
tournaments,
|
||||
private: record.private || false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -264,6 +260,7 @@ export function transformTournament(record: any, isAdmin: boolean = false): Tour
|
||||
end_time: record.end_time,
|
||||
created: record.created,
|
||||
updated: record.updated,
|
||||
regional: record.regional || false,
|
||||
teams,
|
||||
matches,
|
||||
first_place,
|
||||
|
||||
Reference in New Issue
Block a user