Skip to content

Commit

Permalink
fixup! fixup! Feature: archived tournaments
Browse files Browse the repository at this point in the history
  • Loading branch information
evroon committed Feb 9, 2025
1 parent eea505e commit fd5272b
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 32 deletions.
2 changes: 1 addition & 1 deletion backend/bracket/routes/tournaments.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def get_tournament(
@router.get("/tournaments", response_model=TournamentsResponse)
async def get_tournaments(
user: UserPublic | None = Depends(user_authenticated_or_public_dashboard_by_endpoint_name),
filter_: Literal["all", "open", "archived"] = "open",
filter_: Literal["ALL", "OPEN", "ARCHIVED"] = "OPEN",
endpoint_name: str | None = None,
) -> TournamentsResponse:
match user, endpoint_name:
Expand Down
6 changes: 3 additions & 3 deletions backend/bracket/sql/tournaments.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def sql_get_tournament_by_endpoint_name(endpoint_name: str) -> Tournament
async def sql_get_tournaments(
club_ids: tuple[int, ...],
endpoint_name: str | None = None,
filter_: Literal["all", "open", "archived"] = "open",
filter_: Literal["ALL", "OPEN", "ARCHIVED"] = "ALL",
) -> list[Tournament]:
query = """
SELECT *
Expand All @@ -49,9 +49,9 @@ async def sql_get_tournaments(
query += "AND dashboard_endpoint = :endpoint_name"
params = {**params, "endpoint_name": endpoint_name}

if filter_ == "open":
if filter_ == "OPEN":
query += "AND status = 'OPEN'"
elif filter_ == "archived":
elif filter_ == "ARCHIVED":
query += "AND status = 'ARCHIVED'"

result = await database.fetch_all(query=query, values=params)
Expand Down
17 changes: 9 additions & 8 deletions frontend/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
"add_team_button": "Add Team",
"adjust_start_times_checkbox_label": "Adjust start time of matches in this round to the current time",
"all_matches_radio_label": "All matches",
"all_matches_scheduled_description": "Matches have been scheduled on all courts in this round. Add a new round or add a new court for more matches.",
"api_docs_title": "API docs",
"mark_round_as_non_draft": "Mark this round as ready",
"mark_round_as_draft": "Mark this round as draft",
"archive_tournament_button": "Archive Tournament",
"archived_label": "Archived",
"at_least_one_player_validation": "Enter at least one player",
"at_least_one_team_validation": "Enter at least one team",
"at_least_two_team_validation": "Need at least two teams",
"auto_assign_courts_label": "Automatically assign courts to matches",
"auto_create_matches_button": "Plan new round automatically",
"courts_filled_badge": "courts filled",
"back_home_nav": "Take me back to home page",
"back_to_login_nav": "Back to login page",
"checkbox_status_checked": "Checked",
Expand All @@ -53,6 +53,7 @@
"copy_url_button": "Copy URL",
"could_not_find_any_alert": "Could not find any",
"court_name_input_placeholder": "Best Court Ever",
"courts_filled_badge": "courts filled",
"courts_title": "courts",
"create_account_alert_description": "Account creation is disabled on this domain for now since bracket is still in beta phase",
"create_account_alert_title": "Unavailable",
Expand Down Expand Up @@ -83,8 +84,6 @@
"delete_round_button": "Delete Round",
"delete_team_button": "Delete Team",
"delete_tournament_button": "Delete Tournament",
"archive_tournament_button": "Archive Tournament",
"unarchive_tournament_button": "Unarchive Tournament",
"demo_description": "To test Bracket, you can start a demo. A demo will last for 30 minutes, after which your demo account be deleted. Please make fair use of it.",
"demo_policy_title": "Demo policy",
"draft_round_checkbox_label": "This round is a draft round",
Expand Down Expand Up @@ -120,6 +119,7 @@
"filter_stage_item_placeholder": "No filter",
"forgot_password_button": "Forgot password?",
"github_title": "Github",
"go_to_courts_page": "Go to courts page",
"handle_swiss_system": "Handle Swiss System",
"home_spotlight_description": "Get to home page",
"home_title": "Home",
Expand All @@ -135,6 +135,8 @@
"loss_points_input_label": "Points for a loss",
"lowercase_required": "Includes lowercase letter",
"margin_minutes_choose_title": "Please choose a margin between matches",
"mark_round_as_draft": "Mark this round as draft",
"mark_round_as_non_draft": "Mark this round as ready",
"match_duration_label": "Match duration (minutes)",
"match_filter_option_all": "All matches",
"match_filter_option_current": "Current matches",
Expand Down Expand Up @@ -163,9 +165,9 @@
"no_courts_description": "No courts have been created yet. First, create the tournament structure by adding stages and stage items. Then, create courts here and schedule matches on these courts.",
"no_courts_description_swiss": "No courts have been created yet. First add courts before managing a Swiss stage item.",
"no_courts_title": "No courts yet",
"go_to_courts_page": "Go to courts page",
"no_matches_description": "First, add matches by creating stages and stage items. Then, schedule them using the button in the topright corner.",
"no_matches_title": "No matches scheduled yet",
"no_more_matches_title": "No more matches to schedule",
"no_players_title": "No players yet",
"no_round_description": "There are no rounds in this stage item yet",
"no_round_found_description": "Please wait for the organiser to add them.",
Expand Down Expand Up @@ -250,9 +252,8 @@
"tournament_setting_title": "Tournament Settings",
"tournament_title": "tournament",
"tournaments_title": "tournaments",
"unarchive_tournament_button": "Unarchive Tournament",
"upcoming_matches_empty_table_info": "upcoming matches",
"no_more_matches_title": "No more matches to schedule",
"all_matches_scheduled_description": "Matches have been scheduled on all courts in this round. Add a new round or add a new court for more matches.",
"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",
Expand Down
32 changes: 21 additions & 11 deletions frontend/src/components/card_tables/tournaments.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Card, Group, Image, Text, UnstyledButton } from '@mantine/core';
import { Badge, Button, Card, Group, Image, Text, UnstyledButton } from '@mantine/core';
import { useTranslation } from 'next-i18next';
import Link from 'next/link';
import React from 'react';
Expand Down Expand Up @@ -66,23 +66,33 @@ export default function TournamentsCardTable({

<Group justify="space-between" mt="md" mb="xs">
<Text fw={500}>{tournament.name}</Text>
{/*<Badge color="pink">Archived</Badge>*/}
</Group>

<Card.Section className={classes.section}>
<Stat title={t('start_time')} value={<DateTime datetime={tournament.start_time} />} />
</Card.Section>

<Card.Section className={classes.section}>
<Button
component={Link}
color="blue"
fullWidth
radius="md"
href={`/tournaments/${tournament.id}/stages`}
>
OPEN
</Button>
<Group w="100%">
<Badge
fullWidth
color="yellow"
variant="outline"
size="lg"
style={{ visibility: tournament.status === 'ARCHIVED' ? 'visible' : 'hidden' }}
>
{t('archived_label')}
</Badge>
<Button
component={Link}
color="blue"
fullWidth
radius="md"
href={`/tournaments/${tournament.id}/stages`}
>
OPEN
</Button>
</Group>
</Card.Section>
</Card>
</UnstyledButton>
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/interfaces/tournament.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export type TournamentStatus = 'OPEN' | 'ARCHIVED';

export type TournamentFilter = 'ALL' | TournamentStatus;

export interface Tournament {
id: number;
name: string;
Expand All @@ -11,7 +15,7 @@ export interface Tournament {
logo_path: string;
duration_minutes: number;
margin_minutes: number;
status: 'OPEN' | 'ARCHIVED';
status: TournamentStatus;
}
export interface TournamentMinimal {
id: number;
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/index.module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.fullWithMobile {
@media (max-width: $mantine-breakpoint-xs) {
width: 100%;
padding-left: 0;
padding-right: 1rem;
padding: var(--mantine-spacing-sm) var(--mantine-spacing-sm);
}
}
27 changes: 23 additions & 4 deletions frontend/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
import { Grid, Title } from '@mantine/core';
import { Grid, Select, Title } from '@mantine/core';
import { GetStaticProps } from 'next';
import { useTranslation } from 'next-i18next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useState } from 'react';

import TournamentsCardTable from '../components/card_tables/tournaments';
import TournamentModal from '../components/modals/tournament_modal';
import { capitalize } from '../components/utils/util';
import { TournamentFilter } from '../interfaces/tournament';
import { checkForAuthError, getTournaments } from '../services/adapter';
import Layout from './_layout';
import classes from './index.module.css';

export default function HomePage() {
const swrTournamentsResponse = getTournaments();
checkForAuthError(swrTournamentsResponse);
const { t } = useTranslation();
const [filter, setFilter] = useState<TournamentFilter>('OPEN');

const swrTournamentsResponse = getTournaments(filter);
checkForAuthError(swrTournamentsResponse);

return (
<Layout>
<Grid justify="space-between">
<Grid>
<Grid.Col span="auto">
<Title>{capitalize(t('tournaments_title'))}</Title>
</Grid.Col>
<Grid.Col span="content" className={classes.fullWithMobile}>
<Select
size="md"
placeholder="Pick value"
data={[
{ label: 'All', value: 'ALL' },
{ label: 'Archived', value: 'ARCHIVED' },
{ label: 'Open', value: 'OPEN' },
]}
allowDeselect={false}
value={filter}
// @ts-ignore
onChange={(f: TournamentFilter) => setFilter(f)}
/>
</Grid.Col>
<Grid.Col span="content" className={classes.fullWithMobile}>
<TournamentModal swrTournamentsResponse={swrTournamentsResponse} />
</Grid.Col>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/services/adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useSWR, { SWRResponse } from 'swr';
import { Pagination } from '../components/utils/util';
import { SchedulerSettings } from '../interfaces/match';
import { RoundInterface } from '../interfaces/round';
import { TournamentFilter } from '../interfaces/tournament';
import { getLogin, performLogout, tokenPresent } from './local_storage';

// TODO: This is a workaround for the fact that axios is not properly typed.
Expand Down Expand Up @@ -114,8 +115,8 @@ export function getTournamentById(tournament_id: number): SWRResponse {
return useSWR(`tournaments/${tournament_id}`, fetcher);
}

export function getTournaments(): SWRResponse {
return useSWR('tournaments', fetcher);
export function getTournaments(filter: TournamentFilter): SWRResponse {
return useSWR(`tournaments?filter_=${filter}`, fetcher);
}

export function getPlayers(tournament_id: number, not_in_team: boolean = false): SWRResponse {
Expand Down

0 comments on commit fd5272b

Please # to comment.