feat: one-week schedule view always starting on Monday

This commit is contained in:
Niklas Ye
2026-05-22 11:56:47 +02:00
parent d4839c9f6b
commit f8e085e610
3 changed files with 14 additions and 9 deletions
+7 -2
View File
@@ -198,7 +198,12 @@ func NewModel(client *api.Client, serverURL string, refreshInterval time.Duratio
revokeIn.CharLimit = 20 revokeIn.CharLimit = 20
now := time.Now().UTC() now := time.Now().UTC()
window := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC) today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
weekday := int(today.Weekday())
if weekday == 0 {
weekday = 7 // ISO: Sunday = 7
}
window := today.AddDate(0, 0, -(weekday - 1))
return Model{ return Model{
client: client, client: client,
@@ -406,7 +411,7 @@ func buildScheduleDays(window time.Time, entries []api.ScheduleEntry) []schedule
for _, e := range entries { for _, e := range entries {
entryMap[e.Date] = e entryMap[e.Date] = e
} }
days := make([]scheduleDay, 14) days := make([]scheduleDay, 7)
for i := range days { for i := range days {
date := window.AddDate(0, 0, i) date := window.AddDate(0, 0, i)
day := scheduleDay{date: date} day := scheduleDay{date: date}
+6 -6
View File
@@ -271,7 +271,7 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
if next == sectionSchedule && len(m.scheduleDays) == 0 { if next == sectionSchedule && len(m.scheduleDays) == 0 {
m.scheduleLoading = true m.scheduleLoading = true
from := m.scheduleWindow from := m.scheduleWindow
to := m.scheduleWindow.AddDate(0, 0, 13) to := m.scheduleWindow.AddDate(0, 0, 6)
return m, fetchScheduleCmd(m.client, from, to) return m, fetchScheduleCmd(m.client, from, to)
} }
if next == sectionUsers && len(m.users) == 0 { if next == sectionUsers && len(m.users) == 0 {
@@ -287,7 +287,7 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
if m.activeSection == sectionSchedule { if m.activeSection == sectionSchedule {
m.scheduleLoading = true m.scheduleLoading = true
from := m.scheduleWindow from := m.scheduleWindow
to := m.scheduleWindow.AddDate(0, 0, 13) to := m.scheduleWindow.AddDate(0, 0, 6)
return m, fetchScheduleCmd(m.client, from, to) return m, fetchScheduleCmd(m.client, from, to)
} }
if m.activeSection == sectionUsers { if m.activeSection == sectionUsers {
@@ -336,7 +336,7 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
m.scheduleWindow = m.scheduleWindow.AddDate(0, 0, -7) m.scheduleWindow = m.scheduleWindow.AddDate(0, 0, -7)
m.scheduleLoading = true m.scheduleLoading = true
from := m.scheduleWindow from := m.scheduleWindow
to := m.scheduleWindow.AddDate(0, 0, 13) to := m.scheduleWindow.AddDate(0, 0, 6)
return m, fetchScheduleCmd(m.client, from, to) return m, fetchScheduleCmd(m.client, from, to)
} }
return m, nil return m, nil
@@ -346,7 +346,7 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
m.scheduleWindow = m.scheduleWindow.AddDate(0, 0, 7) m.scheduleWindow = m.scheduleWindow.AddDate(0, 0, 7)
m.scheduleLoading = true m.scheduleLoading = true
from := m.scheduleWindow from := m.scheduleWindow
to := m.scheduleWindow.AddDate(0, 0, 13) to := m.scheduleWindow.AddDate(0, 0, 6)
return m, fetchScheduleCmd(m.client, from, to) return m, fetchScheduleCmd(m.client, from, to)
} }
return m, nil return m, nil
@@ -558,7 +558,7 @@ func (m Model) handleConfirmKey(msg tea.KeyMsg) (Model, tea.Cmd) {
m.pendingDeleteEntry = nil m.pendingDeleteEntry = nil
m.scheduleLoading = true m.scheduleLoading = true
from := m.scheduleWindow from := m.scheduleWindow
to := m.scheduleWindow.AddDate(0, 0, 13) to := m.scheduleWindow.AddDate(0, 0, 6)
return m, deleteScheduleEntryCmd(m.client, entry.ID, from, to) return m, deleteScheduleEntryCmd(m.client, entry.ID, from, to)
case confirmDeleteUser: case confirmDeleteUser:
userID := m.selectedUser.ID userID := m.selectedUser.ID
@@ -625,7 +625,7 @@ func (m Model) handleUserPickerKey(msg tea.KeyMsg) (Model, tea.Cmd) {
dates = []string{d.Format("2006-01-02")} dates = []string{d.Format("2006-01-02")}
} }
from := m.scheduleWindow from := m.scheduleWindow
to := m.scheduleWindow.AddDate(0, 0, 13) to := m.scheduleWindow.AddDate(0, 0, 6)
m.mode = modeDashboard m.mode = modeDashboard
m.scheduleLoading = true m.scheduleLoading = true
return m, assignScheduleCmd(m.client, user.ID, dates, from, to) return m, assignScheduleCmd(m.client, user.ID, dates, from, to)
+1 -1
View File
@@ -222,7 +222,7 @@ func (m Model) renderSchedule() string {
// Window label // Window label
from := m.scheduleWindow from := m.scheduleWindow
to := m.scheduleWindow.AddDate(0, 0, 13) to := m.scheduleWindow.AddDate(0, 0, 6)
windowLabel := styleMuted.Render(fmt.Sprintf(" %s — %s", windowLabel := styleMuted.Render(fmt.Sprintf(" %s — %s",
from.Format("Jan 02"), to.Format("Jan 02, 2006"))) from.Format("Jan 02"), to.Format("Jan 02, 2006")))