Skip to content

Commit

Permalink
Refactor(views): Improve workout and route segment name display
Browse files Browse the repository at this point in the history
The name display of workouts and route segments has been improved to handle long
names and empty names more gracefully. A new helper function `Name` was added to
handle this consistently across the application.

Fixes #388

Signed-off-by: Jo Vandeginste <[email protected]>
  • Loading branch information
jovandeginste committed Jan 8, 2025
1 parent 04ff381 commit 577ef91
Show file tree
Hide file tree
Showing 24 changed files with 1,046 additions and 998 deletions.
5 changes: 4 additions & 1 deletion views/equipment/show.templ
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/jovandeginste/workout-tracker/pkg/database"
"github.com/jovandeginste/workout-tracker/views/helpers"
"github.com/jovandeginste/workout-tracker/views/partials"
"github.com/jovandeginste/workout-tracker/views/workouts"
)

templ Show(e *database.Equipment) {
Expand Down Expand Up @@ -123,7 +124,9 @@ templ Show(e *database.Equipment) {
</div>
</td>
<td>
<a href={ templ.SafeURL(helpers.RouteFor(ctx, "workout-show", w.ID)) }>{ w.Name }</a>
<a href={ templ.SafeURL(helpers.RouteFor(ctx, "workout-show", w.ID)) }>
@workouts.Name(&w, 20)
</a>
</td>
<td class="hidden sm:table-cell">
@partials.SnippetDate(w.Date)
Expand Down
48 changes: 22 additions & 26 deletions views/equipment/show_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions views/route_segments/details.templ
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package route_segments

import (
"fmt"
"github.com/invopop/ctxi18n/i18n"
"github.com/jovandeginste/workout-tracker/pkg/database"
"github.com/jovandeginste/workout-tracker/views/helpers"
"github.com/jovandeginste/workout-tracker/views/partials"
)

templ Name(s *database.RouteSegment, maxLength int) {
if s.Name == "" {
<i>(no name)</i>
} else if maxLength > 0 && len(s.Name) > maxLength {
<abbr title={ s.Name }>{ fmt.Sprintf("%.*s", maxLength, s.Name) }...</abbr>
} else {
{ s.Name }
}
}

templ details(s *database.RouteSegment) {
{{ preferredUnits := helpers.CurrentUser(ctx).PreferredUnits() }}
<table>
Expand Down
Loading

0 comments on commit 577ef91

Please sign in to comment.