From 70d3aef8b3384bc0768cc874e6c33b3fd466d340 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Sat, 14 Mar 2026 20:03:46 +0000 Subject: [PATCH] Re-select selected communication on fetch This makes it so the UI updates with any changes we pull down. --- api/communication.go | 5 ----- html/template/sync/communication-root.html | 9 +++++++++ platform/types/contact.go | 4 +++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/api/communication.go b/api/communication.go index 5afbcd50..60fd46f0 100644 --- a/api/communication.go +++ b/api/communication.go @@ -19,11 +19,6 @@ type historyEntry struct { Action string `json:"action"` Timestamp time.Time `json:"timestamp"` } -type reporter struct { - HasEmail bool `json:"has_email"` - HasPhone bool `json:"has_phone"` - Name string `json:"name"` -} type communication struct { Created time.Time `json:"created"` History []historyEntry `json:"history"` diff --git a/html/template/sync/communication-root.html b/html/template/sync/communication-root.html index bc472acd..9b7b07a2 100644 --- a/html/template/sync/communication-root.html +++ b/html/template/sync/communication-root.html @@ -101,6 +101,15 @@ const data = await response.json(); this.communications = data.communications || data; // Handle different response formats + // if we already had something selected, reset it using the new data + if (this.selectedCommunication) { + const matching = this.communications.filter((report) => { + return report.id == this.selectedCommunication.id; + }); + if (matching.length > 0) { + this.selectedCommunication = matching[0]; + } + } } catch (err) { console.error("Error loading communications:", err); throw err; diff --git a/platform/types/contact.go b/platform/types/contact.go index 855e2018..5aa1a5d3 100644 --- a/platform/types/contact.go +++ b/platform/types/contact.go @@ -2,6 +2,7 @@ package types import ( "encoding/json" + //"github.com/rs/zerolog/log" ) type Contact struct { @@ -12,10 +13,11 @@ type Contact struct { Phone *string `db:"phone" json:"-"` } -func (c *Contact) MarshalJSON() ([]byte, error) { +func (c Contact) MarshalJSON() ([]byte, error) { to_marshal := make(map[string]interface{}, 0) to_marshal["name"] = c.Name to_marshal["has_email"] = (c.Email != nil && *c.Email != "") to_marshal["has_phone"] = (c.Phone != nil && *c.Phone != "") + //log.Debug().Msg("marshaling contact") return json.Marshal(to_marshal) }