Make messages list update every 3s

This commit is contained in:
Alessio 2024-05-12 17:01:14 -07:00
parent 455639dffd
commit 827c15431c
2 changed files with 11 additions and 1 deletions

View File

@ -142,6 +142,12 @@ func (app *Application) get_message_global_data() (MessageData, PageGlobalData)
return chat_view_data, global_data
}
func (app *Application) messages_refresh_list(w http.ResponseWriter, r *http.Request) {
chat_view_data, global_data := app.get_message_global_data()
chat_view_data.ActiveRoomID = scraper.DMChatRoomID(r.URL.Query().Get("active-chat"))
app.buffered_render_htmx(w, "chat-list", global_data, chat_view_data)
}
func (app *Application) Messages(w http.ResponseWriter, r *http.Request) {
app.traceLog.Printf("'Messages' handler (path: %q)", r.URL.Path)
@ -157,6 +163,10 @@ func (app *Application) Messages(w http.ResponseWriter, r *http.Request) {
}
parts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
if parts[0] == "refresh-list" {
app.messages_refresh_list(w, r)
return
}
room_id := scraper.DMChatRoomID(parts[0])
// Messages index

View File

@ -1,5 +1,5 @@
{{define "chat-list"}}
<div class="chat-list">
<div class="chat-list" hx-get="/messages/refresh-list?active-chat={{.ActiveRoomID}}" hx-swap="outerHTML" hx-trigger="load delay:3s">
{{range .RoomIDs}}
{{template "chat-list-entry" (dict
"room" (index $.Rooms .)