Skip to content
Open
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
2 changes: 1 addition & 1 deletion DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
52 changes: 52 additions & 0 deletions resources/js/components/live-stream-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<User, 'name'>;
stream: LiveStream;
}) {
return (
<a
href={stream.url}
target="_blank"
rel="noopener noreferrer"
className="-mx-2 flex items-center gap-3 rounded-lg p-2 outline-offset-2 focus-visible:outline-2 focus-visible:outline-ring active:scale-[0.98] motion-safe:transition-[background-color,scale] motion-safe:duration-160 motion-safe:ease-out [@media(hover:hover)_and_(pointer:fine)]:hover:bg-accent"
data-test="live-stream-row"
>
<span className="relative block aspect-video w-28 shrink-0 overflow-clip rounded-md bg-muted">
<img
src={stream.thumbnail_url}
alt=""
loading="lazy"
className="size-full object-cover"
/>
<LiveBadge className="absolute inset-s-1.5 inset-bs-1.5" />
</span>
<span className="min-w-0 flex-1">
<span className="block font-mono text-[11px] text-red-600 dark:text-red-400">
streaming · youtube.com
</span>
{/* A long name gives way, never "is live". */}
<span
className="mbs-0.5 flex text-sm font-medium whitespace-pre"
title={`${user.name} is live`}
>
<span className="truncate">{user.name}</span>
<span className="shrink-0"> is live</span>
</span>
<span className="mbs-0.5 flex items-baseline gap-1 text-[13px] text-primary">
Watch now
<ArrowUpRight
aria-hidden
className="h-[1.2cap] w-auto shrink-0"
/>
</span>
</span>
</a>
);
}

/**
* The avatar's ring turns red and a LIVE label sits on its edge, sized to the avatar it marks.
*/
Expand Down
99 changes: 55 additions & 44 deletions resources/js/components/user-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<string, PreviewData>();

async function fetchPreview(url: string): Promise<PreviewData> {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -362,6 +360,7 @@ function UserPreviewContent({
? UserFollowController.store(user)
: UserFollowController.destroy(user),
{
async: true,
preserveScroll: true,
preserveState: true,
onSuccess: () => {
Expand All @@ -387,12 +386,20 @@ function UserPreviewContent({

return (
<div style={{ '--lane': lane } as CSSProperties}>
<div className="flex items-start justify-between gap-3">
<Link href={show(user)} className="relative rounded-full">
{/* The LIVE label hangs below the avatar, so the header keeps the usual gap under it. */}
<div
className={cn('flex items-center justify-between gap-3', {
'pbe-1.5': user.live,
})}
>
<Link
href={show(user)}
className="relative shrink-0 rounded-full"
>
<UserAvatar
user={user}
className={cn(
'size-14 text-lg ring-2 ring-(--lane) ring-offset-2 ring-offset-popover',
'size-12 ring-2 ring-(--lane) ring-offset-2 ring-offset-popover',
{ 'ring-red-600': user.live },
)}
/>
Expand All @@ -401,7 +408,7 @@ function UserPreviewContent({

{!isCurrentUser &&
(data ? (
<div className="flex gap-2">
<div className="flex shrink-0 gap-1.5">
{auth.user && (
<UserSafetyMenu
user={user}
Expand All @@ -417,7 +424,7 @@ function UserPreviewContent({
variant={
shownIsFollowing ? 'outline' : 'default'
}
className="group/follow min-w-24"
className="group/follow min-w-22"
onClick={() => {
markToggled();
toggleFollow();
Expand All @@ -439,43 +446,47 @@ function UserPreviewContent({
)}
</div>
) : (
<span className="h-8 w-24 rounded-md bg-muted-foreground/15 motion-safe:animate-pulse" />
<span className="h-8 w-30 shrink-0 rounded-md bg-muted-foreground/15 motion-safe:animate-pulse" />
))}
</div>

<Link
href={show(user)}
className="mt-3 block truncate font-semibold hover:underline"
>
{user.name}
</Link>
<p className="flex items-center gap-1.5 font-mono text-[13px] text-muted-foreground">
<span
aria-hidden
className="size-2 shrink-0 rounded-full bg-(--lane)"
/>
<span className="truncate">@{user.username}</span>
{data?.followsYou && (
<span className="ml-1 shrink-0 rounded bg-muted px-1.5 py-0.5 font-sans text-xs">
Follows you
</span>
)}
{data?.isMuting && (
<span className="ml-1 shrink-0 rounded bg-muted px-1.5 py-0.5 font-sans text-xs">
Muted
</span>
)}
</p>
<div className="mbs-3 min-w-0">
<div className="flex items-center gap-2">
<Link
href={show(user)}
className="line-clamp-2 min-w-0 leading-snug font-semibold wrap-break-word [@media(hover:hover)_and_(pointer:fine)]:hover:underline"
>
{user.name}
</Link>
{data?.followsYou && (
<span className="shrink-0 rounded bg-muted px-1.5 py-0.5 text-xs">
Follows you
</span>
)}
{data?.isMuting && (
<span className="shrink-0 rounded bg-muted px-1.5 py-0.5 text-xs">
Muted
</span>
)}
</div>
<p className="flex items-center gap-1.5 font-mono text-[13px] text-muted-foreground">
<span
aria-hidden
className="size-2 shrink-0 rounded-full bg-(--lane)"
/>
<span className="truncate">@{user.username}</span>
</p>
</div>

{user.bio && !data?.isUnavailable && (
<p className="mt-2 line-clamp-3 text-sm text-pretty">
<p className="mbs-3 line-clamp-3 text-sm text-pretty">
<BioText bio={user.bio} />
</p>
)}

<div className="mt-3 flex gap-4 text-sm">
<div className="mbs-3 flex gap-4 font-mono text-[13px]">
{data?.isUnavailable ? (
<p className="text-muted-foreground">
<p className="font-sans text-sm text-muted-foreground">
{data.isBlocking
? `You blocked @${user.username}.`
: 'This profile is unavailable.'}
Expand All @@ -494,7 +505,7 @@ function UserPreviewContent({
</span>
<Link
href={UserFollowingController.index(user)}
className="hover:underline"
className="[@media(hover:hover)_and_(pointer:fine)]:hover:underline"
>
<span className="font-mono font-medium">
{data.user.following_count}
Expand All @@ -505,7 +516,7 @@ function UserPreviewContent({
</Link>
<Link
href={UserFollowersController.index(user)}
className="hover:underline"
className="[@media(hover:hover)_and_(pointer:fine)]:hover:underline"
>
<span className="font-mono font-medium">
{data.user.followers_count}
Expand All @@ -523,8 +534,8 @@ function UserPreviewContent({
</div>

{user.live && !data?.isUnavailable && (
<div className="mt-4 border-t pt-4">
<LiveStreamCard user={user} stream={user.live} />
<div className="mbs-3 border-bs pbs-2">
<LiveStreamRow user={user} stream={user.live} />
</div>
)}
</div>
Expand Down
24 changes: 20 additions & 4 deletions tests/Unit/FollowState.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Props = Record<string, unknown> & { children?: ReactNode };

let showPreview = false;
type VisitOptions = {
async?: boolean;
onHttpException?: (response: { status: number }) => boolean | void;
onSuccess?: () => void;
onError?: () => void;
Expand All @@ -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')),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
50 changes: 50 additions & 0 deletions tests/Unit/LiveStreamRow.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/// <reference types="node" />
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(
<LiveStreamRow user={{ name: 'Nuno' }} stream={stream} />,
);

assert.match(
html,
/^<a [^>]*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(
<LiveStreamRow user={{ name: 'Nuno' }} stream={stream} />,
);

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(
<LiveStreamRow user={{ name }} stream={stream} />,
);

assert.match(html, new RegExp(`<span class="truncate">${name}</span>`));
assert.match(html, /<span class="shrink-0"> is live<\/span>/);
assert.match(html, new RegExp(`title="${name} is live"`));
});