added better links to teams and players
This commit is contained in:
54
internal/view/component/links/links.templ
Normal file
54
internal/view/component/links/links.templ
Normal file
@@ -0,0 +1,54 @@
|
||||
package links
|
||||
|
||||
import "git.haelnorr.com/h/oslstats/internal/db"
|
||||
import "fmt"
|
||||
|
||||
// PlayerLink renders a player name as a clickable link to their profile page.
|
||||
// The player's DisplayName() is used as the link text.
|
||||
templ PlayerLink(player *db.Player) {
|
||||
<a
|
||||
href={ templ.SafeURL(fmt.Sprintf("/players/%d", player.ID)) }
|
||||
class="text-text hover:text-blue transition"
|
||||
>
|
||||
{ player.DisplayName() }
|
||||
</a>
|
||||
}
|
||||
|
||||
// PlayerLinkFromStats renders a player name link using a player ID and name string.
|
||||
// This is useful when only aggregated stats are available (no full Player object).
|
||||
templ PlayerLinkFromStats(playerID int, playerName string) {
|
||||
<a
|
||||
href={ templ.SafeURL(fmt.Sprintf("/players/%d", playerID)) }
|
||||
class="text-text hover:text-blue transition"
|
||||
>
|
||||
{ playerName }
|
||||
</a>
|
||||
}
|
||||
|
||||
// TeamLinkInSeason renders a team name as a clickable link to the team's
|
||||
// season-specific detail page, with an optional color dot prefix.
|
||||
templ TeamLinkInSeason(team *db.Team, season *db.Season, league *db.League) {
|
||||
<a
|
||||
href={ templ.SafeURL(fmt.Sprintf("/seasons/%s/leagues/%s/teams/%d", season.ShortName, league.ShortName, team.ID)) }
|
||||
class="flex items-center gap-2 hover:text-blue transition"
|
||||
>
|
||||
if team.Color != "" {
|
||||
<span
|
||||
class="w-3 h-3 rounded-full shrink-0"
|
||||
style={ "background-color: " + templ.SafeCSS(team.Color) }
|
||||
></span>
|
||||
}
|
||||
<span class="text-sm font-medium">{ team.Name }</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
// TeamNameLinkInSeason renders just the team name as a clickable link (no color dot).
|
||||
// Useful where the color dot is already rendered separately or in inline contexts.
|
||||
templ TeamNameLinkInSeason(team *db.Team, season *db.Season, league *db.League) {
|
||||
<a
|
||||
href={ templ.SafeURL(fmt.Sprintf("/seasons/%s/leagues/%s/teams/%d", season.ShortName, league.ShortName, team.ID)) }
|
||||
class="hover:text-blue transition"
|
||||
>
|
||||
{ team.Name }
|
||||
</a>
|
||||
}
|
||||
Reference in New Issue
Block a user