mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-09 04:36:02 -05:00
Sub counts clean up
This commit is contained in:
@@ -581,7 +581,7 @@ export interface TournamentSub {
|
||||
okWeapons: string | null;
|
||||
tournamentId: number;
|
||||
userId: number;
|
||||
visibility: string;
|
||||
visibility: "+1" | "+2" | "+3" | "ALL";
|
||||
}
|
||||
|
||||
export interface TournamentStaff {
|
||||
|
||||
@@ -2029,6 +2029,7 @@ export const PADDLING_POOL_257 = () =>
|
||||
logoUrl: null,
|
||||
logoSrc: "/test.png",
|
||||
avatarImgId: null,
|
||||
subCounts: [],
|
||||
startTime: 1709748000,
|
||||
author: {
|
||||
id: 860,
|
||||
@@ -7733,6 +7734,7 @@ export const PADDLING_POOL_255 = () =>
|
||||
logoUrl: null,
|
||||
logoSrc: "/test.png",
|
||||
avatarImgId: null,
|
||||
subCounts: [],
|
||||
startTime: 1708538400,
|
||||
author: {
|
||||
id: 860,
|
||||
@@ -13759,6 +13761,7 @@ export const IN_THE_ZONE_32 = () =>
|
||||
logoUrl: null,
|
||||
logoSrc: "/test.png",
|
||||
avatarImgId: null,
|
||||
subCounts: [],
|
||||
startTime: 1707588000,
|
||||
author: {
|
||||
id: 274,
|
||||
|
||||
@@ -59,6 +59,7 @@ export const testTournament = (
|
||||
isFinalized: 0,
|
||||
name: "test",
|
||||
castTwitchAccounts: [],
|
||||
subCounts: [],
|
||||
staff: [],
|
||||
tieBreakerMapPool: [],
|
||||
participatedUsers: [],
|
||||
|
||||
@@ -56,6 +56,16 @@ export async function findById(id: number) {
|
||||
])
|
||||
.where("TournamentStaff.tournamentId", "=", id),
|
||||
).as("staff"),
|
||||
jsonArrayFrom(
|
||||
eb
|
||||
.selectFrom("TournamentSub")
|
||||
.select(({ fn }) => [
|
||||
"TournamentSub.visibility",
|
||||
fn.countAll<number>().as("count"),
|
||||
])
|
||||
.where("TournamentSub.tournamentId", "=", id)
|
||||
.groupBy("TournamentSub.visibility"),
|
||||
).as("subCounts"),
|
||||
exists(
|
||||
selectFrom("TournamentResult")
|
||||
.where("TournamentResult.tournamentId", "=", id)
|
||||
|
||||
@@ -18,7 +18,6 @@ import { useUser } from "~/features/auth/core/user";
|
||||
import { getUser } from "~/features/auth/core/user.server";
|
||||
import { Tournament } from "~/features/tournament-bracket/core/Tournament";
|
||||
import { tournamentData } from "~/features/tournament-bracket/core/Tournament.server";
|
||||
import { findSubsByTournamentId } from "~/features/tournament-subs";
|
||||
import { type SendouRouteHandle } from "~/utils/remix";
|
||||
import { makeTitle } from "~/utils/strings";
|
||||
import { assertUnreachable } from "~/utils/types";
|
||||
@@ -114,31 +113,6 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
|
||||
const user = await getUser(request);
|
||||
const tournamentId = tournamentIdFromParams(params);
|
||||
|
||||
const subsCount = findSubsByTournamentId({
|
||||
tournamentId,
|
||||
userId: user?.id,
|
||||
// eslint-disable-next-line array-callback-return
|
||||
}).filter((sub) => {
|
||||
if (sub.visibility === "ALL") return true;
|
||||
|
||||
const userPlusTier = user?.plusTier ?? 4;
|
||||
|
||||
switch (sub.visibility) {
|
||||
case "+1": {
|
||||
return userPlusTier === 1;
|
||||
}
|
||||
case "+2": {
|
||||
return userPlusTier <= 2;
|
||||
}
|
||||
case "+3": {
|
||||
return userPlusTier <= 3;
|
||||
}
|
||||
default: {
|
||||
assertUnreachable(sub.visibility);
|
||||
}
|
||||
}
|
||||
}).length;
|
||||
|
||||
const tournament = await tournamentData({ tournamentId, user });
|
||||
|
||||
const streams =
|
||||
@@ -162,7 +136,6 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
|
||||
|
||||
return {
|
||||
tournament,
|
||||
subsCount,
|
||||
streamingParticipants: streams.flatMap((s) => (s.userId ? [s.userId] : [])),
|
||||
streamsCount: streams.length,
|
||||
toSetMapPool:
|
||||
@@ -202,6 +175,28 @@ export default function TournamentLayout() {
|
||||
|
||||
const onBracketsPage = location.pathname.includes("brackets");
|
||||
|
||||
const subsCount = () =>
|
||||
tournament.ctx.subCounts.reduce((acc, cur) => {
|
||||
if (cur.visibility === "ALL") return acc + cur.count;
|
||||
|
||||
const userPlusTier = user?.plusTier ?? 4;
|
||||
|
||||
switch (cur.visibility) {
|
||||
case "+1": {
|
||||
return userPlusTier === 1 ? acc + cur.count : acc;
|
||||
}
|
||||
case "+2": {
|
||||
return userPlusTier <= 2 ? acc + cur.count : acc;
|
||||
}
|
||||
case "+3": {
|
||||
return userPlusTier <= 3 ? acc + cur.count : acc;
|
||||
}
|
||||
default: {
|
||||
assertUnreachable(cur.visibility);
|
||||
}
|
||||
}
|
||||
}, 0);
|
||||
|
||||
return (
|
||||
<Main bigger={onBracketsPage}>
|
||||
<SubNav>
|
||||
@@ -216,7 +211,7 @@ export default function TournamentLayout() {
|
||||
</SubNavLink>
|
||||
{!tournament.everyBracketOver && tournament.subsFeatureEnabled && (
|
||||
<SubNavLink to="subs" end={false}>
|
||||
{t("tournament:tabs.subs", { count: data.subsCount })}
|
||||
{t("tournament:tabs.subs", { count: subsCount() })}
|
||||
</SubNavLink>
|
||||
)}
|
||||
{tournament.hasStarted && !tournament.everyBracketOver ? (
|
||||
|
||||
Reference in New Issue
Block a user