From 39afc40ceb6ab98bcc37effeb07ad7b5dbca632a Mon Sep 17 00:00:00 2001 From: Barry Prendergast Date: Sat, 21 Nov 2026 14:17:50 +0000 Subject: [PATCH 1/4] fix: signing out takes you to the homepage (#172) Signing out of Settings sent you to the sign-in page, because Settings saw nobody signed in and asked you to sign in again. Now signOut takes a leave callback, which runs once the session has ended and before anyone is shown as signed out; meanwhile the status is loading. Settings goes home there. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PSPB1cH898qV61BH1NiFKL --- web/e2e/settings.spec.ts | 16 ++++++ .../AccountCard/AccountCard.test.tsx | 41 +++++++++----- .../components/AccountCard/AccountCard.tsx | 8 ++- .../auth/session/SessionProvider.test.tsx | 54 +++++++++++++++++-- .../features/auth/session/SessionProvider.tsx | 27 +++++++--- .../auth/session/SessionProvider.types.ts | 8 ++- web/src/i18n/locales/en-GB/messages.po | 8 +-- 7 files changed, 133 insertions(+), 29 deletions(-) diff --git a/web/e2e/settings.spec.ts b/web/e2e/settings.spec.ts index dc02a01..cf5be20 100644 --- a/web/e2e/settings.spec.ts +++ b/web/e2e/settings.spec.ts @@ -1,4 +1,5 @@ import { expect, test } from './fixtures'; +import { ADA, mockPerson, signIn } from './mocks'; test('sends signed-out visitors to sign in first', async ({ page }) => { await page.goto('/settings'); @@ -8,3 +9,18 @@ test('sends signed-out visitors to sign in first', async ({ page }) => { ).toBeVisible(); await expect(page.getByRole('button', { name: 'Sign in' })).toBeVisible(); }); + +test('signing out goes to the homepage (#172)', async ({ page }) => { + await mockPerson(page); + await signIn(page, { did: ADA.did, scope: 'atproto transition:generic' }); + await page.goto('/settings'); + await page.getByRole('button', { name: 'Sign out' }).click(); + await expect(page.getByText('Signed out')).toBeVisible(); + await expect(page).toHaveURL('/'); + await expect( + page.getByRole('heading', { level: 1, name: 'Welcome to Lanyards' }) + ).toBeVisible(); + await expect( + page.getByRole('banner').getByRole('link', { name: 'Sign in' }) + ).toBeVisible(); +}); diff --git a/web/src/features/account/components/AccountCard/AccountCard.test.tsx b/web/src/features/account/components/AccountCard/AccountCard.test.tsx index e97a1ed..6adb4b0 100644 --- a/web/src/features/account/components/AccountCard/AccountCard.test.tsx +++ b/web/src/features/account/components/AccountCard/AccountCard.test.tsx @@ -6,7 +6,7 @@ import { useSession } from '@/features/auth/session/useSession'; import { useProfile } from '@/lib/atproto/useProfile'; import { expectNoAxeViolations } from '@/test/axe'; import { ALICE } from '@/test/fixtures'; -import { renderWithProviders } from '@/test/render'; +import { renderInRouter, waitForRoute } from '@/test/router'; import { AccountCard } from './AccountCard'; @@ -31,31 +31,47 @@ const signedInAs = (profile: object | undefined, status = 'success') => { }; describe('AccountCard', () => { - it('shows who is signed in', () => { + it('shows who is signed in', async () => { signedInAs(ALICE); - renderWithProviders(); - expect(screen.getByText('Alice')).toBeInTheDocument(); + renderInRouter(, '/settings'); + expect(await screen.findByText('Alice')).toBeInTheDocument(); expect(screen.getByText('@alice.bsky.social')).toBeInTheDocument(); }); - it('falls back to the handle when there is no display name', () => { + it('falls back to the handle when there is no display name', async () => { signedInAs({ did: ALICE.did, handle: ALICE.handle }); - renderWithProviders(); - expect(screen.getByText('alice.bsky.social')).toBeInTheDocument(); + renderInRouter(, '/settings'); + expect(await screen.findByText('alice.bsky.social')).toBeInTheDocument(); + }); + + it('signs out to the homepage (#172)', async () => { + signedInAs(ALICE); + // The session ends, then calls back to say where to go. + signOut.mockImplementation(async (leave?: () => Promise) => { + await leave?.(); + }); + const { router } = renderInRouter(, '/settings'); + await userEvent.click( + await screen.findByRole('button', { name: 'Sign out' }) + ); + expect(signOut).toHaveBeenCalledWith(expect.any(Function)); + await waitForRoute(router, '/'); }); it('signs out', async () => { signedInAs(ALICE); - renderWithProviders(); - await userEvent.click(screen.getByRole('button', { name: 'Sign out' })); + renderInRouter(, '/settings'); + await userEvent.click( + await screen.findByRole('button', { name: 'Sign out' }) + ); expect(signOut).toHaveBeenCalled(); }); it('still offers sign-out when the profile cannot load', async () => { signedInAs(undefined, 'error'); - renderWithProviders(); + renderInRouter(, '/settings'); expect( - screen.getByText("We couldn't load your profile.") + await screen.findByText("We couldn't load your profile.") ).toBeInTheDocument(); await userEvent.click(screen.getByRole('button', { name: 'Sign out' })); expect(signOut).toHaveBeenCalled(); @@ -63,7 +79,8 @@ describe('AccountCard', () => { it('has no axe violations', async () => { signedInAs(ALICE); - const { container } = renderWithProviders(); + const { container } = renderInRouter(, '/settings'); + await screen.findByText('Alice'); await expectNoAxeViolations(container); }); }); diff --git a/web/src/features/account/components/AccountCard/AccountCard.tsx b/web/src/features/account/components/AccountCard/AccountCard.tsx index 4b778ce..6242e3e 100644 --- a/web/src/features/account/components/AccountCard/AccountCard.tsx +++ b/web/src/features/account/components/AccountCard/AccountCard.tsx @@ -1,4 +1,5 @@ import { useLingui } from '@lingui/react/macro'; +import { useRouter } from '@tanstack/react-router'; import { Button } from '@/components/Button/Button'; import { useSession } from '@/features/auth/session/useSession'; @@ -11,6 +12,7 @@ import type { AccountCardProps } from './AccountCard.types'; export function AccountCard({ className }: AccountCardProps) { const { t } = useLingui(); const session = useSession(); + const router = useRouter(); const did = session.status === 'signedIn' ? session.session.did : undefined; const profile = useProfile(did); @@ -39,7 +41,11 @@ export function AccountCard({ className }: AccountCardProps) { : t`Loading your profile…`}

)} - diff --git a/web/src/features/auth/session/SessionProvider.test.tsx b/web/src/features/auth/session/SessionProvider.test.tsx index d25d534..01fd316 100644 --- a/web/src/features/auth/session/SessionProvider.test.tsx +++ b/web/src/features/auth/session/SessionProvider.test.tsx @@ -26,7 +26,7 @@ vi.mock('@/components/Toaster/notify', () => ({ const session = { did: 'did:plc:ewvi7nxzyoun6zhxrhs64oiz' } as never; -function Probe() { +function Probe({ leave }: { leave?: () => Promise }) { const session = useSession(); return ( <> @@ -34,6 +34,9 @@ function Probe() { + @@ -41,10 +44,10 @@ function Probe() { ); } -const renderProvider = () => +const renderProvider = (leave?: () => Promise) => renderWithProviders( - + ); @@ -105,6 +108,51 @@ describe('SessionProvider', () => { expect(track).toHaveBeenCalledWith('signed_out'); }); + it('moves on before anyone is shown as signed out (#172)', async () => { + vi.mocked(restoreSession).mockResolvedValue({ + status: 'restored', + session, + }); + vi.mocked(signOut).mockResolvedValue(undefined); + const seen: string[] = []; + // Where to go next, once the session has ended. Meanwhile nobody is + // signed in or out, so a page that needs a session doesn't send + // people off to sign in again. + const leave = vi.fn(async () => { + await screen.findByText('status: loading'); + seen.push( + vi.mocked(signOut).mock.calls.length ? 'ended' : 'still signed in' + ); + }); + renderProvider(leave); + await screen.findByText('status: signedIn'); + await userEvent.click( + screen.getByRole('button', { name: 'Sign out and leave' }) + ); + expect(await screen.findByText('status: signedOut')).toBeInTheDocument(); + expect(leave).toHaveBeenCalledTimes(1); + expect(seen).toEqual(['ended']); + expect(notify.success).toHaveBeenCalledWith('Signed out'); + }); + + it('signs out even if moving on fails', async () => { + vi.mocked(restoreSession).mockResolvedValue({ + status: 'restored', + session, + }); + vi.mocked(signOut).mockResolvedValue(undefined); + const failure = new Error('navigation failed'); + renderProvider(() => Promise.reject(failure)); + await screen.findByText('status: signedIn'); + await userEvent.click( + screen.getByRole('button', { name: 'Sign out and leave' }) + ); + expect(await screen.findByText('status: signedOut')).toBeInTheDocument(); + expect(captureError).toHaveBeenCalledWith(failure, { + source: 'sign-out-leave', + }); + }); + it('refresh() picks up a session stored after sign-in', async () => { vi.mocked(restoreSession).mockResolvedValueOnce({ status: 'none' }); renderProvider(); diff --git a/web/src/features/auth/session/SessionProvider.tsx b/web/src/features/auth/session/SessionProvider.tsx index 136b6e1..de81130 100644 --- a/web/src/features/auth/session/SessionProvider.tsx +++ b/web/src/features/auth/session/SessionProvider.tsx @@ -71,14 +71,25 @@ export function SessionProvider({ children }: SessionProviderProps) { if (started === generation.current) apply(result); }, [apply]); - const signOut = useCallback(async () => { - if (state.status !== 'signedIn') return; - generation.current++; - await endSession(state.session); - setState({ status: 'signedOut' }); - track('signed_out'); - notify.success(t`Signed out`); - }, [state, t]); + const signOut = useCallback( + async (leave?: () => Promise) => { + if (state.status !== 'signedIn') return; + generation.current++; + // Neither signed in nor out until `leave` has moved on. + setState({ status: 'loading' }); + await endSession(state.session); + try { + await leave?.(); + } catch (error) { + // Wherever they are, they're signed out all the same. + captureError(error, { source: 'sign-out-leave' }); + } + setState({ status: 'signedOut' }); + track('signed_out'); + notify.success(t`Signed out`); + }, + [state, t] + ); const value = useMemo( () => ({ ...state, signOut, refresh }), diff --git a/web/src/features/auth/session/SessionProvider.types.ts b/web/src/features/auth/session/SessionProvider.types.ts index 5b14ad4..122323b 100644 --- a/web/src/features/auth/session/SessionProvider.types.ts +++ b/web/src/features/auth/session/SessionProvider.types.ts @@ -8,7 +8,13 @@ export type SessionState = | { status: 'signedIn'; session: SessionHandle }; export type SessionContextValue = SessionState & { - signOut(): Promise; + /** + * Ends the session. `leave`, if given, runs once it has ended and before + * anyone is shown as signed out: say where to go next there (#172), so + * a page that needs a session never sends people off to sign in again. + * Meanwhile the status is `loading`. + */ + signOut(leave?: () => Promise): Promise; /** Re-reads the stored session, e.g. right after the OAuth callback. */ refresh(): Promise; }; diff --git a/web/src/i18n/locales/en-GB/messages.po b/web/src/i18n/locales/en-GB/messages.po index c0c8fd2..096f998 100644 --- a/web/src/i18n/locales/en-GB/messages.po +++ b/web/src/i18n/locales/en-GB/messages.po @@ -724,7 +724,7 @@ msgstr "Links" msgid "Loading lanyard…" msgstr "Loading lanyard…" -#: src/features/account/components/AccountCard/AccountCard.tsx:39 +#: src/features/account/components/AccountCard/AccountCard.tsx:41 msgid "Loading your profile…" msgstr "Loading your profile…" @@ -1105,7 +1105,7 @@ msgstr "Sign in to see this lanyard" msgid "Sign in with your Bluesky handle, or any AT Protocol account, and Lanyards gathers your publications, talks, affiliations and profiles into one lanyard to share anywhere: on a conference badge, in an email signature, on a slide." msgstr "Sign in with your Bluesky handle, or any AT Protocol account, and Lanyards gathers your publications, talks, affiliations and profiles into one lanyard to share anywhere: on a conference badge, in an email signature, on a slide." -#: src/features/account/components/AccountCard/AccountCard.tsx:43 +#: src/features/account/components/AccountCard/AccountCard.tsx:49 msgid "Sign out" msgstr "Sign out" @@ -1125,7 +1125,7 @@ msgstr "Signal username copied" msgid "Signed in, you can send us feedback, with screenshots, right from Lanyards. Or reach us here:" msgstr "Signed in, you can send us feedback, with screenshots, right from Lanyards. Or reach us here:" -#: src/features/auth/session/SessionProvider.tsx:80 +#: src/features/auth/session/SessionProvider.tsx:89 msgid "Signed out" msgstr "Signed out" @@ -1381,7 +1381,7 @@ msgstr "We couldn't finish signing you in." msgid "We couldn't load this lanyard" msgstr "We couldn't load this lanyard" -#: src/features/account/components/AccountCard/AccountCard.tsx:38 +#: src/features/account/components/AccountCard/AccountCard.tsx:40 msgid "We couldn't load your profile." msgstr "We couldn't load your profile." From b15dc9139c63ec4be41ec8ed17d8439d936bb0b7 Mon Sep 17 00:00:00 2001 From: Barry Prendergast Date: Sat, 21 Nov 2026 14:45:55 +0000 Subject: [PATCH 2/4] feat: a person's badge hangs from their lanyard, in the laminate sleeve (#173) The badge at the top of a lanyard, on the public page and in the customiser, now hangs as on the Share screen: a lanyard printed with the handle, the clasp through the sleeve's slot, and the laminate sleeve. It never sways, since it holds buttons. On the app's light or dark page the lanyard wears the person's accent, edged with a hairline, and the sleeve is edged in the page's own ink. Both shared pieces gain those options: LanyardRibbon tone="accent" and BadgeSleeve ground="page". The loading skeleton hangs the same way, so nothing jumps. The straps run up to the header, and the customiser's title is for screen readers only. Keeping the 2.5 s loading budget: the page sleeve has no inset highlight, which cost 0.1 s of paint, and the cover, lanyard and sleeve load as one file, not three. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PSPB1cH898qV61BH1NiFKL --- web/src/app/customise.test.tsx | 11 ++- .../components/BadgeHero/BadgeHero.styles.ts | 6 +- .../components/BadgeHero/BadgeHero.test.tsx | 24 ++++- .../components/BadgeHero/BadgeHero.tsx | 91 ++++++++++--------- .../BadgeLanyard/BadgeLanyard.styles.ts | 15 +++ .../BadgeLanyard/BadgeLanyard.test.tsx | 33 +++++++ .../components/BadgeLanyard/BadgeLanyard.tsx | 34 +++++++ .../BadgeLanyard/BadgeLanyard.types.ts | 9 ++ .../LanyardPage/LanyardPage.styles.ts | 3 +- .../LanyardSkeleton/LanyardSkeleton.styles.ts | 4 +- .../LanyardSkeleton/LanyardSkeleton.tsx | 30 +++--- .../CustomisePage/CustomisePage.styles.ts | 9 +- .../customise/CustomisePage/CustomisePage.tsx | 61 +++++++------ .../BadgeSleeve/BadgeSleeve.styles.ts | 31 +++++-- .../BadgeSleeve/BadgeSleeve.test.tsx | 21 +++++ .../qr/components/BadgeSleeve/BadgeSleeve.tsx | 16 +++- .../BadgeSleeve/BadgeSleeve.types.ts | 2 + .../LanyardRibbon/LanyardRibbon.constants.ts | 3 + .../LanyardRibbon/LanyardRibbon.styles.ts | 41 ++++++--- .../LanyardRibbon/LanyardRibbon.test.tsx | 24 +++++ .../LanyardRibbon/LanyardRibbon.tsx | 62 +++++++++---- .../LanyardRibbon/LanyardRibbon.types.ts | 4 + web/src/i18n/locales/en-GB/messages.po | 14 +-- web/vite.config.ts | 14 ++- 24 files changed, 411 insertions(+), 151 deletions(-) create mode 100644 web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.styles.ts create mode 100644 web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.test.tsx create mode 100644 web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.tsx create mode 100644 web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.types.ts diff --git a/web/src/app/customise.test.tsx b/web/src/app/customise.test.tsx index 90699cf..8dec102 100644 --- a/web/src/app/customise.test.tsx +++ b/web/src/app/customise.test.tsx @@ -189,9 +189,14 @@ describe('//edit', { timeout: 20_000 }, () => { expect(grounds()).toHaveLength(1); const [ground] = grounds(); expect(ground).toContainElement(region); - expect(ground).toContainElement( - screen.getByRole('heading', { level: 1, name: 'Customise your lanyard' }) - ); + const heading = screen.getByRole('heading', { + level: 1, + name: 'Customise your lanyard', + }); + expect(ground).toContainElement(heading); + // For screen readers only: the lanyard hangs from the canvas's top + // edge, and the header already says Customise (#173). + expect(heading).toHaveClass('sr-only'); }); it('shows only its own header, with the customiser’s actions', async () => { diff --git a/web/src/features/lanyard/components/BadgeHero/BadgeHero.styles.ts b/web/src/features/lanyard/components/BadgeHero/BadgeHero.styles.ts index 3002035..1faf16a 100644 --- a/web/src/features/lanyard/components/BadgeHero/BadgeHero.styles.ts +++ b/web/src/features/lanyard/components/BadgeHero/BadgeHero.styles.ts @@ -4,14 +4,10 @@ // only generates classes it finds in the source. export const badge = - '@container flex w-full flex-col overflow-hidden rounded-sm shadow-badge outline outline-1 -outline-offset-1 outline-border'; + '@container flex w-full flex-col overflow-hidden rounded-sm outline outline-1 -outline-offset-1 outline-border'; export const cover = 'relative h-30 @min-[40rem]:h-60'; -/** Where a real lanyard's clip would go through the badge. */ -export const slot = - 'absolute left-1/2 top-[1.125rem] h-3.5 w-24 -translate-x-1/2 rounded-sm bg-background shadow-[inset_0_2px_3px_rgb(6_1_30/0.35)]'; - export const field = 'flex flex-wrap items-end gap-x-10 gap-y-6 bg-accent px-5 pb-6 text-on-accent @min-[40rem]:px-12 @min-[40rem]:pb-10'; diff --git a/web/src/features/lanyard/components/BadgeHero/BadgeHero.test.tsx b/web/src/features/lanyard/components/BadgeHero/BadgeHero.test.tsx index 8bbba90..ab26d3c 100644 --- a/web/src/features/lanyard/components/BadgeHero/BadgeHero.test.tsx +++ b/web/src/features/lanyard/components/BadgeHero/BadgeHero.test.tsx @@ -1,5 +1,5 @@ import userEvent from '@testing-library/user-event'; -import { screen } from '@testing-library/react'; +import { fireEvent, screen } from '@testing-library/react'; import { describe, expect, it } from 'vitest'; import { ADA } from '@/test/people'; @@ -51,6 +51,28 @@ describe('BadgeHero', () => { ).toBeInTheDocument(); }); + it('hangs in a laminate sleeve from a lanyard printed with the handle (#173)', () => { + const { container } = renderWithProviders(); + const badge = screen.getByRole('region', { name: 'Dr Ada Example' }); + expect(badge.closest('[data-sleeve]')).not.toBeNull(); + const straps = container.querySelectorAll('textPath'); + expect(straps).toHaveLength(2); + for (const strap of straps) { + expect(strap.textContent).toContain('@alice.test'); + } + }); + + it('never sways: it holds buttons, which must stay put (#173)', () => { + const { container } = renderWithProviders(); + const badge = screen.getByRole('region', { name: 'Dr Ada Example' }); + for (let x = 100; x <= 600; x += 50) { + fireEvent.pointerMove(badge, { pointerType: 'mouse', clientX: x }); + } + for (const element of container.querySelectorAll('*')) { + expect(element.style.transform).toBe(''); + } + }); + it('wears a decorative cover and shows initials without an avatar (#129)', () => { const { container } = renderWithProviders(); const cover = container.querySelector('[data-cover] svg'); diff --git a/web/src/features/lanyard/components/BadgeHero/BadgeHero.tsx b/web/src/features/lanyard/components/BadgeHero/BadgeHero.tsx index 88e997a..7e6ee45 100644 --- a/web/src/features/lanyard/components/BadgeHero/BadgeHero.tsx +++ b/web/src/features/lanyard/components/BadgeHero/BadgeHero.tsx @@ -2,13 +2,16 @@ import { CoverPattern } from '@/components/CoverPattern/CoverPattern'; import { heroName } from '@/lib/person/hero'; import { cn } from '@/lib/utils'; +import { BadgeLanyard } from '../BadgeLanyard/BadgeLanyard'; import { DepartureBoard } from '../DepartureBoard/DepartureBoard'; import * as styles from './BadgeHero.styles'; import type { BadgeHeroProps } from './BadgeHero.types'; /** * The badge at the top of a lanyard (spec §7): the cover, the accent field - * with the name in billboard type, and the departure board. + * with the name in billboard type, and the departure board. It hangs in a + * laminate sleeve from a lanyard printed with the handle, as on the Share + * screen (#173), but never sways: it holds buttons, which must stay put. */ export function BadgeHero({ hero, @@ -22,51 +25,51 @@ export function BadgeHero({ const meta = [hero.pronouns, `@${hero.handle}`].filter(Boolean).join(' · '); return ( -
-
- -
-
-
-
- {hero.avatar ? ( - - ) : ( - + +
+
+ +
+
+
+
+ {hero.avatar ? ( + + ) : ( + + )} +
+
+ + {heroName(hero)} + +

{meta}

+
+ {hero.headline && ( +

{hero.headline}

)}
-
- - {heroName(hero)} - -

{meta}

-
- {hero.headline &&

{hero.headline}

} + {actions &&
{actions}
}
- {actions &&
{actions}
} -
- -
+ + + ); } diff --git a/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.styles.ts b/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.styles.ts new file mode 100644 index 0000000..6244932 --- /dev/null +++ b/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.styles.ts @@ -0,0 +1,15 @@ +// A person's badge on their lanyard page (#173): in a laminate sleeve, on +// a lanyard in their accent, on a page that may be light or dark. + +export const hang = 'flex w-full flex-col items-center'; + +// The clasp's hook ends in the sleeve's slot, a little below its top edge. +// The straps are cut cleanly where the box starts, before the shift down, +// so they run up to the header or the canvas's edge. +export const ribbon = + 'relative z-10 h-24 w-auto shrink-0 translate-y-[1.125rem] [clip-path:inset(-1.125rem_-100vw_-100vw)] sm:h-32 md:translate-y-7 md:[clip-path:inset(-1.75rem_-100vw_-100vw)]'; + +/** A bigger sleeve for the bigger badge. */ +export const sleeve = 'md:p-4 md:pt-12'; + +export const slot = 'md:top-4 md:h-4 md:w-24'; diff --git a/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.test.tsx b/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.test.tsx new file mode 100644 index 0000000..b125cc1 --- /dev/null +++ b/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.test.tsx @@ -0,0 +1,33 @@ +import { render, screen } from '@testing-library/react'; +import { describe, expect, it } from 'vitest'; + +import { BadgeLanyard } from './BadgeLanyard'; + +describe('BadgeLanyard (#173)', () => { + it('hangs the badge in a sleeve, from straps printed with the handle', () => { + const { container } = render( + +

Dr Ada Example

+
+ ); + const name = screen.getByRole('heading', { name: 'Dr Ada Example' }); + expect(name.closest('[data-sleeve]')).not.toBeNull(); + const straps = container.querySelectorAll('textPath'); + expect(straps).toHaveLength(2); + for (const strap of straps) { + expect(strap.textContent).toContain('@alice.test'); + } + }); + + it('hangs plain straps while the handle is unknown', () => { + const { container } = render( + +

Loading

+
+ ); + expect(container.querySelector('[data-sleeve]')).not.toBeNull(); + for (const strap of container.querySelectorAll('textPath')) { + expect(strap.textContent).toBe(''); + } + }); +}); diff --git a/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.tsx b/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.tsx new file mode 100644 index 0000000..51e019a --- /dev/null +++ b/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.tsx @@ -0,0 +1,34 @@ +import { BadgeSleeve } from '@/features/qr/components/BadgeSleeve/BadgeSleeve'; +import { LanyardRibbon } from '@/features/qr/components/LanyardRibbon/LanyardRibbon'; +import { cn } from '@/lib/utils'; + +import * as styles from './BadgeLanyard.styles'; +import type { BadgeLanyardProps } from './BadgeLanyard.types'; + +/** + * The lanyard a person's badge hangs from on their page (#173): straps in + * their accent, printed with their handle, and a laminate sleeve, as on + * the Share screen. It never sways: the badge holds buttons. + */ +export function BadgeLanyard({ + children, + handle, + className, +}: BadgeLanyardProps) { + return ( +
+ + + {children} + +
+ ); +} diff --git a/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.types.ts b/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.types.ts new file mode 100644 index 0000000..9717d48 --- /dev/null +++ b/web/src/features/lanyard/components/BadgeLanyard/BadgeLanyard.types.ts @@ -0,0 +1,9 @@ +import type { ReactNode } from 'react'; + +export type BadgeLanyardProps = { + /** The badge, or its loading shape. */ + children: ReactNode; + /** Printed on the straps; plain straps while it's unknown. */ + handle?: string; + className?: string; +}; diff --git a/web/src/features/lanyard/components/LanyardPage/LanyardPage.styles.ts b/web/src/features/lanyard/components/LanyardPage/LanyardPage.styles.ts index 8eaaa4b..48ffd6b 100644 --- a/web/src/features/lanyard/components/LanyardPage/LanyardPage.styles.ts +++ b/web/src/features/lanyard/components/LanyardPage/LanyardPage.styles.ts @@ -1,6 +1,7 @@ // The badge is up to 1,120 px wide; the blocks under it up to 760 px (#129). +// No padding on top: the badge's lanyard starts under the header (#173). export const page = - 'flex w-full max-w-[70rem] flex-col items-center gap-10 self-center px-4 py-8 sm:px-6 sm:py-10'; + 'flex w-full max-w-[70rem] flex-col items-center gap-10 self-center px-4 pb-8 sm:px-6 sm:pb-10'; export const column = 'flex w-full max-w-[47.5rem] flex-col gap-6'; diff --git a/web/src/features/lanyard/components/LanyardSkeleton/LanyardSkeleton.styles.ts b/web/src/features/lanyard/components/LanyardSkeleton/LanyardSkeleton.styles.ts index e20ed43..e7ce052 100644 --- a/web/src/features/lanyard/components/LanyardSkeleton/LanyardSkeleton.styles.ts +++ b/web/src/features/lanyard/components/LanyardSkeleton/LanyardSkeleton.styles.ts @@ -2,10 +2,10 @@ // the badge's sizes, so nothing jumps when it arrives. export const page = - 'flex w-full max-w-[70rem] flex-col items-center gap-10 self-center px-4 py-8 sm:px-6 sm:py-10'; + 'flex w-full max-w-[70rem] flex-col items-center gap-10 self-center px-4 pb-8 sm:px-6 sm:pb-10'; export const badge = - '@container flex w-full flex-col overflow-hidden rounded-sm shadow-badge outline outline-1 -outline-offset-1 outline-border'; + '@container flex w-full flex-col overflow-hidden rounded-sm outline outline-1 -outline-offset-1 outline-border'; const pulse = 'motion-safe:animate-pulse'; diff --git a/web/src/features/lanyard/components/LanyardSkeleton/LanyardSkeleton.tsx b/web/src/features/lanyard/components/LanyardSkeleton/LanyardSkeleton.tsx index 147726d..76ac8d8 100644 --- a/web/src/features/lanyard/components/LanyardSkeleton/LanyardSkeleton.tsx +++ b/web/src/features/lanyard/components/LanyardSkeleton/LanyardSkeleton.tsx @@ -2,26 +2,32 @@ import { useLingui } from '@lingui/react/macro'; import { cn } from '@/lib/utils'; +import { BadgeLanyard } from '../BadgeLanyard/BadgeLanyard'; import * as styles from './LanyardSkeleton.styles'; import type { LanyardSkeletonProps } from './LanyardSkeleton.types'; -/** Holds the badge's place, in its shape, while the profile loads. */ +/** + * Holds the badge's place, in its shape, while the profile loads: on its + * lanyard and in its sleeve, with plain straps (#173). + */ export function LanyardSkeleton({ className }: LanyardSkeletonProps) { const { t } = useLingui(); return (
-
- {t`Loading lanyard…`} -
+
); } diff --git a/web/src/features/lanyard/customise/CustomisePage/CustomisePage.styles.ts b/web/src/features/lanyard/customise/CustomisePage/CustomisePage.styles.ts index 138cd94..0082fc6 100644 --- a/web/src/features/lanyard/customise/CustomisePage/CustomisePage.styles.ts +++ b/web/src/features/lanyard/customise/CustomisePage/CustomisePage.styles.ts @@ -13,17 +13,18 @@ export const workspace = 'flex flex-1 items-stretch md:min-h-0'; // From md up it scrolls, and is positioned, so absolutely placed content // inside it (such as screen-reader text) scrolls with it rather than // stretching the page. +// The lanyard hangs from its top edge (#173), unless a notice comes first. export const canvas = - 'min-w-0 items-center gap-6 px-4 py-6 md:relative md:overflow-y-auto md:px-8 md:py-8'; + 'min-w-0 items-center gap-6 px-4 pb-6 has-[>[data-notice]:not(:empty)]:pt-6 md:relative md:overflow-y-auto md:px-8 md:pb-8 md:has-[>[data-notice]:not(:empty)]:pt-8'; export const intro = 'flex w-full max-w-[640px] flex-col gap-3'; -export const heading = - 'text-[22px] font-semibold leading-7 tracking-tight text-ui-text'; +/** For screen readers: the header already says Customise (#173). */ +export const heading = 'sr-only'; /** Empty but present, so the status is announced when it appears. */ export const moving = - 'text-[15px] leading-[22px] text-ui-text-muted empty:sr-only'; + 'w-full max-w-[640px] text-[15px] leading-[22px] text-ui-text-muted empty:sr-only'; export const frame = 'w-full max-w-[640px]'; diff --git a/web/src/features/lanyard/customise/CustomisePage/CustomisePage.tsx b/web/src/features/lanyard/customise/CustomisePage/CustomisePage.tsx index d4d84ae..305d44a 100644 --- a/web/src/features/lanyard/customise/CustomisePage/CustomisePage.tsx +++ b/web/src/features/lanyard/customise/CustomisePage/CustomisePage.tsx @@ -156,34 +156,39 @@ function Customiser({ /> -
-

- {t`Customise your lanyard`} -

- {(!canEdit || !canKeep || draft.permissionLost) && ( - - )} -

- {move.moving ? t`Updating your podcasts and videos…` : ''} -

- {settings.invalid && ( -
-

- {t`We couldn't read your lanyard settings`} -

-

- {t`They may have been saved in a form Lanyards doesn't recognise. Resetting replaces them with the defaults.`} -

- -
- )} -
+

+ {t`Customise your lanyard`} +

+

+ {move.moving ? t`Updating your podcasts and videos…` : ''} +

+ {(!canEdit || + !canKeep || + draft.permissionLost || + settings.invalid) && ( +
+ {(!canEdit || !canKeep || draft.permissionLost) && ( + + )} + {settings.invalid && ( +
+

+ {t`We couldn't read your lanyard settings`} +

+

+ {t`They may have been saved in a form Lanyards doesn't recognise. Resetting replaces them with the defaults.`} +

+ +
+ )} +
+ )}
{ expect(slot?.className).toMatch(/(^|\s)top-4(\s|$)/); expect(glare?.className).toMatch(/(^|\s)hidden(\s|$)/); }); + + it('is white plastic on the brand ground, and themed on a page (#173)', () => { + const { container, rerender } = render( + +

Badge

+
+ ); + const sleeve = () => container.querySelector('[data-sleeve]'); + expect(sleeve()?.className).toContain('border-white/60'); + rerender( + +

Badge

+
+ ); + // The page may be light or dark: its own ink shows the edge. + expect(sleeve()?.className).not.toContain('border-white/60'); + expect(sleeve()?.className).toContain('border-foreground/20'); + expect(sleeve()?.querySelector('span')?.className).toContain( + 'bg-background' + ); + }); }); diff --git a/web/src/features/qr/components/BadgeSleeve/BadgeSleeve.tsx b/web/src/features/qr/components/BadgeSleeve/BadgeSleeve.tsx index 3c89cc8..af6aeb0 100644 --- a/web/src/features/qr/components/BadgeSleeve/BadgeSleeve.tsx +++ b/web/src/features/qr/components/BadgeSleeve/BadgeSleeve.tsx @@ -5,19 +5,27 @@ import type { BadgeSleeveProps } from './BadgeSleeve.types'; /** * The clear sleeve a badge hangs in (#169), on the Share screen, the - * homepage and the sign-in page (#170). Its lip's slot is where a - * LanyardRibbon's clasp goes through. + * homepage and the sign-in page (#170), and on a person's lanyard page + * (#173). Its lip's slot is where a LanyardRibbon's clasp goes through. */ export function BadgeSleeve({ children, ref, + ground = 'brand', className, slotClassName, glareClassName, }: BadgeSleeveProps) { return ( -
-