Revert "fix: append chat messages instead of re-rendering entire game"
This reverts commit 6976b773bd.
This commit is contained in:
@@ -23,21 +23,16 @@ type Config struct {
|
|||||||
StopKeyPropagation bool
|
StopKeyPropagation bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChatMessage renders a single chat message. Used for appending new messages via SSE.
|
templ Chat(messages []chat.Message, cfg Config) {
|
||||||
templ ChatMessage(m 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" }>
|
<div class={ cfg.CSSPrefix + "-chat-msg" }>
|
||||||
<span style={ fmt.Sprintf("color:%s;font-weight:bold;", cfg.Color(m.Slot)) }>
|
<span style={ fmt.Sprintf("color:%s;font-weight:bold;", cfg.Color(m.Slot)) }>
|
||||||
{ m.Nickname + ": " }
|
{ m.Nickname + ": " }
|
||||||
</span>
|
</span>
|
||||||
<span>{ m.Message }</span>
|
<span>{ m.Message }</span>
|
||||||
</div>
|
</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>
|
||||||
<div class={ cfg.CSSPrefix + "-chat-input" } data-morph-ignore>
|
<div class={ cfg.CSSPrefix + "-chat-input" } data-morph-ignore>
|
||||||
|
|||||||
@@ -148,13 +148,8 @@ func HandleGameEvents(store *connect4.Store, nc *nats.Conn, sm *scs.SessionManag
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
case msg := <-chatCh:
|
case msg := <-chatCh:
|
||||||
chatMsg, _ := room.Receive(msg.Data)
|
room.Receive(msg.Data)
|
||||||
err := sse.PatchElementTempl(
|
if err := patchAll(); err != nil {
|
||||||
chatcomponents.ChatMessage(chatMsg, chatCfg),
|
|
||||||
datastar.WithSelectorID("c4-chat-history"),
|
|
||||||
datastar.WithModeAppend(),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,13 +172,8 @@ func HandleSnakeEvents(snakeStore *snake.SnakeStore, nc *nats.Conn, sm *scs.Sess
|
|||||||
if msg == nil {
|
if msg == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
chatMsg, _ := room.Receive(msg.Data)
|
room.Receive(msg.Data)
|
||||||
err := sse.PatchElementTempl(
|
if err := patchAll(); err != nil {
|
||||||
chatcomponents.ChatMessage(chatMsg, chatCfg),
|
|
||||||
datastar.WithSelectorID("snake-chat-history"),
|
|
||||||
datastar.WithModeAppend(),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user