Skip to content

Commit

Permalink
feat: ship details tab
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Apr 6, 2024
1 parent da24e46 commit cff00cf
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 9 deletions.
1 change: 1 addition & 0 deletions darkstat/front/shared.templ
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ templ TabMenu(url utils_types.FilePath) {
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Shields.ToString() } class={ templ.KV("selected", urls.Shields == url) } role="tab" aria-selected="false" aria-controls="tab-content">Shields</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Thrusters.ToString() } class={ templ.KV("selected", urls.Thrusters == url) } role="tab" aria-selected="false" aria-controls="tab-content">Thrusters</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.Ships.ToString() } class={ templ.KV("selected", urls.Ships == url) } role="tab" aria-selected="false" aria-controls="tab-content">Ships</button>
<button hx-get={ types.GetCtx(ctx).SiteRoot + urls.ShipDetails.ToString() } class={ templ.KV("selected", urls.ShipDetails == url) } role="tab" aria-selected="false" aria-controls="tab-content">Ship Details</button>
</div>
}
<hr/>
Expand Down
66 changes: 60 additions & 6 deletions darkstat/front/ships.templ
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,30 @@ import (
"strings"
)

func ShipDetailedUrl(ship configs_export.Ship) string {
return "ships/ships_base_" + strings.ToLower(ship.Nickname)
func ShipDetailedUrl(ship configs_export.Ship, mode ShipTabMode) string {
if mode == ShipShowBases {
return "ships/ships_base_" + strings.ToLower(ship.Nickname)
} else if mode == ShipShowDetails {
return "ships/ships_details_" + strings.ToLower(ship.Nickname)
}
panic("unsupported ship mode")
}

type ShipTabMode int64

const (
ShipShowBases ShipTabMode = iota
ShipShowDetails
)

// https://www.cssscript.com/minimalist-table-sortable/#:~:text=Description%3A-,sorttable.,clicking%20on%20the%20table%20headers
// https://www.cssscript.com/fast-html-table-sorting/
templ ShipsT(ships []configs_export.Ship) {
@TabMenu(urls.Ships)
templ ShipsT(ships []configs_export.Ship, mode ShipTabMode) {
if mode == ShipShowBases {
@TabMenu(urls.Ships)
} else if mode == ShipShowDetails {
@TabMenu(urls.ShipDetails)
}
@TabContent() {
<div class="splitter">
<div id="table-wrapper">
Expand Down Expand Up @@ -54,7 +70,7 @@ templ ShipsT(ships []configs_export.Ship) {
for _, ship := range ships {
<tr
id={ "bottominfo_click" + ship.Nickname }
hx-get={ types.GetCtx(ctx).SiteRoot + ShipDetailedUrl(ship) }
hx-get={ types.GetCtx(ctx).SiteRoot + ShipDetailedUrl(ship, mode) }
hx-trigger="click"
hx-target="#table-bottom"
hx-swap="innerHTML"
Expand Down Expand Up @@ -96,7 +112,11 @@ templ ShipsT(ships []configs_export.Ship) {
</table>
</div>
<div id="table-bottom">
@GoodAtBaseSharedT(ShowPricePerVolume(false))
if mode == ShipShowBases {
@GoodAtBaseSharedT(ShowPricePerVolume(false))
} else if mode == ShipShowDetails {
@ShipDetailsShared([]string{})
}
</div>
</div>
<div id="infocard_view">
Expand All @@ -105,3 +125,37 @@ templ ShipsT(ships []configs_export.Ship) {
</div>
}
}

templ ShipDetailsShared(columns []string) {
<table class="sortable">
<thead>
<tr class="flexed-tr">
<th style="width:50px;">Ship Hardpoint</th>
for index, _ := range columns {
<th style="width:50px;">Equip { strconv.Itoa(index) }</th>
}
<th style="max-width:100%;"></th>
</tr>
</thead>
<tbody>
{ children... }
</tbody>
</table>
}

templ ShipDetails(ship configs_export.Ship) {
@ShipDetailsShared(ship.BiggestHardpoint) {
for _, slot := range ship.Slots {
<tr>
<td>{ slot.SlotName }</td>
for _, equip := range slot.AllowedEquip {
<td>{ equip }</td>
}
for _, _ = range ship.BiggestHardpoint[len(slot.AllowedEquip):] {
<td></td>
}
<td></td>
</tr>
}
}
}
1 change: 1 addition & 0 deletions darkstat/front/urls/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ const (
Shields utils_types.FilePath = "shields.html"
Thrusters utils_types.FilePath = "thrusters.html"
Ships utils_types.FilePath = "ships.html"
ShipDetails utils_types.FilePath = "ship_details.html"
)
12 changes: 10 additions & 2 deletions darkstat/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ func (l *Linker) Link() *builder.Builder {
),
builder.NewComponent(
urls.Ships,
front.ShipsT(data.Ships),
front.ShipsT(data.Ships, front.ShipShowBases),
),
builder.NewComponent(
urls.ShipDetails,
front.ShipsT(data.Ships, front.ShipShowDetails),
),
)

Expand Down Expand Up @@ -310,9 +314,13 @@ func (l *Linker) Link() *builder.Builder {
for _, ship := range data.Ships {
build.RegComps(
builder.NewComponent(
utils_types.FilePath(front.ShipDetailedUrl(ship)),
utils_types.FilePath(front.ShipDetailedUrl(ship, front.ShipShowBases)),
front.GoodAtBaseInfoT(ship.Bases, front.ShowPricePerVolume(false)),
),
builder.NewComponent(
utils_types.FilePath(front.ShipDetailedUrl(ship, front.ShipShowDetails)),
front.ShipDetails(ship),
),
)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.1

require (
github.com/a-h/templ v0.2.543
github.com/darklab8/fl-configs v0.26.0
github.com/darklab8/fl-configs v0.27.0
github.com/darklab8/go-typelog v0.6.0
github.com/darklab8/go-utils v0.12.0
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ github.com/darklab8/fl-configs v0.25.0 h1:A3ydu6zAiA8Szsv7bCaatsHDz1qdRGXhkQBUkB
github.com/darklab8/fl-configs v0.25.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.26.0 h1:sxNYGvvUqSh+x7h6HJx7cCAeZBmvUCtf12kHYhwnYtA=
github.com/darklab8/fl-configs v0.26.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/fl-configs v0.27.0 h1:z62lSXdPSw1Qq9z860iVRHtT6l6qkzBEbAxsrG+esFs=
github.com/darklab8/fl-configs v0.27.0/go.mod h1:8zaCaFL21TvawP65KB9NOJ+nEpaMDQYsnoOi77RiSVY=
github.com/darklab8/go-typelog v0.6.0 h1:Ci8imc7ScXiy5e1qMgf46NyJjrqNLPoIE1gbVe7bxl4=
github.com/darklab8/go-typelog v0.6.0/go.mod h1:AwwOf3dkp/tpevHFNbkB+PbwlDrUUgO1CVFkEnj+q5w=
github.com/darklab8/go-utils v0.12.0 h1:LxsG3yVNf9W4xyV+tHPOaZB2ewItgM/1BzOXyKFvofs=
Expand Down

0 comments on commit cff00cf

Please sign in to comment.