chore: updated list of habbits on admin dashboard 7c11f395
Steve Simkins · 2026-08-12 20:59 3 file(s) · +21 −67
apps/habbits/app.go +3 −16
52 52
	RecordedAtInput string
53 53
}
54 54
55 -
// dashDay groups a day's records by habit for the dashboard (day -> habit -> records).
56 -
type dashDay struct {
57 -
	Date   string
58 -
	Habits []dashHabit
59 -
}
60 -
61 -
type dashHabit struct {
62 -
	HabitName    string
63 -
	HabitShortID string
64 -
	ValueType    string
65 -
	Unit         string
66 -
	Records      []recordRow
67 -
}
68 -
69 -
// habitDay groups a single habit's records by day for the habit detail page.
55 +
// habitDay groups records by day. Used for both the dashboard (all habits,
56 +
// records interleaved chronologically) and the habit detail page.
70 57
type habitDay struct {
71 58
	Date    string
72 59
	Records []recordRow
80 67
	Success string
81 68
	Error   string
82 69
	Habits  []habitRow
83 -
	Days    []dashDay
70 +
	Days    []habitDay
84 71
}
85 72
86 73
type newHabitPageData struct {
apps/habbits/handlers_web.go +3 −34
41 41
	}
42 42
}
43 43
44 -
// groupDashboard buckets records (ordered recorded_at DESC) into day groups,
45 -
// and within each day into per-habit groups, preserving encounter order.
46 -
func groupDashboard(recs []Record) []dashDay {
47 -
	var days []dashDay
48 -
	dayIdx := map[string]int{}
49 -
	habitIdx := map[string]map[string]int{}
50 -
	for _, r := range recs {
51 -
		row := recordToRow(r)
52 -
		di, ok := dayIdx[row.Date]
53 -
		if !ok {
54 -
			di = len(days)
55 -
			dayIdx[row.Date] = di
56 -
			habitIdx[row.Date] = map[string]int{}
57 -
			days = append(days, dashDay{Date: row.Date})
58 -
		}
59 -
		hi, ok := habitIdx[row.Date][r.HabitShortID]
60 -
		if !ok {
61 -
			hi = len(days[di].Habits)
62 -
			habitIdx[row.Date][r.HabitShortID] = hi
63 -
			days[di].Habits = append(days[di].Habits, dashHabit{
64 -
				HabitName:    r.HabitName,
65 -
				HabitShortID: r.HabitShortID,
66 -
				ValueType:    r.ValueType,
67 -
				Unit:         r.Unit,
68 -
			})
69 -
		}
70 -
		days[di].Habits[hi].Records = append(days[di].Habits[hi].Records, row)
71 -
	}
72 -
	return days
73 -
}
74 -
75 -
// groupByDay buckets a single habit's records (ordered recorded_at DESC) into
76 -
// day groups, preserving encounter order.
44 +
// groupByDay buckets records (ordered recorded_at DESC) into day groups,
45 +
// preserving encounter order so records stay chronological within a day.
77 46
func groupByDay(recs []Record) []habitDay {
78 47
	var days []habitDay
79 48
	idx := map[string]int{}
164 133
		Success: r.URL.Query().Get("success"),
165 134
		Error:   r.URL.Query().Get("error"),
166 135
		Habits:  habitRows,
167 -
		Days:    groupDashboard(records),
136 +
		Days:    groupByDay(records),
168 137
	}, a.Log)
169 138
}
170 139
apps/habbits/templates/index.html +15 −17
83 83
      {{range .Days}}
84 84
      <div class="day-group">
85 85
        <h3 class="day-heading">{{.Date}}</h3>
86 -
        {{range .Habits}}
87 -
        <div class="habit-group">
88 -
          <a class="habit-group-name" href="/habits/{{.HabitShortID}}">{{.HabitName}}</a>
89 -
          <ul class="admin-list">
90 -
            {{range .Records}}
91 -
            <li class="admin-list-item">
92 -
              <div class="admin-list-info">
93 -
                <span class="admin-list-title">{{.Value}}{{if .Unit}} {{.Unit}}{{end}}</span>
94 -
                <span class="admin-list-meta">
95 -
                  <span class="admin-list-date">{{.TimeDisplay}}</span>
96 -
                </span>
97 -
              </div>
98 -
            </li>
99 -
            {{end}}
100 -
          </ul>
101 -
        </div>
102 -
        {{end}}
86 +
        <ul class="admin-list">
87 +
          {{range .Records}}
88 +
          <li class="admin-list-item">
89 +
            <div class="admin-list-info">
90 +
              <span class="admin-list-title">
91 +
                <a href="/habits/{{.HabitShortID}}">{{.HabitName}}</a>
92 +
                {{.Value}}{{if .Unit}} {{.Unit}}{{end}}
93 +
              </span>
94 +
              <span class="admin-list-meta">
95 +
                <span class="admin-list-date">{{.TimeDisplay}}</span>
96 +
              </span>
97 +
            </div>
98 +
          </li>
99 +
          {{end}}
100 +
        </ul>
103 101
      </div>
104 102
      {{end}}
105 103
      {{end}}