From b8e6768bc6043f641268a6a4f2c689d98b8781f9 Mon Sep 17 00:00:00 2001 From: Riley Thompson Date: Mon, 15 Jul 2024 20:43:09 -0400 Subject: [PATCH] Updates (#116) * override @supabase/auth-js dependency from v2.64.2 to v2.61.0 to resolve https://github.com/supabase/supabase-js/issues/936 * update two way binding in profile visibility to work with angular 18 * redirect to /join if player is not authenticated within the game * remove logs * update console messages --- be-jeopardy/internal/jeopardy/game.go | 21 ------------------- be-jeopardy/internal/jeopardy/reaction.go | 4 +--- fe-jeopardy/package-lock.json | 6 +++--- fe-jeopardy/package.json | 2 +- .../src/app/game/chat/chat.component.ts | 4 +--- fe-jeopardy/src/app/game/game.component.ts | 13 +++++++++--- .../app/game/post-game/post-game.component.ts | 3 +-- .../src/app/profile/profile.component.html | 4 ++-- .../src/app/profile/profile.component.ts | 16 ++++++++++++++ .../src/app/reactions/reactions.component.ts | 6 +----- 10 files changed, 36 insertions(+), 43 deletions(-) diff --git a/be-jeopardy/internal/jeopardy/game.go b/be-jeopardy/internal/jeopardy/game.go index 5981bc9..eb451c3 100644 --- a/be-jeopardy/internal/jeopardy/game.go +++ b/be-jeopardy/internal/jeopardy/game.go @@ -162,10 +162,8 @@ func (g *Game) processMessages() { log.Errorf("Error processing message: %s", err.Error()) } case player := <-g.disconnectChan: - log.Infof("Stopping game %s", g.Name) g.disconnectPlayer(player) case <-g.restartChan: - log.Infof("Restarting game %s", g.Name) g.restartGame(context.Background()) } } @@ -239,21 +237,17 @@ func (g *Game) disconnectPlayer(player GamePlayer) { func (g *Game) processMsg(ctx context.Context, msg Message) error { player := msg.Player if g.State != msg.State { - log.Infof("Ignoring message from player %s because it is not for the current game state", player.name()) return nil } if g.Paused { if msg.Pause == -1 { - log.Infof("Player %s resumed the game", player.name()) g.startGame() g.messageAllPlayers("Player %s resumed the game", player.name()) return nil } - log.Infof("Ignoring message from player %s because game is paused", player.name()) return nil } if msg.Pause == 1 { - log.Infof("Player %s paused the game", player.name()) g.pauseGame() g.messageAllPlayers("Player %s paused the game", player.name()) return nil @@ -262,34 +256,19 @@ func (g *Game) processMsg(ctx context.Context, msg Message) error { switch g.State { case RecvPick: if msg.InitDispute { - log.Infof("Player %s disputed the previous question", player.name()) err = g.initDispute(player) } else { - log.Debugf("Player %s picked", player.name()) err = g.processPick(player, msg.CatIdx, msg.ValIdx) } case RecvBuzz: - action := "buzzed" - if msg.IsPass { - action = "passed" - } - log.Debugf("Player %s %s", player.name(), action) err = g.processBuzz(ctx, player, msg.IsPass) case RecvAns: - log.Debugf("Player %s answered", player.name()) err = g.processAnswer(ctx, player, msg.Answer) case RecvWager: - log.Debugf("Player %s wagered", player.name()) err = g.processWager(player, msg.Wager) case RecvDispute: - action := "confirmed" - if !msg.Dispute { - action = "disputed" - } - log.Debugf("Player %s %s the question", player.name(), action) err = g.processDispute(ctx, player, msg.Dispute) case PostGame: - log.Debugf("Player %s protested", player.name()) err = g.processProtest(player, msg.ProtestFor) case PreGame: err = fmt.Errorf("received unexpected message") diff --git a/be-jeopardy/internal/jeopardy/reaction.go b/be-jeopardy/internal/jeopardy/reaction.go index 6004ed7..f802c3a 100644 --- a/be-jeopardy/internal/jeopardy/reaction.go +++ b/be-jeopardy/internal/jeopardy/reaction.go @@ -46,7 +46,7 @@ func (p *Player) processReactions(reactChan chan Reaction) { if err != nil { log.Errorf("Error reading reaction message from player %s: %s", p.Name, err.Error()) if websocket.IsCloseError(err, 1001) { - log.Infof("Player %s closed chat connection", p.Name) + log.Infof("Player %s closed reaction connection", p.Name) } return } @@ -54,7 +54,6 @@ func (p *Player) processReactions(reactChan chan Reaction) { if err := json.Unmarshal(message, &msg); err != nil { log.Errorf("Error parsing reaction message: %s", err.Error()) } - log.Infof("Received reaction from player %s: %+v", p.Name, msg) msg.PlayerName = p.Name msg.TimeStamp = time.Now().Unix() msg.RandPos = getRandPos(10, 150) @@ -89,7 +88,6 @@ func (p *Player) readReaction() ([]byte, error) { } func (p *Player) sendReaction(msg Reaction) error { - log.Infof("Sending reaction to player %s: %+v", p.Name, msg) if p.ReactionConn == nil { log.Errorf("Error sending reaction to player %s because connection is nil", p.Name) return fmt.Errorf("player has no reaction connection") diff --git a/fe-jeopardy/package-lock.json b/fe-jeopardy/package-lock.json index 02f1744..0b60fa7 100644 --- a/fe-jeopardy/package-lock.json +++ b/fe-jeopardy/package-lock.json @@ -3612,9 +3612,9 @@ "dev": true }, "node_modules/@supabase/auth-js": { - "version": "2.64.2", - "resolved": "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.64.2.tgz", - "integrity": "sha512-s+lkHEdGiczDrzXJ1YWt2y3bxRi+qIUnXcgkpLSrId7yjBeaXBFygNjTaoZLG02KNcYwbuZ9qkEIqmj2hF7svw==", + "version": "2.61.0", + "resolved": "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.61.0.tgz", + "integrity": "sha512-ACHvg619Kunpxgx4bFq7qPyX1YEBl22Xxm6uucAVq5VS/UWC3ugq6H+J7m5Lv9XXLSpl+G9O9eNFX1sIyq3gRw==", "dependencies": { "@supabase/node-fetch": "^2.6.14" } diff --git a/fe-jeopardy/package.json b/fe-jeopardy/package.json index c7fdc9b..e463a83 100644 --- a/fe-jeopardy/package.json +++ b/fe-jeopardy/package.json @@ -40,7 +40,7 @@ }, "overrides": { "@supabase/supabase-js": { - "@supabase/gotrue-js": "2.61.0" + "@supabase/auth-js": "2.61.0" } } } diff --git a/fe-jeopardy/src/app/game/chat/chat.component.ts b/fe-jeopardy/src/app/game/chat/chat.component.ts index 01ab607..df0529b 100644 --- a/fe-jeopardy/src/app/game/chat/chat.component.ts +++ b/fe-jeopardy/src/app/game/chat/chat.component.ts @@ -34,7 +34,7 @@ export class ChatComponent implements OnInit, AfterViewChecked { let resp = JSON.parse(event.data) if (resp.code >= 4400) { - console.log(resp.message) + console.error(resp.message) this.messages.push({ username: 'Jeopardy System', message: resp.message, @@ -47,8 +47,6 @@ export class ChatComponent implements OnInit, AfterViewChecked { return } - console.log(resp) - this.messages.push({ username: resp.name, message: resp.message, diff --git a/fe-jeopardy/src/app/game/game.component.ts b/fe-jeopardy/src/app/game/game.component.ts index 378c5a4..e6862d2 100644 --- a/fe-jeopardy/src/app/game/game.component.ts +++ b/fe-jeopardy/src/app/game/game.component.ts @@ -1,5 +1,6 @@ import { animate, state, style, transition, trigger } from '@angular/animations' import { Component, ElementRef, OnInit, ViewChild } from '@angular/core' +import { ActivatedRoute, Router } from '@angular/router' import { GameState, Ping, Player } from '../model/model' import { GameStateService } from '../services/game-state.service' import { JwtService } from '../services/jwt.service' @@ -20,7 +21,7 @@ import { WebsocketService } from '../services/websocket.service' }) export class GameComponent implements OnInit { private countdownInterval: NodeJS.Timeout - protected gameLink: string + protected joinPath: string protected gameMessage: string protected questionAnswer: string protected wagerAmt: string @@ -38,9 +39,15 @@ export class GameComponent implements OnInit { protected game: GameStateService, protected player: PlayerService, private modal: ModalService, + private router: Router, + private route: ActivatedRoute, ) { } ngOnInit(): void { + this.route.paramMap.subscribe(params => { + let joinCode = params.get('joinCode') + this.joinPath = joinCode ? `/join/${joinCode}` : '/' + }) let showJeopardyMusicInfo = localStorage.getItem('showJeopardyMusicInfo') if (showJeopardyMusicInfo === null) { this.showMusicInfo = true @@ -74,6 +81,8 @@ export class GameComponent implements OnInit { if (resp.code >= 4400) { switch (resp.code) { case 4400: + this.router.navigate([this.joinPath]) + break case 4401: case 4500: this.modal.displayMessage(resp.message) @@ -92,8 +101,6 @@ export class GameComponent implements OnInit { this.player.updatePlayer(resp.curPlayer) this.gameMessage = resp.message - console.log(resp) - if (resp.code == 4100) { this.modal.displayMessage(resp.message) return diff --git a/fe-jeopardy/src/app/game/post-game/post-game.component.ts b/fe-jeopardy/src/app/game/post-game/post-game.component.ts index d5f3311..04df2fa 100644 --- a/fe-jeopardy/src/app/game/post-game/post-game.component.ts +++ b/fe-jeopardy/src/app/game/post-game/post-game.component.ts @@ -37,7 +37,6 @@ export class PostGameComponent { playAgain() { return this.api.PlayAgain().subscribe({ next: (resp: any) => { - console.log(resp) }, error: (err: any) => { let msg = err.status != 0 ? err.error.message : ServerUnavailableMsg; @@ -53,7 +52,7 @@ export class PostGameComponent { }, error: (err: any) => { let msg = err.status != 0 ? err.error.message : ServerUnavailableMsg; - console.log(msg) + console.error(msg) this.router.navigate(['/']) }, }) diff --git a/fe-jeopardy/src/app/profile/profile.component.html b/fe-jeopardy/src/app/profile/profile.component.html index 8fc93c4..a15ffb7 100644 --- a/fe-jeopardy/src/app/profile/profile.component.html +++ b/fe-jeopardy/src/app/profile/profile.component.html @@ -21,9 +21,9 @@

{{ profileUser.email }}

Date joined: {{ profileUser.dateJoined }}

- + - +
diff --git a/fe-jeopardy/src/app/profile/profile.component.ts b/fe-jeopardy/src/app/profile/profile.component.ts index 0303ae4..358f8e3 100644 --- a/fe-jeopardy/src/app/profile/profile.component.ts +++ b/fe-jeopardy/src/app/profile/profile.component.ts @@ -133,4 +133,20 @@ export class ProfileComponent implements OnInit { } await this.auth.GetUser() } + + protected get publicProfile(): boolean { + return this.user.public + } + + protected get privateProfile(): boolean { + return !this.user.public + } + + protected set publicProfile(value: boolean) { + this.user.public = value + } + + protected set privateProfile(value: boolean) { + this.user.public = !value + } } diff --git a/fe-jeopardy/src/app/reactions/reactions.component.ts b/fe-jeopardy/src/app/reactions/reactions.component.ts index eb66c14..5eb84d6 100644 --- a/fe-jeopardy/src/app/reactions/reactions.component.ts +++ b/fe-jeopardy/src/app/reactions/reactions.component.ts @@ -38,15 +38,13 @@ export class ReactionsComponent { this.reactions.OnOpen(() => { this.reactions.Send({ token: this.jwt.GetJWT() }) - console.log('Connected to reactions service') }) this.reactions.OnMessage((event: { data: string }) => { let resp = JSON.parse(event.data) - console.log('Received reaction:', resp) if (resp.code >= 4400) { - console.log(resp.reaction) + console.error(resp.reaction) this.reactionsList.push({ username: 'Jeopardy System', reaction: resp.reaction, @@ -60,8 +58,6 @@ export class ReactionsComponent { return } - console.log(resp) - this.reactionsList.push({ username: resp.name, reaction: resp.reaction,