-
+
+
+
+
+
+
+
{#if user}
Welcome, {user.username || 'User'}
@@ -38,9 +54,6 @@
{/if}
-
-
-
diff --git a/src/lib/components/brackets/bracket.svelte b/src/lib/components/brackets/bracket.svelte
new file mode 100644
index 0000000..b364600
--- /dev/null
+++ b/src/lib/components/brackets/bracket.svelte
@@ -0,0 +1,26 @@
+
+
+
+ {bracket.name}
+
+ {#if !bracket.rounds || bracket.rounds.length <= 0}
+ No matches
+ {:else}
+ {bracket.rounds[bracket.position - 1].name} ({bracket.position}/{bracket.rounds.length})
+ {/if}
+
+
+
diff --git a/src/lib/components/rounds/create-round.svelte b/src/lib/components/brackets/create-bracket.svelte
similarity index 75%
rename from src/lib/components/rounds/create-round.svelte
rename to src/lib/components/brackets/create-bracket.svelte
index abae1e4..72b1c2f 100644
--- a/src/lib/components/rounds/create-round.svelte
+++ b/src/lib/components/brackets/create-bracket.svelte
@@ -7,6 +7,7 @@
import Label from '$ui/label/label.svelte';
import RadioGroupItem from '$ui/radio-group/radio-group-item.svelte';
import RadioGroup from '$ui/radio-group/radio-group.svelte';
+ import type { Bracket } from '@/lib/server/db/schema/brackets';
import type { Round } from '@/lib/server/db/schema/rounds';
import { cn, instanceOf } from '@/lib/utils';
import { SchedulingMode } from '@/types';
@@ -19,15 +20,17 @@
let {
competitionId,
- rounds = $bindable(),
- showAddRound = $bindable(true)
- }: { competitionId: string; rounds: Round[]; showAddRound: boolean } = $props();
+ brackets = $bindable(),
+ showAddBracket = $bindable(true)
+ }: { competitionId: string; brackets: Bracket[]; showAddBracket: boolean } = $props();
let schedulingMode: SchedulingMode = $state(SchedulingMode.single);
let name = $state('');
let nameInvalid = $state(false);
- let nbMatches: number | undefined = $state();
- let nbMatchesInvalid = $state(false);
+ let size: number | undefined = $state();
+ let sizeInvalid = $state(false);
+
+ let buttonDisabled = $state(false);
async function submit() {
if (name.length === 0) {
@@ -35,25 +38,27 @@
toast.error('Name is required');
return;
}
- if (!nbMatches || nbMatches < 0) {
- nbMatchesInvalid = true;
+ if (!size || size < 0) {
+ sizeInvalid = true;
toast.error('Number of matches must be greater than 0');
return;
}
nameInvalid = false;
+ // loading/disable button
+ buttonDisabled = true;
const response = await fetch(`/api/competitions/${competitionId}`, {
method: 'POST',
credentials: 'include',
- body: JSON.stringify({ scheduling_mode: schedulingMode, name: name, nb_matches: nbMatches })
+ body: JSON.stringify({ scheduling_mode: schedulingMode, name: name, size: size })
});
- console.log('response', response);
// update rounds
const data = await response.json();
- if (instanceOf
(data, 'id')) {
- rounds = [...rounds, data];
- showAddRound = false;
+ buttonDisabled = false;
+ if (Array.isArray(data) && data.length > 0 && instanceOf(data[0], 'id')) {
+ brackets = [...brackets, data[0]];
+ showAddBracket = false;
} else {
- throw new Error('Invalid round');
+ throw new Error('Invalid bracket');
}
}
@@ -65,8 +70,8 @@
- Size*
Number of participants at the beginning of the stage.
@@ -80,10 +85,10 @@
placeholder="Name"
/>
@@ -110,6 +115,6 @@
{/each}
diff --git a/src/lib/components/brackets/match.svelte b/src/lib/components/brackets/match.svelte
new file mode 100644
index 0000000..6152424
--- /dev/null
+++ b/src/lib/components/brackets/match.svelte
@@ -0,0 +1,173 @@
+
+
+
+
+
+
+
+
Team {match.team1?.name}
+
+
+
+
+
+
+
+
+
Team {match.team2?.name}
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/lib/components/brackets/round.svelte b/src/lib/components/brackets/round.svelte
new file mode 100644
index 0000000..09693a3
--- /dev/null
+++ b/src/lib/components/brackets/round.svelte
@@ -0,0 +1,40 @@
+
+
+
+
+
+ {@render children()}
+
+
+
+
diff --git a/src/lib/components/brackets/types/double.svelte b/src/lib/components/brackets/types/double.svelte
new file mode 100644
index 0000000..e69de29
diff --git a/src/lib/components/brackets/types/double_round_robin.svelte b/src/lib/components/brackets/types/double_round_robin.svelte
new file mode 100644
index 0000000..e69de29
diff --git a/src/lib/components/brackets/types/round_robin.svelte b/src/lib/components/brackets/types/round_robin.svelte
new file mode 100644
index 0000000..e69de29
diff --git a/src/lib/components/brackets/types/single.svelte b/src/lib/components/brackets/types/single.svelte
new file mode 100644
index 0000000..917a9af
--- /dev/null
+++ b/src/lib/components/brackets/types/single.svelte
@@ -0,0 +1,52 @@
+
+
+{#if bracket && bracket.rounds}
+
+
+
+ {#each bracket.rounds as round, index}
+ {#if round && round.matches}
+
+ {#each round.matches as match}
+
+ {/each}
+
+ {/if}
+ {/each}
+
+
+{/if}
+
+
diff --git a/src/lib/components/brackets/types/swiss.svelte b/src/lib/components/brackets/types/swiss.svelte
new file mode 100644
index 0000000..e69de29
diff --git a/src/lib/components/rounds/create-schema.ts b/src/lib/components/rounds/create-schema.ts
deleted file mode 100644
index d76c88b..0000000
--- a/src/lib/components/rounds/create-schema.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import { SchedulingMode } from '@/types';
-import z from 'zod';
-
-export const formSchema = z.object({
- scheduling_mode: z.nativeEnum(SchedulingMode)
-});
-
-export type FormSchema = typeof formSchema;
diff --git a/src/lib/components/rounds/round.svelte b/src/lib/components/rounds/round.svelte
deleted file mode 100644
index 88a3d05..0000000
--- a/src/lib/components/rounds/round.svelte
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
- Round {round.name}
-
- {#if !round.matches || round.matches.length <= 0}
- No matches, add some !
- {:else}
- Matches :{#each round.matches as match (match.id)}
- {JSON.stringify(match)}
- {/each}
- {/if}
-
-
-
diff --git a/src/lib/components/theme-toggle.svelte b/src/lib/components/theme-toggle.svelte
new file mode 100644
index 0000000..668b0fb
--- /dev/null
+++ b/src/lib/components/theme-toggle.svelte
@@ -0,0 +1,17 @@
+
+
+
diff --git a/src/lib/components/ui/button/button.svelte b/src/lib/components/ui/button/button.svelte
index 16f1a3c..4daf453 100644
--- a/src/lib/components/ui/button/button.svelte
+++ b/src/lib/components/ui/button/button.svelte
@@ -1,36 +1,36 @@
@@ -58,15 +58,15 @@
{/snippet}
-{#if captionLayout === 'dropdown'}
+{#if captionLayout === "dropdown"}
{@render MonthSelect()}
{@render YearSelect()}
-{:else if captionLayout === 'dropdown-months'}
+{:else if captionLayout === "dropdown-months"}
{@render MonthSelect()}
{#if placeholder}
{formatYear(placeholder)}
{/if}
-{:else if captionLayout === 'dropdown-years'}
+{:else if captionLayout === "dropdown-years"}
{#if placeholder}
{formatMonth(placeholder)}
{/if}
diff --git a/src/lib/components/ui/calendar/calendar-cell.svelte b/src/lib/components/ui/calendar/calendar-cell.svelte
index 6eb8149..5f295d6 100644
--- a/src/lib/components/ui/calendar/calendar-cell.svelte
+++ b/src/lib/components/ui/calendar/calendar-cell.svelte
@@ -1,6 +1,6 @@
-
+
diff --git a/src/lib/components/ui/calendar/calendar-grid.svelte b/src/lib/components/ui/calendar/calendar-grid.svelte
index bfa49dc..e0c8627 100644
--- a/src/lib/components/ui/calendar/calendar-grid.svelte
+++ b/src/lib/components/ui/calendar/calendar-grid.svelte
@@ -1,6 +1,6 @@
-
+
{@render children?.()}
diff --git a/src/lib/components/ui/calendar/calendar-months.svelte b/src/lib/components/ui/calendar/calendar-months.svelte
index 023cad3..f717a9d 100644
--- a/src/lib/components/ui/calendar/calendar-months.svelte
+++ b/src/lib/components/ui/calendar/calendar-months.svelte
@@ -1,6 +1,6 @@
@@ -50,7 +50,7 @@ get along, so we shut typescript up by casting `value` to `never`.
{weekdayFormat}
{disableDaysOutsideMonth}
class={cn(
- 'bg-background group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent',
+ "bg-background group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
className
)}
{locale}
@@ -97,7 +97,7 @@ get along, so we shut typescript up by casting `value` to `never`.
{#if day}
{@render day({
day: date,
- outsideMonth: !isEqualMonth(date, month.value)
+ outsideMonth: !isEqualMonth(date, month.value),
})}
{:else}
diff --git a/src/lib/components/ui/calendar/index.ts b/src/lib/components/ui/calendar/index.ts
index 180d173..f3a16d2 100644
--- a/src/lib/components/ui/calendar/index.ts
+++ b/src/lib/components/ui/calendar/index.ts
@@ -1,21 +1,21 @@
-import Root from './calendar.svelte';
-import Cell from './calendar-cell.svelte';
-import Day from './calendar-day.svelte';
-import Grid from './calendar-grid.svelte';
-import Header from './calendar-header.svelte';
-import Months from './calendar-months.svelte';
-import GridRow from './calendar-grid-row.svelte';
-import Heading from './calendar-heading.svelte';
-import GridBody from './calendar-grid-body.svelte';
-import GridHead from './calendar-grid-head.svelte';
-import HeadCell from './calendar-head-cell.svelte';
-import NextButton from './calendar-next-button.svelte';
-import PrevButton from './calendar-prev-button.svelte';
-import MonthSelect from './calendar-month-select.svelte';
-import YearSelect from './calendar-year-select.svelte';
-import Month from './calendar-month.svelte';
-import Nav from './calendar-nav.svelte';
-import Caption from './calendar-caption.svelte';
+import Root from "./calendar.svelte";
+import Cell from "./calendar-cell.svelte";
+import Day from "./calendar-day.svelte";
+import Grid from "./calendar-grid.svelte";
+import Header from "./calendar-header.svelte";
+import Months from "./calendar-months.svelte";
+import GridRow from "./calendar-grid-row.svelte";
+import Heading from "./calendar-heading.svelte";
+import GridBody from "./calendar-grid-body.svelte";
+import GridHead from "./calendar-grid-head.svelte";
+import HeadCell from "./calendar-head-cell.svelte";
+import NextButton from "./calendar-next-button.svelte";
+import PrevButton from "./calendar-prev-button.svelte";
+import MonthSelect from "./calendar-month-select.svelte";
+import YearSelect from "./calendar-year-select.svelte";
+import Month from "./calendar-month.svelte";
+import Nav from "./calendar-nav.svelte";
+import Caption from "./calendar-caption.svelte";
export {
Day,
@@ -36,5 +36,5 @@ export {
MonthSelect,
Caption,
//
- Root as Calendar
+ Root as Calendar,
};
diff --git a/src/lib/components/ui/pagination/index.ts b/src/lib/components/ui/pagination/index.ts
index 2f5532a..d83c7a9 100644
--- a/src/lib/components/ui/pagination/index.ts
+++ b/src/lib/components/ui/pagination/index.ts
@@ -1,10 +1,10 @@
-import Root from './pagination.svelte';
-import Content from './pagination-content.svelte';
-import Item from './pagination-item.svelte';
-import Link from './pagination-link.svelte';
-import PrevButton from './pagination-prev-button.svelte';
-import NextButton from './pagination-next-button.svelte';
-import Ellipsis from './pagination-ellipsis.svelte';
+import Root from "./pagination.svelte";
+import Content from "./pagination-content.svelte";
+import Item from "./pagination-item.svelte";
+import Link from "./pagination-link.svelte";
+import PrevButton from "./pagination-prev-button.svelte";
+import NextButton from "./pagination-next-button.svelte";
+import Ellipsis from "./pagination-ellipsis.svelte";
export {
Root,
@@ -21,5 +21,5 @@ export {
Link as PaginationLink,
PrevButton as PaginationPrevButton,
NextButton as PaginationNextButton,
- Ellipsis as PaginationEllipsis
+ Ellipsis as PaginationEllipsis,
};
diff --git a/src/lib/components/ui/pagination/pagination-content.svelte b/src/lib/components/ui/pagination/pagination-content.svelte
index ce650ce..e1124fc 100644
--- a/src/lib/components/ui/pagination/pagination-content.svelte
+++ b/src/lib/components/ui/pagination/pagination-content.svelte
@@ -1,6 +1,6 @@
+
+
+ {#if data.bracket.scheduling_mode === SchedulingMode.single}
+
+ {:else if data.bracket.scheduling_mode === SchedulingMode.double}
+ double
+ {:else if data.bracket.scheduling_mode === SchedulingMode.round_robin}
+ round_robin
+ {:else if data.bracket.scheduling_mode === SchedulingMode.swiss}
+ swiss
+ {:else if data.bracket.scheduling_mode === SchedulingMode.double_round_robin}
+ double_round_robin
+ {/if}
+
diff --git a/src/routes/competitions/[id]/rounds/[round_id]/+page.svelte b/src/routes/competitions/[id]/rounds/[round_id]/+page.svelte
deleted file mode 100644
index 491807b..0000000
--- a/src/routes/competitions/[id]/rounds/[round_id]/+page.svelte
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-{JSON.stringify(data)}
diff --git a/src/routes/competitions/new/+page.svelte b/src/routes/competitions/new/+page.svelte
index ed1311b..2af1744 100644
--- a/src/routes/competitions/new/+page.svelte
+++ b/src/routes/competitions/new/+page.svelte
@@ -1,8 +1,5 @@
-
-
-
-
-
+
+ Create Competition | FlbxCup
+
+
+
+
+
+
+
+
+
+
Create New Competition
+
Set up your tournament and start competing
-
Create New Competition
-
Set up your tournament and start competing
-
-
-
-
-
- Competition Details
-
- Fill in the information below to create your competition
-
-
-