all repos — well-binge @ 534e397c0e1c59345f80638baeb559dca6c2de86

Create positive, recurring habits.

add habit feedback
Marco Andronaco andronacomarco@gmail.com
Fri, 18 Oct 2024 12:12:40 +0200
commit

534e397c0e1c59345f80638baeb559dca6c2de86

parent

80150294670e221c25fd3ddab40d0301775d0e60

2 files changed, 103 insertions(+), 32 deletions(-)

jump to
M src/app/functions.gosrc/app/functions.go

@@ -154,39 +154,55 @@

return user, ok } -func formatDuration(t time.Time) string { - days := int(time.Since(t).Hours()) / 24 +func formatDuration(t time.Time) (days int, s string) { + days = int(time.Since(t).Hours()) / 24 switch { case days == 0: - return "Today" + s = "Today" case days == 1: - return "Yesterday" + s = "Yesterday" case days <= 7: - return fmt.Sprintf("%d day(s) ago", days) + s = fmt.Sprintf("%d day(s) ago", days) case days <= 30: weeks := days / 7 remainingDays := days % 7 if remainingDays == 0 { - return fmt.Sprintf("%d week(s) ago", weeks) + s = fmt.Sprintf("%d week(s) ago", weeks) + } else { + s = fmt.Sprintf("%d week(s), %d day(s) ago", weeks, remainingDays) } - return fmt.Sprintf("%d wee(k), %d day(s) ago", weeks, remainingDays) default: months := days / 30 remainingDays := days % 30 if remainingDays == 0 { - return fmt.Sprintf("%d month(s) ago", months) + s = fmt.Sprintf("%d month(s) ago", months) + } else { + s = fmt.Sprintf("%d month(s), %d day(s) ago", months, remainingDays) } - return fmt.Sprintf("%d month(s), %d day(s) ago", months, remainingDays) } + return } func toHabitDisplay(habit Habit) HabitDisplay { - var lastAck string - if habit.LastAck == nil { - lastAck = "-" + var ( + days int + lastAck string + class string + ) + + if habit.LastAck != nil { + days, lastAck = formatDuration(*habit.LastAck) + class = getClassForAck(habit, days) } else { - lastAck = formatDuration(*habit.LastAck) + lastAck = "-" + if habit.Negative { + class = classGood + } + + if !habit.Disabled { + class = classBad + } } return HabitDisplay{

@@ -194,7 +210,33 @@ ID: habit.ID,

Name: habit.Name, LastAck: lastAck, Disabled: habit.Disabled, - Class: classGood, + Class: class, + } +} + +func getClassForAck(habit Habit, days int) string { + if habit.Negative { + switch { + case days <= 1: + return classBad + case days <= 7: + return classWarn + default: + return classGood + } + } + + if habit.Disabled { + return "" + } + + switch { + case days <= 1: + return classGood + case days <= int(habit.Days): + return classWarn + default: + return classBad } }
M static/style.cssstatic/style.css

@@ -1,35 +1,64 @@

label { - display: grid; - grid-template-columns: auto auto; - align-items: center; - justify-items: start; - align-content: center; - justify-content: space-between; - max-width: 350px; + display: grid; + grid-template-columns: auto auto; + align-items: center; + justify-items: start; + align-content: center; + justify-content: space-between; + max-width: 350px; } label > input { - max-width: 250px; + max-width: 250px; } .habits-title { - display: grid; - grid-template-columns: auto auto; - justify-content: space-between; - align-items: center + display: grid; + grid-template-columns: auto auto; + justify-content: space-between; + align-items: center; } .actions { - display: grid; - grid-template-columns: auto auto; - justify-items: center; - justify-content: center; + display: grid; + grid-template-columns: auto auto; + justify-items: center; + justify-content: center; } .actions > form { - padding-inline: 5px; + padding-inline: 5px; } thead { - font-weight: bold; + font-weight: bold; +} + +.good { + background-color: hsl(120, 50%, 10%) !important; +} + +.bad { + background-color: hsl(0, 50%, 10%) !important; +} + +.warn { + background-color: hsl(60, 50%, 10%) !important; +} + +@media (prefers-color-scheme: light) { + .good { + background-color: hsl(120, 50%, 85%) !important; + color: black; + } + + .bad { + background-color: hsl(0, 50%, 85%) !important; + color: black; + } + + .warn { + background-color: hsl(60, 50%, 85%) !important; + color: black; + } }