diff --git a/internal/web/static/style.css b/internal/web/static/style.css index 87b4027..356e32a 100644 --- a/internal/web/static/style.css +++ b/internal/web/static/style.css @@ -91,7 +91,7 @@ ul.recent .amt { font-weight: 600; } ul.recent .meta { color: #333; } ul.recent .atts { margin-left: .15rem; } ul.recent .atts a { text-decoration: none; } -ul.recent .when { color: #999; font-size: .8rem; margin-left: .35rem; } +ul.recent .when { color: #999; font-size: .8rem; margin-left: .35rem; white-space: nowrap; } p.pager { margin-top: 1rem; } .err { diff --git a/internal/web/views.go b/internal/web/views.go index c88ee8e..6c3d888 100644 --- a/internal/web/views.go +++ b/internal/web/views.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "time" "maisym.com/hsa/internal/receipt" @@ -129,7 +130,7 @@ func (s *Server) renderRecent(w http.ResponseWriter, r *http.Request, orderBy, t Date: row.ReceiptDate.Format(dateLayout), Amount: dollars(row.AmountCents), Category: row.Category, - Who: row.Who, + Who: shortWho(row.Who), When: row.UploadedAt.Local().Format("2006-01-02 15:04"), Filename: row.OriginalFilename, Attachments: links, @@ -224,6 +225,17 @@ func (s *Server) handleAttachmentFile(w http.ResponseWriter, r *http.Request) { http.ServeContent(w, r, a.OriginalFilename, a.UploadedAt, bytes.NewReader(a.ImageData)) } +// shortWho abbreviates a "First Last" person label to "F. Last" to keep the recent +// list compact on narrow screens. Single-word or empty labels are left as-is. +func shortWho(label string) string { + fields := strings.Fields(label) + if len(fields) < 2 { + return label + } + first := []rune(fields[0]) + return string(first[0]) + ". " + fields[len(fields)-1] +} + // dollars formats integer cents as a plain dollar string, e.g. 1234 -> "12.34". func dollars(cents int64) string { if cents < 0 {