Revert "fix: append chat messages instead of re-rendering entire game"
All checks were successful
CI / Deploy / test (push) Successful in 14s
CI / Deploy / lint (push) Successful in 25s
CI / Deploy / deploy (push) Successful in 3s

This reverts commit 6976b773bd.
This commit is contained in:
Ryan Hamamura
2026-03-03 09:15:42 -10:00
parent 6976b773bd
commit 513467470c
3 changed files with 11 additions and 26 deletions

View File

@@ -23,8 +23,10 @@ type Config struct {
StopKeyPropagation bool
}
// ChatMessage renders a single chat message. Used for appending new messages via SSE.
templ ChatMessage(m chat.Message, cfg Config) {
templ Chat(messages []chat.Message, cfg Config) {
<div id={ cfg.CSSPrefix + "-chat" } class={ cfg.CSSPrefix + "-chat" }>
<div class={ cfg.CSSPrefix + "-chat-history" }>
for _, m := range messages {
<div class={ cfg.CSSPrefix + "-chat-msg" }>
<span style={ fmt.Sprintf("color:%s;font-weight:bold;", cfg.Color(m.Slot)) }>
{ m.Nickname + ": " }
@@ -32,13 +34,6 @@ templ ChatMessage(m chat.Message, cfg Config) {
<span>{ m.Message }</span>
</div>
}
templ Chat(messages []chat.Message, cfg Config) {
<div id={ cfg.CSSPrefix + "-chat" } class={ cfg.CSSPrefix + "-chat" }>
<div id={ cfg.CSSPrefix + "-chat-history" } class={ cfg.CSSPrefix + "-chat-history" }>
for _, m := range messages {
@ChatMessage(m, cfg)
}
</div>
<div class={ cfg.CSSPrefix + "-chat-input" } data-morph-ignore>
if cfg.StopKeyPropagation {

View File

@@ -148,13 +148,8 @@ func HandleGameEvents(store *connect4.Store, nc *nats.Conn, sm *scs.SessionManag
return
}
case msg := <-chatCh:
chatMsg, _ := room.Receive(msg.Data)
err := sse.PatchElementTempl(
chatcomponents.ChatMessage(chatMsg, chatCfg),
datastar.WithSelectorID("c4-chat-history"),
datastar.WithModeAppend(),
)
if err != nil {
room.Receive(msg.Data)
if err := patchAll(); err != nil {
return
}
}

View File

@@ -172,13 +172,8 @@ func HandleSnakeEvents(snakeStore *snake.SnakeStore, nc *nats.Conn, sm *scs.Sess
if msg == nil {
continue
}
chatMsg, _ := room.Receive(msg.Data)
err := sse.PatchElementTempl(
chatcomponents.ChatMessage(chatMsg, chatCfg),
datastar.WithSelectorID("snake-chat-history"),
datastar.WithModeAppend(),
)
if err != nil {
room.Receive(msg.Data)
if err := patchAll(); err != nil {
return
}
}