Skip to content

Suggest four times from the host's own free space - #39

Merged
JamesmarkeyUK merged 1 commit into
mainfrom
claude/auto-select-calendar-slots-trf88k
Aug 14, 2026
Merged

Suggest four times from the host's own free space#39
JamesmarkeyUK merged 1 commit into
mainfrom
claude/auto-select-calendar-slots-trf88k

Conversation

@JamesmarkeyUK

Copy link
Copy Markdown
Contributor

With a calendar connected, the create screen can now fill the poll in itself. Beside the week view, "Suggest 4 times" reads the host's free/busy and proposes four candidate slots — weekdays only, between 10:00 and 16:00 in the poll's timezone, and at most one morning and one afternoon on any given day, so four options can't all be one Tuesday. They're ordinary slots once added: drag to move, click to remove, click the button again for four more.

How it picks

suggestFreeSlots in src/lib/autoSlots.ts is a pure function fed the same per-day busy segments the week grid shades from, so a suggestion lands exactly where the shading says the host is free.

  • Spread beats density — one option per day first, alternating which half of the day it tries so the set isn't four identical 10am slots; it doubles up on a day only once the weekdays run out.
  • Afternoons prefer 13:00 onwards, dropping into the 12:00–13:00 hour only when nothing later fits.
  • Starts snap to the same 30-minute grid a drawn slot uses; the first day is cut off an hour ahead of now; slots the poll already has count as busy, so a second click adds four more options rather than four duplicates. Slot length copies whatever the host is already proposing (an hour by default).

Wiring

CreatePoll.suggestTimes fetches the whole 21-day scan range itself rather than trusting whichever weeks the grid happens to have loaded, and aborts if any connected provider's read fails — half a diary would propose times the host isn't actually free for. The grid then jumps to the week the first suggestion landed in (new focus prop on CalendarWeekView), since slots off-screen look like nothing happened.

hostCalendar's private zonedParts moves into time.ts as zonedDayAndMinute, so "now" and the busy segments are read in one frame; calendarWeekday joins it for the Mon–Fri test.

Testing

  • npm test — 77 passed, 13 of them new: the 10–4 window, the weekend skip, the one-morning-one-afternoon rule, the lunch-hour fallback, existing-slot avoidance, partial results when the diary is full, and a timezone-frame test that fails if the busy data is read in UTC instead of the poll's zone.
  • npm run typecheck and npm run build both clean.
  • Not exercised against a live provider — that needs Supabase credentials and a connected Google/Microsoft account.

🤖 Generated with Claude Code

https://claude.ai/code/session_01W4A85YwKbANRATBa496oug


Generated by Claude Code

With a calendar connected, the create screen can now fill the poll in
itself: "Suggest 4 times" reads the host's free/busy and proposes four
candidate slots — weekdays only, between 10:00 and 16:00 in the poll's
timezone, and at most one morning and one afternoon on any given day, so
four options can't all be one Tuesday.

The picking is a pure function (`suggestFreeSlots`, unit-tested) fed the
same per-day busy segments the week grid shades from, so a suggestion
lands exactly where the shading says the host is free. Spread beats
density: one option per day first, alternating which half of the day it
tries so the set isn't four identical 10am slots, doubling up only once
the days run out. Afternoons prefer 13:00 onwards and drop into the lunch
hour only when nothing later fits; starts snap to the same 30-minute grid
a drawn slot does; slots the poll already has count as busy, so clicking
again adds four more rather than four duplicates.

The click reads the whole 21-day range itself rather than trusting
whichever weeks the grid has loaded, and aborts if a connected provider's
read fails — half a diary would propose times the host isn't free for.
The grid then jumps to the week the first suggestion landed in, since
slots off-screen look like nothing happened.

`zonedDayAndMinute` moves into time.ts (it was hostCalendar's private
`zonedParts`) so "now" and the busy segments are read in one frame, and
`calendarWeekday` joins it for the Mon–Fri test.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W4A85YwKbANRATBa496oug
@JamesmarkeyUK
JamesmarkeyUK merged commit 070ae61 into main Aug 14, 2026
1 check passed
@JamesmarkeyUK
JamesmarkeyUK deleted the claude/auto-select-calendar-slots-trf88k branch August 14, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants