Add play again button for rematch after game ends
When a game finishes (win or draw), players see a "Play again" button. Clicking it creates a new game and the opponent sees a "Join Rematch" link to join the same game.
This commit is contained in:
30
ui/status.go
30
ui/status.go
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/ryanhamamura/via/h"
|
||||
)
|
||||
|
||||
func StatusBanner(g *game.Game, myColor int) h.H {
|
||||
func StatusBanner(g *game.Game, myColor int, playAgainClick h.H) h.H {
|
||||
var message string
|
||||
var class string
|
||||
|
||||
@@ -35,10 +35,34 @@ func StatusBanner(g *game.Game, myColor int) h.H {
|
||||
class = "status draw"
|
||||
}
|
||||
|
||||
return h.Div(
|
||||
content := []h.H{
|
||||
h.Class(class),
|
||||
h.Text(message),
|
||||
)
|
||||
}
|
||||
|
||||
// Show rematch options for finished games
|
||||
if g.IsFinished() {
|
||||
if g.RematchGameID != nil {
|
||||
content = append(content,
|
||||
h.A(
|
||||
h.Class("rematch-link"),
|
||||
h.Href("/game/"+*g.RematchGameID),
|
||||
h.Text("Join Rematch"),
|
||||
),
|
||||
)
|
||||
} else if playAgainClick != nil {
|
||||
content = append(content,
|
||||
h.Button(
|
||||
h.Class("play-again-btn"),
|
||||
h.Type("button"),
|
||||
h.Text("Play again"),
|
||||
playAgainClick,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return h.Div(content...)
|
||||
}
|
||||
|
||||
func getOpponentName(g *game.Game, myColor int) string {
|
||||
|
||||
Reference in New Issue
Block a user