package pages import ( "fmt" "reichard.io/antholume/database" "reichard.io/antholume/graph" "reichard.io/antholume/ngtemplates/common" ) type UserMetadata struct { DocumentCount int ActivityCount int ProgressCount int DeviceCount int } type UserStatistics struct { WPM map[string][]UserStatisticEntry Duration map[string][]UserStatisticEntry Words map[string][]UserStatisticEntry } type UserStatisticEntry struct { UserID string Value string } templ Home( settings common.Settings, dailyReadSVG graph.SVGGraphData, userStreaks []database.UserStreak, userStatistics UserStatistics, userMetadata UserMetadata, ) { @layout(settings, "Home WAT") {
@DailyReadChart(dailyReadSVG)
@InfoCard("Documents", userMetadata.DocumentCount, "./documents") @InfoCard("Activity Records", userMetadata.ActivityCount, "./activity") @InfoCard("Progress Records", userMetadata.ProgressCount, "./progress") @InfoCard("Devices", userMetadata.DeviceCount, "")
for _, item := range userStreaks { @StreakCard(item) }
@LeaderboardCard("WPM", userStatistics.WPM) @LeaderboardCard("Duration", userStatistics.Duration) @LeaderboardCard("Words", userStatistics.Words)
} } templ infoCardInner(name string, metric int) {

{ fmt.Sprint(metric) }

{ name }

} templ InfoCard(name string, metric int, link string) { if link != "" { @infoCardInner(name, metric) } else {
@infoCardInner(name, metric)
} } templ LeaderboardCard(name string, stats map[string][]UserStatisticEntry) {

{ name } Leaderboard

for name, data := range stats {
if len(data) == 0 {

N/A

} else {

{ data[0].UserID }

}
for idx, item := range data { if idx == 0 {

{ item.UserID }

{ item.Value }
} else if idx < 3 {

{ item.UserID }

{ item.Value }
} }
}
} templ StreakCard(streak database.UserStreak) {

if streak.Window == "WEEK" { Weekly Read Streak } else { Daily Read Streak }

{ fmt.Sprint(streak.CurrentStreak) }

if streak.Window == "WEEK" { Current Read Streak } else { Current Read Streak }

{ streak.CurrentStreakStartDate } ➞ { streak.CurrentStreakEndDate }
{ fmt.Sprint(streak.CurrentStreak) }

if streak.Window == "WEEK" { Best Weekly Streak } else { Best Daily Streak }

{ streak.MaxStreakStartDate } ➞ { streak.MaxStreakEndDate }
{ fmt.Sprint(streak.MaxStreak) }
} templ DailyReadChart(dailyReadSVG graph.SVGGraphData) {

Daily Read Totals

for _, item := range dailyReadSVG.LinePoints {
{ item.Data.Label } { fmt.Sprint(item.Data.Value) } minutes
}
}