Switch to 5-day rolling view with clock/weather info panel

- Show today + next 4 days instead of a fixed Sun-Sat week grid
- Replace Next Week column with a right-side info panel (live clock,
  date, current weather + 3-day forecast)
- Simplify topbar to just the view pill, date range, and member filter
- Adjust grid to repeat(5, 1fr) 190px

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-27 20:53:36 +12:00
parent fc6abfe745
commit 20c9bb55b1
4 changed files with 199 additions and 237 deletions

52
app.py
View File

@@ -112,30 +112,25 @@ def parse_member_and_title(summary, family_members):
return None, title
def week_start_for(d):
"""Return the Sunday on/before date d (Sunday-starting week)."""
return d - timedelta(days=(d.weekday() + 1) % 7)
NUM_DAYS = 5
def empty_week_payload(week_start_date, members):
def empty_days_payload(start_date, members):
days = []
for i in range(7):
d = week_start_date + timedelta(days=i)
for i in range(NUM_DAYS):
d = start_date + timedelta(days=i)
days.append({'date': d.isoformat(), 'weekday': d.strftime('%A'), 'events': []})
next_week_start = week_start_date + timedelta(days=7)
next_week_end = next_week_start + timedelta(days=6)
return {
'week_start': week_start_date.isoformat(),
'week_end': (week_start_date + timedelta(days=6)).isoformat(),
'start': start_date.isoformat(),
'end': (start_date + timedelta(days=NUM_DAYS - 1)).isoformat(),
'days': days,
'next_week': {'start': next_week_start.isoformat(), 'end': next_week_end.isoformat(), 'count': 0, 'events': []},
'members': members,
}
@app.route('/api/calendar')
def get_calendar():
"""Fetch Google Calendar events from iCal feed for a Sunday-starting week."""
"""Fetch Google Calendar events — today plus the next 4 days."""
global calendar_cache
nz_tz = pytz.timezone('Pacific/Auckland')
@@ -144,17 +139,17 @@ def get_calendar():
start_param = request.args.get('start')
if start_param:
try:
week_start_date = week_start_for(datetime.strptime(start_param, '%Y-%m-%d').date())
start_date = datetime.strptime(start_param, '%Y-%m-%d').date()
except ValueError:
week_start_date = week_start_for(now.date())
start_date = now.date()
else:
week_start_date = week_start_for(now.date())
start_date = now.date()
family_members = app.config['FAMILY_MEMBERS']
default_member = app.config['DEFAULT_MEMBER']
members_for_filter = family_members + [default_member]
cache_key = week_start_date.isoformat()
cache_key = start_date.isoformat()
if (calendar_cache.get('key') == cache_key and calendar_cache['data'] and calendar_cache['timestamp'] and
(now - calendar_cache['timestamp']).total_seconds() < app.config['CALENDAR_UPDATE_INTERVAL']):
return jsonify(calendar_cache['data'])
@@ -162,16 +157,15 @@ def get_calendar():
try:
ical_url = app.config.get('GOOGLE_CALENDAR_ICAL_URL')
if not ical_url:
return jsonify(empty_week_payload(week_start_date, members_for_filter))
return jsonify(empty_days_payload(start_date, members_for_filter))
response = requests.get(ical_url, timeout=10)
response.raise_for_status()
cal = Calendar.from_ical(response.content)
# Fetch this week + next week, so the "Next Week" preview column has data.
range_start = nz_tz.localize(datetime.combine(week_start_date, datetime.min.time()))
range_end = range_start + timedelta(days=14)
range_start = nz_tz.localize(datetime.combine(start_date, datetime.min.time()))
range_end = range_start + timedelta(days=NUM_DAYS)
recurring_events = recurring_ical_events.of(cal).between(range_start, range_end)
events = []
@@ -219,25 +213,15 @@ def get_calendar():
events.sort(key=lambda x: x['start'])
days = []
for i in range(7):
d = week_start_date + timedelta(days=i)
for i in range(NUM_DAYS):
d = start_date + timedelta(days=i)
day_events = [e for e in events if datetime.fromisoformat(e['start']).date() == d]
days.append({'date': d.isoformat(), 'weekday': d.strftime('%A'), 'events': day_events})
next_week_start = week_start_date + timedelta(days=7)
next_week_end = next_week_start + timedelta(days=6)
next_week_events = [e for e in events if datetime.fromisoformat(e['start']).date() >= next_week_start]
result = {
'week_start': week_start_date.isoformat(),
'week_end': (week_start_date + timedelta(days=6)).isoformat(),
'start': start_date.isoformat(),
'end': (start_date + timedelta(days=NUM_DAYS - 1)).isoformat(),
'days': days,
'next_week': {
'start': next_week_start.isoformat(),
'end': next_week_end.isoformat(),
'count': len(next_week_events),
'events': next_week_events[:5],
},
'members': members_for_filter,
}