Skip to content

Commit

Permalink
adding tournaments
Browse files Browse the repository at this point in the history
  • Loading branch information
codephobia committed Jan 27, 2024
1 parent a5f01c3 commit a306f2f
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 208 deletions.
11 changes: 6 additions & 5 deletions apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Use nxgo/cli as the base image to do the build
FROM nxgo/cli as builder
# FROM nxgo/cli as builder
FROM golang:1.20-alpine as builder

# Create app directory
WORKDIR /workspace

# Build argument for fontawesome npm token
ARG FONTAWESOME_NPM_AUTH_TOKEN
# ARG FONTAWESOME_NPM_AUTH_TOKEN

# Copy package.json and the lock file
COPY package.json package-lock.json .npmrc ./
# COPY package.json package-lock.json .npmrc ./

# Install app dependencies
RUN npm ci
# RUN npm ci

# Copy go mod files
COPY go.mod go.sum ./
Expand All @@ -29,7 +30,7 @@ COPY apps/seed apps/seed
COPY libs/go libs/go

# Copy Nx files
COPY nx.json workspace.json tsconfig.base.json ./
# COPY nx.json workspace.json tsconfig.base.json ./

# Build api app
# RUN nx build api
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="flex flex-col flex-grow" *ngIf="vm$ | async as vm">
<div class="flex flex-row h-66px bg-sad-input border-sad-active border-b">
<div *ngIf="vm.hasTournaments" class="flex flex-row h-66px bg-sad-input border-sad-active border-b">
<div class="w-9/12 flex flex-col justify-center items-start px-10">
<p class="text-white uppercase text-xs">Name</p>
</div>
Expand All @@ -17,6 +17,9 @@
</div>
</div>
</div>
<ng-container *ngIf="!vm.hasTournaments">
<p class="p-4 text-white bg-sad-input border-sad-active border-t">Please create a new tournament on Challonge to continue.</p>
</ng-container>
</ng-container>
<ng-template #loading>
<div class="relative flex flex-row h-66px" *ngFor="let tournament of [1, 2, 3, 4, 5]; even as isEven; odd as isOdd" [ngClass]="{ 'bg-sad-table-even': isEven, 'bg-sad-table-odd': isOdd }">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@ export class TournamentListStore extends ComponentStore<TournamentListState> {
// selectors
private isLoaded$ = this.select((state) => state.callState === LoadingState.LOADED);
private tournaments$ = this.select((state) => state.tournaments);
private hasTournaments$ = this.select(
this.isLoaded$,
this.tournaments$,
(loaded, tournaments) => loaded && !!tournaments.length
);
readonly vm$ = this.select(
this.isLoaded$,
this.tournaments$,
(isLoaded, tournaments) => ({
this.hasTournaments$,
(isLoaded, tournaments, hasTournaments) => ({
isLoaded,
tournaments,
hasTournaments,
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@ <h2 class="text-white uppercase">{{ vm.tournament?.name }}</h2>
</div>
<div class="flex flex-row flex-grow bg-sad-table-odd">
<div class="flex flex-col flex-grow p-5 gap-5">
<div class="flex flex-row">
<div class="flex flex-row gap-5">
<div class="flex flex-col flex-grow">
<div class="flex flex-row h-66px items-center text-white py-2.5 px-5 border-l border-r border-t border-sad-active rounded-t bg-sad-table-even uppercase">Global Settings</div>
<div class="flex flex-row bg-sad-table-odd p-5 border border-sad-active rounded-b">
<div class="flex flex-col gap-2.5">
<dashboard-toggle label="Overlay" [checked]="vm.showOverlay" (toggled)="updateShowOverlay(!vm.showOverlay)"></dashboard-toggle>
<dashboard-toggle label="Flags" [checked]="vm.showFlags" (toggled)="updateShowFlags(!vm.showFlags)"></dashboard-toggle>
<dashboard-toggle label="Fargo" [checked]="vm.showFargo" (toggled)="updateShowFargo(!vm.showFargo)"></dashboard-toggle>
<dashboard-toggle label="Score" [checked]="vm.showScore" (toggled)="updateShowScore(!vm.showScore)"></dashboard-toggle>
<dashboard-toggle label="Handicapped" [checked]="vm.isHandicapped" (toggled)="updateIsHandicapped(!vm.isHandicapped)"></dashboard-toggle>
</div>
</div>
</div>
<div class="flex flex-col flex-grow">
<div class="flex flex-row h-66px items-center text-white py-2.5 px-5 border-l border-r border-t border-sad-active rounded-t bg-sad-table-even uppercase">Game Type</div>
<div class="flex flex-row flex-grow bg-sad-table-odd p-5 border border-sad-active rounded-b">
<div class="flex flex-col gap-2.5">
<div class="flex flex-row gap-2.5">
<button
Expand Down Expand Up @@ -41,11 +53,19 @@ <h2 class="text-white uppercase">{{ vm.tournament?.name }}</h2>
10 Ball
</button>
</div>
<dashboard-toggle label="Overlay" [checked]="vm.showOverlay" (toggled)="updateShowOverlay(!vm.showOverlay)"></dashboard-toggle>
<dashboard-toggle label="Flags" [checked]="vm.showFlags" (toggled)="updateShowFlags(!vm.showFlags)"></dashboard-toggle>
<dashboard-toggle label="Fargo" [checked]="vm.showFargo" (toggled)="updateShowFargo(!vm.showFargo)"></dashboard-toggle>
<dashboard-toggle label="Score" [checked]="vm.showScore" (toggled)="updateShowScore(!vm.showScore)"></dashboard-toggle>
<dashboard-toggle label="Handicapped" [checked]="vm.isHandicapped" (toggled)="updateIsHandicapped(!vm.isHandicapped)"></dashboard-toggle>
</div>
</div>
</div>
<div class="flex flex-col flex-grow">
<div class="flex flex-row h-66px items-center text-white py-2.5 px-5 border-l border-r border-t border-sad-active rounded-t bg-sad-table-even uppercase">Max Tables</div>
<div class="flex flex-row flex-grow bg-sad-table-odd p-5 border border-sad-active rounded-b">
<div class="flex flex-col gap-2.5">
<div class="flex flex-row gap-2.5">
<button type="button" class="px-5 py-2.5 rounded text-white" [ngClass]="vm.maxTables === 1 ? 'bg-blue-700' : 'bg-gray-700'" (click)="updateMaxTables(1)">1</button>
<button type="button" class="px-5 py-2.5 rounded text-white" [ngClass]="vm.maxTables === 2 ? 'bg-blue-700' : 'bg-gray-700'" (click)="updateMaxTables(2)">2</button>
<button type="button" class="px-5 py-2.5 rounded text-white" [ngClass]="vm.maxTables === 3 ? 'bg-blue-700' : 'bg-gray-700'" (click)="updateMaxTables(3)">3</button>
<button type="button" class="px-5 py-2.5 rounded text-white" [ngClass]="vm.maxTables === 4 ? 'bg-blue-700' : 'bg-gray-700'" (click)="updateMaxTables(4)">4</button>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export class TournamentSetupComponent {
this.store.getTournamentById(tournamentId);
}

public updateMaxTables(maxTables: number): void {
this.store.updateMaxTables(maxTables);
}

public updateGameType(gameType: GameType): void {
this.store.updateGameType(gameType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum LoadingState {
interface TournamentSetupState {
callState: LoadingState;
tournament: Tournament | null;
maxTables: number;
isHandicapped: boolean;
showOverlay: boolean;
showFlags: boolean;
Expand All @@ -27,6 +28,7 @@ interface TournamentSetupState {
export const initialState: TournamentSetupState = {
callState: LoadingState.INIT,
tournament: null,
maxTables: 3,
isHandicapped: true,
showOverlay: true,
showFlags: false,
Expand Down Expand Up @@ -58,6 +60,10 @@ export class TournamentSetupStore extends ComponentStore<TournamentSetupState> {
callState: LoadingState.LOADED,
}));

readonly updateMaxTables = this.updater<number>((state, maxTables) => ({
...state,
maxTables,
}));

readonly updateGameType = this.updater<GameType>((state, gameType) => ({
...state,
Expand Down Expand Up @@ -102,6 +108,7 @@ export class TournamentSetupStore extends ComponentStore<TournamentSetupState> {
// selectors
private isLoaded$ = this.select((state) => state.callState === LoadingState.LOADED);
private tournament$ = this.select((state) => state.tournament);
private maxTables$ = this.select((state) => state.maxTables);
private isHandicapped$ = this.select((state) => state.isHandicapped);
private showOverlay$ = this.select((state) => state.showOverlay);
private showFlags$ = this.select((state) => state.showFlags);
Expand All @@ -113,6 +120,7 @@ export class TournamentSetupStore extends ComponentStore<TournamentSetupState> {
readonly vm$ = this.select(
this.isLoaded$,
this.tournament$,
this.maxTables$,
this.isHandicapped$,
this.showOverlay$,
this.showFlags$,
Expand All @@ -121,9 +129,10 @@ export class TournamentSetupStore extends ComponentStore<TournamentSetupState> {
this.gameType$,
this.aSideRaceTo$,
this.bSideRaceTo$,
(isLoaded, tournament, isHandicapped, showOverlay, showFlags, showFargo, showScore, gameType, aSideRaceTo, bSideRaceTo) => ({
(isLoaded, tournament, maxTables, isHandicapped, showOverlay, showFlags, showFargo, showScore, gameType, aSideRaceTo, bSideRaceTo) => ({
isLoaded,
tournament,
maxTables,
isHandicapped,
showOverlay,
showFlags,
Expand Down Expand Up @@ -151,6 +160,7 @@ export class TournamentSetupStore extends ComponentStore<TournamentSetupState> {
readonly loadTournament = this.effect((trigger$) => trigger$.pipe(
withLatestFrom(
this.tournament$,
this.maxTables$,
this.gameType$,
this.showOverlay$,
this.showFlags$,
Expand All @@ -160,7 +170,8 @@ export class TournamentSetupStore extends ComponentStore<TournamentSetupState> {
this.aSideRaceTo$,
this.bSideRaceTo$,
),
switchMap(([, tournament, game_type, show_overlay, show_flags, show_fargo, show_score, is_handicapped, a_side_race_to, b_side_race_to]) => this.tournamentsService.load(tournament!.id, {
switchMap(([, tournament, max_tables, game_type, show_overlay, show_flags, show_fargo, show_score, is_handicapped, a_side_race_to, b_side_race_to]) => this.tournamentsService.load(tournament!.id, {
max_tables,
game_type,
show_overlay,
show_flags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class ToggleComponent {

@Input()
public set checked(value: boolean) {
console.log(`input: ${value}`);
this.store.setChecked(value);
}

Expand Down
3 changes: 2 additions & 1 deletion libs/go/api/tournaments.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type TournamentLoadBody struct {
}

type TournamentLoadBodySettings struct {
MaxTables int `json:"max_tables"`
GameType models.GameType `json:"game_type"`
ShowOverlay bool `json:"show_overlay"`
ShowFlags bool `json:"show_flags"`
Expand Down Expand Up @@ -147,7 +148,7 @@ func (server *Server) handleTournamentLoadPost(w http.ResponseWriter, r *http.Re

// make settings
settings := &challonge.Settings{
MaxTables: 3,
MaxTables: body.Settings.MaxTables,
GameType: body.Settings.GameType,
ShowOverlay: body.Settings.ShowOverlay,
ShowFlags: body.Settings.ShowFlags,
Expand Down
Loading

0 comments on commit a306f2f

Please sign in to comment.