refactor: use computed signals in pubsub-crud and chatroom examples
Some checks failed
CI / Build and Test (push) Has been cancelled

This commit is contained in:
Ryan Hamamura
2026-02-19 09:03:13 -10:00
parent 6763e1a420
commit f3a9c8036f
2 changed files with 15 additions and 13 deletions

View File

@@ -18,6 +18,12 @@ func ProfilePage(c *via.Context) {
via.MaxLen(20, "Must be at most 20 characters"),
)
selectedEmoji := c.Signal(existingEmoji)
previewName := c.Computed(func() string {
if name := nameField.String(); name != "" {
return name
}
return "Your Name"
})
saveToSession := func() bool {
if !c.ValidateAll() {
@@ -68,18 +74,13 @@ func ProfilePage(c *via.Context) {
h.Button(h.Text("Start Chatting"), saveAndChat.OnClick()),
)
previewName := nameField.String()
if previewName == "" {
previewName = "Your Name"
}
return h.Div(h.Class("profile-page"),
h.H2(h.Text("Your Profile"), h.DataViewTransition("page-title")),
// Live preview
h.Div(h.Class("profile-preview"),
h.Div(h.Class("avatar avatar-lg"), h.Text(selectedEmoji.String())),
h.Span(h.Class("preview-name"), h.Text(previewName)),
h.Span(h.Class("preview-name"), previewName.Text()),
),
h.Div(h.Class("profile-form"),