Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions internal/handler/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ type bookPageData struct {
HostName string
HostInitial string
AvatarURL string
Hosts []hostDisplay // faces for the info panel (1 = single, >1 = group stack)
Hosts []hostDisplay // faces for the info panel (1 = single, >1 = group stack); capped at maxHostFaces
HostsMore int // >0 when the stack was capped: hosts not drawn, shown as a "+N" chip
HostsLabel string // "Alex, Sam & 2 others" for the group case
// SoleHostName is the host's name when this event type has exactly one, and "" when
// it has several. It is what lets an empty day read "Alex has no available times on
Expand Down Expand Up @@ -160,6 +161,29 @@ func (h *Handler) displayHosts(ctx context.Context, etID, mode string) []hostDis
return out
}

// maxHostFaces caps the host face stack in the info panel. The panel is 240px
// wide with 1.5rem padding (192px of content); each face is 56px and the stack
// overlaps by 16px, so four circles already fill 176px. Drawing every face of a
// six-host team overflowed the panel and spilled into the calendar (#166). Three
// faces plus a "+N" chip matches the label, which names at most three hosts.
const maxHostFaces = 3

// capHostFaces returns at most limit faces for drawing.
func capHostFaces(hosts []hostDisplay, limit int) []hostDisplay {
if limit <= 0 || len(hosts) <= limit {
return hosts
}
return hosts[:limit]
}

// hostsOverflow counts the hosts capHostFaces left out, for the "+N" chip.
func hostsOverflow(hosts []hostDisplay, limit int) int {
if limit <= 0 || len(hosts) <= limit {
return 0
}
return len(hosts) - limit
}

// hostsLabel renders a group host list as "Alex, Sam & 2 others" (first names), or
// "Alex, Sam y 2 más" in Spanish. The separator and conjunction are locale keys, not
// hardcoded punctuation — translating only the trailing noun (as this used to) produces
Expand Down Expand Up @@ -522,7 +546,8 @@ func (h *Handler) BookPage(w http.ResponseWriter, r *http.Request) {
HostName: hosts[0].Name,
HostInitial: hosts[0].Initial,
AvatarURL: hosts[0].AvatarURL,
Hosts: hosts,
Hosts: capHostFaces(hosts, maxHostFaces),
HostsMore: hostsOverflow(hosts, maxHostFaces),
HostsLabel: hostsLabel(hosts, loc),
SoleHostName: soleHostName(hosts),
MinNoticeLabel: noticeLabel(minNotice, loc),
Expand Down
12 changes: 10 additions & 2 deletions internal/handler/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
var BASE = SELF ? new URL(SELF.src).origin : window.location.origin;

var TZ = (Intl.DateTimeFormat().resolvedOptions().timeZone) || 'UTC';
// Max host faces drawn in the info panel; mirrors maxHostFaces in book.go.
var MAX_HOST_FACES = 3;
var STEP_BP = 560; // below this width → step-flow (one view at a time)

// i18n — the server resolves locale from the browser's own Accept-Language header
Expand Down Expand Up @@ -289,13 +291,19 @@
hosts = sel.host_ids.map(function (id) { return hm[id]; }).filter(Boolean);
}
if (!hosts || !hosts.length) hosts = (this.info.hosts && this.info.hosts.length) ? this.info.hosts : [];
var faceKids = hosts.map(function (host, i) {
var z = (hosts.length - i) * 10;
// Cap the face stack so it cannot overflow the info panel into the calendar (#166).
// Keep in step with maxHostFaces in book.go and book.html's copy.
var shown = hosts.slice(0, MAX_HOST_FACES);
var faceKids = shown.map(function (host, i) {
var z = (shown.length - i) * 10;
var inner = host.avatar_url
? el('img', { class: 'avatar-img', src: host.avatar_url, alt: host.name || '' })
: el('span', { class: 'avatar-initials', text: ((host.name || '?')[0] || '?').toUpperCase() });
return el('span', { class: 'face', style: 'z-index:' + z }, [inner]);
});
if (hosts.length > shown.length) {
faceKids.push(el('span', { class: 'face face-more', style: 'z-index:100', text: '+' + (hosts.length - shown.length) }));
}
// info-head = avatar + title (host name + event name). On compact widths the
// avatar centers against this title only; meta + description sit below, indented
// to line up under the title. On desktop these wrappers are plain blocks, so the
Expand Down
68 changes: 68 additions & 0 deletions internal/handler/host_faces_book_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package handler_test

import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
)

// The info panel is 240px wide with 1.5rem padding (192px of content). Each face
// is 56px and the stack overlaps by 16px, so six hosts is 256px — it spilled into
// the calendar column (#166). The page must draw at most three faces plus a "+N"
// chip, matching the label which already names only three hosts.
func TestBookPageCapsHostFacesAtThree(t *testing.T) {
h, database, key, ownerID := setupWorkspaceWithDB(t)
slug, _ := seedEventTypeHTTP(t, h, key)

parts := []string{
fmt.Sprintf(`{"user_id":%q,"role":"required","priority":0}`, ownerID),
}
for i := 2; i <= 6; i++ {
hostID := fmt.Sprintf("u%d", i)
if _, err := database.Exec(
`INSERT INTO users (id,email,name,iana_timezone,is_admin) VALUES (?,?,?, 'UTC',0)`,
hostID, hostID+"@example.com", "Host "+hostID); err != nil {
t.Fatalf("seed %s: %v", hostID, err)
}
parts = append(parts, fmt.Sprintf(`{"user_id":%q,"role":"required","priority":%d}`, hostID, i-1))
}
if rec := putHosts(t, h, slug, key, `{"hosts":[`+strings.Join(parts, ",")+`]}`); rec.Code != http.StatusOK {
t.Fatalf("set hosts: %d — %s", rec.Code, rec.Body.String())
}

req := httptest.NewRequest(http.MethodGet, "/book/"+slug, nil)
req.SetPathValue("slug", slug)
rec := httptest.NewRecorder()
h.BookPage(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("book page: %d", rec.Code)
}

block := hostFacesBlock(t, rec.Body.String())
if got := strings.Count(block, `class="face"`); got != 3 {
t.Errorf("rendered %d avatar faces; want 3", got)
}
if !strings.Contains(block, `class="face face-more"`) {
t.Error("missing the \"+N\" overflow chip for 6 hosts")
}
if !strings.Contains(block, ">+3</span>") {
t.Error("overflow chip should read +3 for 6 hosts")
}
}

// hostFacesBlock returns the rendered #host-faces element only — the page's inline
// script contains the same class names in template literals.
func hostFacesBlock(t *testing.T, page string) string {
t.Helper()
start := strings.Index(page, `id="host-faces"`)
if start < 0 {
t.Fatal("no #host-faces element in rendered page")
}
end := strings.Index(page[start:], "</div>")
if end < 0 {
t.Fatal("unterminated #host-faces element")
}
return page[start : start+end]
}
41 changes: 41 additions & 0 deletions internal/handler/host_faces_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package handler

import (
"testing"
)

// mkHosts builds n placeholder faces.
func mkHosts(n int) []hostDisplay {
out := make([]hostDisplay, n)
for i := range out {
name := string(rune('A' + i))
out[i] = hostDisplay{Name: name, Initial: name, Z: (n - i) * 10}
}
return out
}

func TestCapHostFaces(t *testing.T) {
cases := []struct {
name string
n int
wantFaces int
wantOverflow int
}{
{"none", 0, 0, 0},
{"single", 1, 1, 0},
{"at the limit", maxHostFaces, maxHostFaces, 0},
{"one over", maxHostFaces + 1, maxHostFaces, 1},
{"six hosts (issue #166)", 6, maxHostFaces, 3},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
hosts := mkHosts(tc.n)
if got := capHostFaces(hosts, maxHostFaces); len(got) != tc.wantFaces {
t.Errorf("capHostFaces len = %d; want %d", len(got), tc.wantFaces)
}
if got := hostsOverflow(hosts, maxHostFaces); got != tc.wantOverflow {
t.Errorf("hostsOverflow = %d; want %d", got, tc.wantOverflow)
}
})
}
}
11 changes: 9 additions & 2 deletions internal/handler/templates/book.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
{{end}}
</span>
{{end}}
{{if .HostsMore}}<span class="face face-more" style="z-index:100">+{{.HostsMore}}</span>{{end}}
</div>
<p id="host-name" class="host-name">{{.HostsLabel}}</p>
<h1 class="event-name">{{.Name}}</h1>
Expand Down Expand Up @@ -300,6 +301,7 @@ <h3>{{call .T "booking_confirmed"}}</h3>
// The default face(s) are server-rendered; on slot-pick we swap to the host(s)
// that slot's host_ids resolve to (round-robin: the priority pick; group: all).
let hostMeta = {};
const MAX_FACES = 3; // keep in step with maxHostFaces in book.go
const facesEl = $('host-faces'), nameEl = $('host-name');
const defaultFacesHTML = facesEl ? facesEl.innerHTML : '';
const defaultName = nameEl ? nameEl.textContent : '';
Expand Down Expand Up @@ -332,8 +334,13 @@ <h3>{{call .T "booking_confirmed"}}</h3>
if (!facesEl) return;
const metas = (ids || []).map(id => hostMeta[id]).filter(Boolean);
if (!metas.length) return; // unknown — keep whatever's shown
const n = metas.length;
facesEl.innerHTML = metas.map((m, i) => faceHTML(m, (n - i) * 10)).join('');
// Cap the stack so it cannot overflow the info panel into the calendar (#166).
// Keep in step with maxHostFaces in book.go and the embed widget's copy.
const shown = metas.slice(0, MAX_FACES);
const more = metas.length - shown.length;
facesEl.innerHTML =
shown.map((m, i) => faceHTML(m, (shown.length - i) * 10)).join('') +
(more > 0 ? `<span class="face face-more" style="z-index:100">+${more}</span>` : '');
nameEl.textContent = hostsLabel(metas);
}
function restoreDefaultHosts() {
Expand Down
13 changes: 13 additions & 0 deletions internal/handler/templates/booking.css
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,19 @@
border: 2.5px solid #fff;
box-shadow: 0 0 0 1px rgba(0,0,0,.06);
}
/* "+N" chip when the stack is capped (see maxHostFaces). Painted above the last
face and inset the same 16px, so its text is never clipped by the overlap. */
.host-faces .face-more {
width: 56px; height: 56px;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.face-more is fixed at 56px, but the embed widget's compact container query (@container (max-width:719px), embed.js:142) shrinks .info .avatar-img/.avatar-initials to 46px and has no .face-more override. At that breakpoint the chip renders 10px larger than the faces beside it and extends below their baseline, so the stack looks off on mobile embeds.

Technical details
# Compact embed: overflow chip does not inherit the shrunk face size

## Affected sites
- internal/handler/templates/booking.css:322-332 — `.face-more` hardcodes 56px.
- internal/handler/embed.js:142 — compact rule shrinks `.avatar-img`/`.avatar-initials` to 46px, but never `.face-more`.

## Required outcome
- At `@container (max-width:719px)`, the `+N` chip matches the 46x46 face size (and shrinks its font if needed) so the stack stays visually uniform.

## Suggested approach (optional)
- Append `.info .face-more{width:46px;height:46px;}` to the same compact rule at `embed.js:142` (the page templates keep 56px, so this belongs in the widget's layer, not the shared rule).

border-radius: 50%;
background: #f3f4f6;
color: #374151;
border: 2.5px solid #fff;
box-shadow: 0 0 0 1px rgba(0,0,0,.06);
display: flex; align-items: center; justify-content: center;
font-size: .8125rem; font-weight: 600; line-height: 1;
box-sizing: border-box;
}

/* ── Conversational booking assistant — floating launcher + drawer (book.html; shared with the widget) ── */
.asst-fab-btn {
Expand Down
Loading