diff --git a/DESIGN.md b/DESIGN.md index 5df0e5f5df..8d5c2b2e05 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -316,7 +316,7 @@ Under the graph, a mono 13px strip prints the streaks, `longest streak 12 days - **Activity tooltip:** one dark tooltip (Ink on Background inverted) follows the hovered cell, edge-aligned near the ends ("3 commits on Tue, Oct 14", "2 commits between 14:00 and 15:00 today"); hovering a day or hour tints that period's commits in the profile feed with Primary Soft. ### User Preview -Hovering an avatar, name, or handle (mouse only, 450ms delay, 200ms grace to move into it) opens a 304px Popover preview below the trigger, flipping above near the viewport bottom: a 56px avatar ringed in the user's lane, Follow / Following (Unfollow on hover) top right, name, mono handle with lane dot and a "Follows you" chip, a 3-line bio, and mono counts linking to following and followers. Follow toggles optimistically and rolls back on error. Closes on scroll, Escape, or leaving. +Hovering an avatar, name, or handle (mouse only, 450ms delay, 200ms grace to move into it) opens a 360px Popover preview below the trigger, flipping above near the viewport bottom. The top row holds a 48px avatar ringed in the user's lane, with the safety menu and Follow / Following (Unfollow on hover) on the right. Under it sit the name (600, wrapping to two lines) with "Follows you" and "Muted" chips beside it, and the mono handle with its lane dot (truncated), a 3-line bio follows, then one mono line of counts linking to following and followers. While the user is live, their avatar ring turns red with the LIVE label on its bottom edge, as on the rail, and the stream sits under a hairline as one clickable row: a 112px thumbnail with the LIVE label, a red mono "streaming · youtube.com", "{name} is live", and "Watch now ↗" in Commit Blue, opening the stream in a new tab. Follow toggles optimistically and rolls back on error. Closes on scroll, Escape, or leaving. ### Notifications The inbox is a log too: every row hangs on a Rail Gray rail whose node is a 36px hollow circle holding the type icon (person-plus, reply, quote, star, at, check, cross). A sticky header carries the "Notifications" title over a row of page tabs (All, Replies, Quotes, Stars, Mentions, Follows, Moderation) with the sliding Commit Blue underline; on phones the row scrolls sideways with the current filter kept in view. Day markers ("Today", "Yesterday", "Wed, Oct 14") split the rows the way they split the log. A row opens with a line of stacked 32px avatars (up to three, then a mono `+N` disc) and a mono relative time pushed right, then the sentence: the actor's name (600), their mono handle when they act alone, otherwise "and N others", and the action in plain prose. Words someone else wrote (a reply, quote, or mention) follow at 15px like a commit body; your own commit (a star, an approval, a rejection) sits underneath as a hairline-bordered, muted block clamped to three lines. Moderation rows replace the avatars with a mono `approved` or `rejected` chip, and a rejection prints a mono `reason:` key before the moderator's words. Groups expand in place from a Commit Blue toggle ("5 stars" / "Hide stars"), listing one compact row per event behind a 1px Rail Gray guide line, each follower with their own Follow button. Rows the inbox marked read on this visit ring their node in Commit Blue and sit above a `HEAD@{last visit}` marker. While you read, polling adds new rows above without moving the ones on screen, and a Commit Blue pill ("↑ 1 new notification") takes you to them. Empty filters speak in git's voice (`$ cat /dev/notifications | grep stars`) with a link back to all notifications; the end of the list is a hollow root node: "That's the oldest notification. There's nothing before it." diff --git a/resources/js/components/live-stream-card.tsx b/resources/js/components/live-stream-card.tsx index d292f9855b..36e5554131 100644 --- a/resources/js/components/live-stream-card.tsx +++ b/resources/js/components/live-stream-card.tsx @@ -67,6 +67,58 @@ export function LiveStreamCard({ ); } +/** + * The stream folded into one row, for a card that is about the person rather than the stream: a small thumbnail + * beside where it plays, the whole row linking out to it. + */ +export function LiveStreamRow({ + user, + stream, +}: { + user: Pick; + stream: LiveStream; +}) { + return ( + + + + + + + + streaming · youtube.com + + {/* A long name gives way, never "is live". */} + + {user.name} + is live + + + Watch now + + + + + ); +} + /** * The avatar's ring turns red and a LIVE label sits on its edge, sized to the avatar it marks. */ diff --git a/resources/js/components/user-preview.tsx b/resources/js/components/user-preview.tsx index cb24adef27..135c4079b5 100644 --- a/resources/js/components/user-preview.tsx +++ b/resources/js/components/user-preview.tsx @@ -12,10 +12,7 @@ import { useFollowHover, useIsFollowing, } from '@/components/follow-button'; -import { - LiveAvatarMarker, - LiveStreamCard, -} from '@/components/live-stream-card'; +import { LiveAvatarMarker, LiveStreamRow } from '@/components/live-stream-card'; import { Button } from '@/components/ui/button'; import { UserAvatar } from '@/components/user-avatar'; import { UserSafetyMenu } from '@/components/user-safety-menu'; @@ -43,11 +40,11 @@ type Position = const openDelay = 450; const closeDelay = 200; -const previewWidth = 304; +const previewWidth = 360; const previewHeight = 260; const viewportMargin = 8; -// Where the centre of the preview's avatar sits: border, padding and half of the size-14 avatar. -const avatarCentre = 45; +// Where the centre of the preview's avatar sits: border, padding and half of the size-12 avatar. +const avatarCentre = 41; const cache = new Map(); async function fetchPreview(url: string): Promise { @@ -284,7 +281,7 @@ export function UserPreview({ scheduleClose(); }} data-state={isOpen ? 'open' : 'closed'} - className="fixed z-50 w-76 rounded-xl border bg-popover p-4 text-popover-foreground shadow-[0_12px_32px_-12px_rgb(0_0_0/0.35)] ease-spring data-[state=closed]:scale-70 data-[state=closed]:opacity-0 data-[state=closed]:ease-in motion-safe:transition-[opacity,scale] motion-safe:duration-560 motion-safe:data-[state=closed]:duration-160 starting:scale-70 starting:opacity-0" + className="fixed z-50 w-90 rounded-xl border bg-popover p-4 text-popover-foreground shadow-[0_12px_32px_-12px_rgb(0_0_0/0.35)] ease-spring data-[state=closed]:scale-70 data-[state=closed]:opacity-0 data-[state=closed]:ease-in motion-safe:transition-[opacity,scale] motion-safe:duration-560 motion-safe:data-[state=closed]:duration-160 starting:scale-70 starting:opacity-0" style={{ ...position, transformOrigin: anchor @@ -342,6 +339,7 @@ function UserPreviewContent({ /** * The button flips right away, but like every other follow control the shared state only changes once the server confirms, so there is nothing to roll back. + * It is an async visit, as follow buttons are, so following someone else before this answers doesn't cancel it. */ const toggleFollow = () => { if (auth.user === null) { @@ -362,6 +360,7 @@ function UserPreviewContent({ ? UserFollowController.store(user) : UserFollowController.destroy(user), { + async: true, preserveScroll: true, preserveState: true, onSuccess: () => { @@ -387,12 +386,20 @@ function UserPreviewContent({ return (
-
- + {/* The LIVE label hangs below the avatar, so the header keeps the usual gap under it. */} +
+ @@ -401,7 +408,7 @@ function UserPreviewContent({ {!isCurrentUser && (data ? ( -
+
{auth.user && ( { markToggled(); toggleFollow(); @@ -439,43 +446,47 @@ function UserPreviewContent({ )}
) : ( - + ))}
- - {user.name} - -

- - @{user.username} - {data?.followsYou && ( - - Follows you - - )} - {data?.isMuting && ( - - Muted - - )} -

+
+
+ + {user.name} + + {data?.followsYou && ( + + Follows you + + )} + {data?.isMuting && ( + + Muted + + )} +
+

+ + @{user.username} +

+
{user.bio && !data?.isUnavailable && ( -

+

)} -
+
{data?.isUnavailable ? ( -

+

{data.isBlocking ? `You blocked @${user.username}.` : 'This profile is unavailable.'} @@ -494,7 +505,7 @@ function UserPreviewContent({ {data.user.following_count} @@ -505,7 +516,7 @@ function UserPreviewContent({ {data.user.followers_count} @@ -523,8 +534,8 @@ function UserPreviewContent({

{user.live && !data?.isUnavailable && ( -
- +
+
)}
diff --git a/tests/Unit/FollowState.test.tsx b/tests/Unit/FollowState.test.tsx index c295cd7f27..8e717e6d11 100644 --- a/tests/Unit/FollowState.test.tsx +++ b/tests/Unit/FollowState.test.tsx @@ -9,6 +9,7 @@ type Props = Record & { children?: ReactNode }; let showPreview = false; type VisitOptions = { + async?: boolean; onHttpException?: (response: { status: number }) => boolean | void; onSuccess?: () => void; onError?: () => void; @@ -32,8 +33,7 @@ vi.doMock('react', () => ({ : initial, () => {}, ], - useSyncExternalStore: (_subscribe: unknown, read: () => unknown) => - read(), + useSyncExternalStore: (_subscribe: unknown, read: () => unknown) => read(), })); vi.doMock('react-dom', async () => ({ ...(await vi.importActual('react-dom')), @@ -319,8 +319,10 @@ test('unfollowing through a cached preview keeps its follower count', () => { followFromProfile(user); const changes: { user: Profile }[] = []; - (previewFollowButton(user, false, (data) => changes.push(data)).props - .onClick as () => void)(); + ( + previewFollowButton(user, false, (data) => changes.push(data)).props + .onClick as () => void + )(); visits.at(-1)?.onSuccess?.(); assert.equal(changes.at(-1)?.user.followers_count, 0); @@ -395,3 +397,17 @@ test('a second click on a follow still on its way sends nothing', () => { assert.equal(finished.disabled, false); assert.equal((finished.onBefore as () => boolean)(), true); }); + +test('following several people from their previews sends every follow without cancelling the others', () => { + const first = suggestion('lucia'); + const second = suggestion('marco'); + + (previewFollowButton(first).props.onClick as () => void)(); + const firstFollow = visits.at(-1); + (previewFollowButton(second).props.onClick as () => void)(); + const secondFollow = visits.at(-1); + + assert.equal(firstFollow?.async, true); + assert.equal(secondFollow?.async, true); + assert.notEqual(firstFollow, secondFollow); +}); diff --git a/tests/Unit/LiveStreamRow.test.tsx b/tests/Unit/LiveStreamRow.test.tsx new file mode 100644 index 0000000000..dc7d8a8cf0 --- /dev/null +++ b/tests/Unit/LiveStreamRow.test.tsx @@ -0,0 +1,50 @@ +/// +import assert from 'node:assert/strict'; +import { renderToStaticMarkup } from 'react-dom/server'; +import { test } from 'vite-plus/test'; +import { LiveStreamRow } from '../../resources/js/components/live-stream-card'; + +const stream = { + url: 'https://www.youtube.com/watch?v=abc123', + thumbnail_url: 'https://i.ytimg.com/vi/abc123/hqdefault_live.jpg', +}; + +test('live stream row links out to the stream in a new tab', () => { + const html = renderToStaticMarkup( + , + ); + + assert.match( + html, + /^]*href="https:\/\/www\.youtube\.com\/watch\?v=abc123"/, + ); + assert.match(html, /target="_blank"/); + assert.match(html, /rel="noopener noreferrer"/); + assert.match(html, /data-test="live-stream-row"/); +}); + +test('live stream row shows the thumbnail, the LIVE label, where it streams and the call to watch', () => { + const html = renderToStaticMarkup( + , + ); + + assert.match( + html, + /src="https:\/\/i\.ytimg\.com\/vi\/abc123\/hqdefault_live\.jpg"/, + ); + assert.match(html, /data-test="live-badge"/); + assert.match(html, /streaming · youtube\.com/); + assert.match(html.replace(/<[^>]+>/g, ''), /Nuno is live/); + assert.match(html, /Watch now/); +}); + +test('live stream row shortens a long name but always says the person is live', () => { + const name = 'Prof. Berta McDermott-Vandervort of the Laravel Core Team'; + const html = renderToStaticMarkup( + , + ); + + assert.match(html, new RegExp(`${name}`)); + assert.match(html, / is live<\/span>/); + assert.match(html, new RegExp(`title="${name} is live"`)); +});