kettlebell-tracker/internal/ui/home.go

80 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ui
import (
"fmt"
"log"
"git.patanix.de/git/kettlebell-app/internal/data"
"git.patanix.de/git/kettlebell-app/internal/services"
"git.patanix.de/git/kettlebell-app/internal/ui/theme"
"git.patanix.de/git/kettlebell-app/internal/ui/utils"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
func MakeHomeScreen(ts *services.TrainingService, db *data.DatabaseService, onStart func()) fyne.CanvasObject {
// Header
headerTitle := canvas.NewText("Patanix", theme.ColorSlate200)
headerTitle.TextSize = 28
headerTitle.TextStyle.Bold = true
header := container.NewVBox(
widget.NewLabel("Hallo,"),
headerTitle,
)
// Nächstes Training CTA
state := ts.State
nextTrainingCard := widget.NewCard(
"Nächstes Training",
fmt.Sprintf("%s - Tag %d", state.CurrentProgram, state.CurrentBlockDay),
container.NewVBox(
widget.NewLabel(fmt.Sprintf("Ziel: %d Wiederholungen pro Satz", state.CurrentReps)),
widget.NewButton("Training starten", onStart),
),
)
// Letzte Leistung
setsValue := widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
durationValue := widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
weightValue := widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
statsCard := widget.NewCard("Letzte Leistung", "", container.NewGridWithColumns(3,
container.NewVBox(widget.NewLabel("Sätze"), setsValue),
container.NewVBox(widget.NewLabel("Dauer"), durationValue),
container.NewVBox(widget.NewLabel("Gewicht"), weightValue),
))
// Funktion zum Laden der letzten Leistung
loadLastPerformance := func() {
lastSession, err := db.GetLastTraining()
if err != nil {
log.Printf("Fehler beim Laden der letzten Session: %v", err)
return
}
if lastSession != nil {
setsValue.SetText(fmt.Sprintf("%d", lastSession.Sets))
durationValue.SetText(utils.FormatDuration(lastSession.Duration))
weightValue.SetText(fmt.Sprintf("%.1fkg", lastSession.WeightLeft)) // Annahme: linkes Gewicht ist repräsentativ
}
}
layout := container.NewVBox(
header,
widget.NewSeparator(),
nextTrainingCard,
statsCard,
)
paddedLayout := container.NewPadded(layout)
// Daten laden, wenn der Bildschirm sichtbar wird
if paddedLayout.Visible() {
loadLastPerformance()
}
// paddedLayout.OnVisible = loadLastPerformance
return paddedLayout
}