92 lines
1.8 KiB
Go
92 lines
1.8 KiB
Go
package components
|
|
|
|
import (
|
|
"dk/internal/middleware"
|
|
"dk/internal/router"
|
|
"dk/internal/template"
|
|
"dk/internal/towns"
|
|
"dk/internal/users"
|
|
)
|
|
|
|
// LeftAside generates the left sidebar content
|
|
func LeftAside(ctx router.Ctx) string {
|
|
if !middleware.IsAuthenticated(ctx) {
|
|
return ""
|
|
}
|
|
|
|
leftSideTmpl, err := template.Cache.Load("leftside.html")
|
|
if err != nil {
|
|
return "leftside failed to load?"
|
|
}
|
|
|
|
currentUser := middleware.GetCurrentUser(ctx)
|
|
if currentUser == nil {
|
|
return "no currentUser?"
|
|
}
|
|
|
|
user, err := users.Find(currentUser.ID)
|
|
if err != nil {
|
|
return "user not found?"
|
|
}
|
|
|
|
cardinalX := "E"
|
|
if user.X < 0 {
|
|
cardinalX = "W"
|
|
}
|
|
|
|
cardinalY := "S"
|
|
if user.Y < 0 {
|
|
cardinalY = "N"
|
|
}
|
|
|
|
townname := ""
|
|
if user.Currently == "In Town" {
|
|
town, err := towns.ByCoords(user.X, user.Y)
|
|
if err != nil {
|
|
townname = "error finding town"
|
|
}
|
|
townname = "<b>In " + town.Name + "</b>"
|
|
}
|
|
|
|
leftSideData := map[string]any{
|
|
"user": user.ToMap(),
|
|
"cardinalX": cardinalX,
|
|
"cardinalY": cardinalY,
|
|
"townname": townname,
|
|
"townlist": "@TODO",
|
|
}
|
|
|
|
return leftSideTmpl.RenderNamed(leftSideData)
|
|
}
|
|
|
|
// RightAside generates the right sidebar content
|
|
func RightAside(ctx router.Ctx) string {
|
|
if !middleware.IsAuthenticated(ctx) {
|
|
return ""
|
|
}
|
|
|
|
// Load and render the rightside template with user data
|
|
rightSideTmpl, err := template.Cache.Load("rightside.html")
|
|
if err != nil {
|
|
return "" // Silently fail - sidebar is optional
|
|
}
|
|
|
|
// Get the current user from session
|
|
currentUser := middleware.GetCurrentUser(ctx)
|
|
if currentUser == nil {
|
|
return ""
|
|
}
|
|
|
|
user, err := users.Find(currentUser.ID)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
// Pass the user object directly to the template
|
|
rightSideData := map[string]any{
|
|
"user": user.ToMap(),
|
|
}
|
|
|
|
return rightSideTmpl.RenderNamed(rightSideData)
|
|
}
|