feat: use consistent tooltip pattern for time
Amolith
and
Crush
created 2 weeks ago
Modify the author/time info on the home page to follow the same
tooltip pattern as the commits page, displaying "Updated {time}".
- Change HomeRepository.UpdatedAt from string to time.Time
- Convert timestamps to UTC for consistency
- Clean up tooltip format to show timezone only once
- Remove unused humanize import
Implements: bug-af63a29
Co-Authored-By: Crush <crush@charm.land>
Change summary
pkg/web/templates/home.html | 2 +-
pkg/web/webui.go | 11 ++++++++---
pkg/web/webui_home.go | 7 +++----
3 files changed, 12 insertions(+), 8 deletions(-)
Detailed changes
@@ -24,7 +24,7 @@
<br>
{{end}}
{{if .UpdatedAt}}
- Updated {{.UpdatedAt}}
+ Updated <time datetime="{{.UpdatedAt | rfc3339}}" data-tooltip="{{.UpdatedAt | formatDate}}">{{.UpdatedAt | relativeTime}}</time>
{{end}}
</small>
</footer>
@@ -111,10 +111,15 @@ var templateFuncs = template.FuncMap{
return hashStr
},
"formatDate": func(t interface{}) string {
- if time, ok := t.(fmt.Stringer); ok {
- return time.String()
+ switch v := t.(type) {
+ case time.Time:
+ return v.Format("2006-01-02 15:04:05 UTC")
+ default:
+ if time, ok := t.(fmt.Stringer); ok {
+ return time.String()
+ }
+ return fmt.Sprintf("%v", t)
}
- return fmt.Sprintf("%v", t)
},
"humanizeSize": func(size int64) string {
const unit = 1024
@@ -15,7 +15,6 @@ import (
"github.com/charmbracelet/soft-serve/pkg/config"
"github.com/charmbracelet/soft-serve/pkg/proto"
"github.com/charmbracelet/soft-serve/pkg/ui/common"
- "github.com/dustin/go-humanize"
)
type HomeRepository struct {
@@ -24,7 +23,7 @@ type HomeRepository struct {
Description string
IsPrivate bool
CloneURL string
- UpdatedAt string
+ UpdatedAt time.Time
}
type HomeData struct {
@@ -135,9 +134,9 @@ func home(w http.ResponseWriter, r *http.Request) {
description := strings.TrimSpace(repo.Description())
cloneURL := common.RepoURL(cfg.SSH.PublicURL, name)
- var updatedAt string
+ var updatedAt time.Time
if item.lastUpdate != nil {
- updatedAt = humanize.Time(*item.lastUpdate)
+ updatedAt = item.lastUpdate.UTC()
}
homeRepos = append(homeRepos, HomeRepository{