Create chat/ package with Message type, Room (NATS pub/sub + buffer), DB persistence helpers, and a unified templ component parameterized by Config (CSS prefix, post URL, color function, key propagation). Both c4game and snakegame now use chat.Room for message management and chatcomponents.Chat for rendering, eliminating the duplicated ChatMessage types, chat templ components, chatAutoScroll scripts, color functions, and inline buffer management.
50 lines
1.4 KiB
Plaintext
50 lines
1.4 KiB
Plaintext
package pages
|
|
|
|
import (
|
|
"github.com/ryanhamamura/c4/chat"
|
|
chatcomponents "github.com/ryanhamamura/c4/chat/components"
|
|
"github.com/ryanhamamura/c4/features/c4game/components"
|
|
sharedcomponents "github.com/ryanhamamura/c4/features/common/components"
|
|
"github.com/ryanhamamura/c4/features/common/layouts"
|
|
"github.com/ryanhamamura/c4/game"
|
|
"github.com/starfederation/datastar-go/datastar"
|
|
)
|
|
|
|
templ GamePage(g *game.Game, myColor int, messages []chat.Message, chatCfg chatcomponents.Config) {
|
|
@layouts.Base("Connect 4") {
|
|
<main
|
|
class="flex flex-col items-center gap-4 p-4"
|
|
data-signals="{chatMsg: ''}"
|
|
data-init={ datastar.GetSSE("/games/%s/events", g.ID) }
|
|
>
|
|
@sharedcomponents.BackToLobby()
|
|
@sharedcomponents.StealthTitle("text-3xl font-bold")
|
|
@components.PlayerInfo(g, myColor)
|
|
@components.StatusBanner(g, myColor)
|
|
<div class="c4-game-area">
|
|
@components.Board(g, myColor)
|
|
@chatcomponents.Chat(messages, chatCfg)
|
|
</div>
|
|
if g.Status == game.StatusWaitingForPlayer {
|
|
@components.InviteLink(g.ID)
|
|
}
|
|
</main>
|
|
}
|
|
}
|
|
|
|
templ JoinPage(gameID string) {
|
|
@layouts.Base("Connect 4 - Join") {
|
|
@sharedcomponents.GameJoinPrompt(
|
|
"/login?return_url=/games/"+gameID,
|
|
"/register?return_url=/games/"+gameID,
|
|
"/games/"+gameID,
|
|
)
|
|
}
|
|
}
|
|
|
|
templ NicknamePage(gameID string) {
|
|
@layouts.Base("Connect 4 - Join") {
|
|
@sharedcomponents.NicknamePrompt("/games/" + gameID + "/join")
|
|
}
|
|
}
|