Skip to content

Commit

Permalink
Improve round robing handling (#699)
Browse files Browse the repository at this point in the history
fix #695
  • Loading branch information
evroon committed May 5, 2024
1 parent 4ab77af commit 24f04fb
Show file tree
Hide file tree
Showing 20 changed files with 747 additions and 314 deletions.
15 changes: 2 additions & 13 deletions docs/src/components/HeroTitle/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { Container, Text, Button, Group, Center } from "@mantine/core";
import { GithubIcon } from "@mantinex/dev-icons";
import { Button, Center, Container, Group, Text } from "@mantine/core";
import classes from "./styles.module.css";
import React from "react";
import {
IconBracketsContainStart,
IconLibrary,
IconLivePhoto,
IconLiveView,
IconPlayCard,
IconPlayerPlay,
IconRocket,
IconRun,
IconStar,
} from "@tabler/icons-react";
import { IconLibrary, IconRocket } from "@tabler/icons-react";

export function HeroTitle() {
return (
Expand Down
9 changes: 1 addition & 8 deletions docs/src/components/feature_cards.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
Card,
Container,
rem,
SimpleGrid,
Text,
useMantineTheme,
} from "@mantine/core";
import { Card, Container, rem, SimpleGrid, Text } from "@mantine/core";
import {
IconBrandOpenSource,
IconCloud,
Expand Down
5 changes: 2 additions & 3 deletions docs/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ import {
MantineProvider,
Paper,
rem,
ThemeIcon,
Text,
ThemeIcon,
Title,
Stack,
} from "@mantine/core";
import "@mantine/core/styles.css";
import "@mantine/carousel/styles.css";
import { HeroTitle } from "../components/HeroTitle";
import { HomeCarousel } from "../components/HomeCarousel";
import classes from "./index.module.css";
import FeaturesCards from "../components/feature_cards";
import { IconBrandGithub, IconColorSwatch } from "@tabler/icons-react";
import { IconBrandGithub } from "@tabler/icons-react";

const theme = createTheme({});

Expand Down
30 changes: 15 additions & 15 deletions frontend/public/favicon-wide.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion frontend/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"filter_stage_item_placeholder": "No filter",
"forgot_password_button": "Forgot password?",
"github_title": "Github",
"handle_swiss_system": "Handle Swiss System",
"home_spotlight_description": "Get to home page",
"home_title": "Home",
"inactive": "Inactive",
Expand Down Expand Up @@ -169,6 +170,8 @@
"recommended_badge_title": "Recommended",
"remove_logo": "Remove logo",
"remove_match_button": "Remove Match",
"results_spotlight_description": "Enter scores of matches",
"results_title": "Results",
"round_name_input_placeholder": "Best Round Ever",
"round_robin_label": "Round Robin",
"save_button": "Save",
Expand Down Expand Up @@ -213,8 +216,8 @@
"tournament_title": "tournament",
"tournaments_title": "tournaments",
"upcoming_matches_empty_table_info": "upcoming matches",
"upload_placeholder_tournament": "Drop a file here to upload as tournament logo.",
"upload_placeholder_team": "Drop a file here to upload as team logo.",
"upload_placeholder_tournament": "Drop a file here to upload as tournament logo.",
"uppercase_required": "Includes uppercase letter",
"user_settings_spotlight_description": "Change name, email, password etc.",
"user_settings_title": "User Settings",
Expand Down
61 changes: 12 additions & 49 deletions frontend/src/components/brackets/brackets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { SWRResponse } from 'swr';

import { BracketDisplaySettings } from '../../interfaces/brackets';
import { RoundInterface } from '../../interfaces/round';
import { StageWithStageItems } from '../../interfaces/stage';
import { StageItemWithRounds, stageItemIsHandledAutomatically } from '../../interfaces/stage_item';
import { TournamentMinimal } from '../../interfaces/tournament';
import { createRound } from '../../services/round';
Expand Down Expand Up @@ -60,9 +59,7 @@ function getRoundsGridCols(
<React.Fragment key={stageItem.id}>
<div style={{ width: '100%' }}>
<Grid grow>
<Grid.Col span={6}>
<h2>{stageItem.name}</h2>
</Grid.Col>
<Grid.Col span={6}></Grid.Col>
<Grid.Col span={6}>
<Group justify="right">
{hideAddRoundButton ? null : (
Expand Down Expand Up @@ -123,23 +120,6 @@ function NoRoundsAlert({ readOnly }: { readOnly: boolean }) {
);
}

function NotStartedAlert() {
const { t } = useTranslation();

return (
<Container>
<Alert
icon={<IconAlertCircle size={16} />}
title={t('tournament_not_started_title')}
color="blue"
radius="lg"
>
{t('tournament_not_started_description')}
</Alert>
</Container>
);
}

function LoadingSkeleton() {
return (
<Group>
Expand All @@ -158,55 +138,38 @@ export default function Brackets({
swrStagesResponse,
swrUpcomingMatchesResponse,
readOnly,
selectedStageId,
displaySettings,
stageItem,
}: {
tournamentData: TournamentMinimal;
swrStagesResponse: SWRResponse;
swrUpcomingMatchesResponse: SWRResponse | null;
readOnly: boolean;
selectedStageId: string | null;
displaySettings: BracketDisplaySettings;
stageItem: StageItemWithRounds;
}) {
const { t } = useTranslation();

if (swrStagesResponse.isLoading) {
return <LoadingSkeleton />;
}
if (selectedStageId == null) {
return <NotStartedAlert />;
}
if (
selectedStageId == null ||
(!swrStagesResponse.isLoading && !responseIsValid(swrStagesResponse))
) {
if (!swrStagesResponse.isLoading && !responseIsValid(swrStagesResponse)) {
return <NoRoundsAlert readOnly={readOnly} />;
}

if (swrStagesResponse.isLoading) {
return <LoadingSkeleton />;
}

const stages_map = Object.fromEntries(
swrStagesResponse.data.data.map((x: StageWithStageItems) => [x.id, x])
const rounds = getRoundsGridCols(
t,
stageItem,
tournamentData,
swrStagesResponse,
swrUpcomingMatchesResponse,
readOnly,
displaySettings
);
const rounds = stages_map[selectedStageId].stage_items
.sort((i1: StageItemWithRounds, i2: StageItemWithRounds) => (i1.name > i2.name ? 1 : -1))
.map((stageItem: StageItemWithRounds) =>
getRoundsGridCols(
t,
stageItem,
tournamentData,
swrStagesResponse,
swrUpcomingMatchesResponse,
readOnly,
displaySettings
)
);

if (rounds.length < 1) {
return <NoRoundsAlert readOnly={readOnly} />;
}

return <div>{rounds}</div>;
}
13 changes: 13 additions & 0 deletions frontend/src/components/builder/builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { ActionIcon, Badge, Card, Group, Menu, Stack, Text, rem } from '@mantine
import { IconDots, IconPencil, IconTrash } from '@tabler/icons-react';
import assert from 'assert';
import { useTranslation } from 'next-i18next';
import { useRouter } from 'next/router';
import React, { useState } from 'react';
import { BiSolidWrench } from 'react-icons/bi';
import { SWRResponse } from 'swr';

import { StageWithStageItems } from '../../interfaces/stage';
Expand Down Expand Up @@ -56,6 +58,7 @@ function StageItemRow({
stageItem: StageItemWithRounds;
swrStagesResponse: SWRResponse;
}) {
const router = useRouter();
const { t } = useTranslation();
const [opened, setOpened] = useState(false);
const stageItemsLookup = getStageItemLookup(swrStagesResponse);
Expand Down Expand Up @@ -107,6 +110,16 @@ function StageItemRow({
>
{t('edit_name_button')}
</Menu.Item>
{stageItem.type === 'SWISS' ? (
<Menu.Item
leftSection={<BiSolidWrench size={rem(14)} />}
onClick={() => {
router.push(`/tournaments/${tournament.id}/swiss/${stageItem.id}`);
}}
>
{t('handle_swiss_system')}
</Menu.Item>
) : null}
<Menu.Item
leftSection={<IconTrash size={rem(14)} />}
onClick={async () => {
Expand Down
Loading

0 comments on commit 24f04fb

Please sign in to comment.