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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

## [Unreleased]

### Added

- The website uses your Google or Discord picture as your profile picture when you sign in with one of them.
- While the console is still sending images, the website shows how many have arrived (in the sync badge and on the profile), and they appear as they arrive.

### Changed

- Images the console has not sent yet show the placeholder instead of a broken image.

### Security

- The console's pairing QR code puts the code in the URL fragment (`/link#code=…`), which browsers never send, so the code no longer reaches the server or its logs. The website still accepts `/link?code=…` from older consoles.
Expand Down
5 changes: 5 additions & 0 deletions contract/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export interface Trophy {
iconUrl: string | null;
}

export interface ImageSync {
total: number;
stored: number;
}

export interface EarnedTrophy {
setId: string;
setName: string;
Expand Down
21 changes: 21 additions & 0 deletions web/src/app/(app)/(profile)/_components/image-sync-banner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { ImageSync } from '@openpsapp/contract/api';
import { ImageIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { Card } from '@/components/ui/card';
import { Progress } from '@/components/ui/progress';

export function ImageSyncBanner({ images, className }: { images: ImageSync; className?: string }) {
const { t } = useTranslation();
return (
<Card className={className} role="status">
<div className="flex items-start gap-3 px-5 md:px-6">
<ImageIcon className="mt-0.5 size-5 shrink-0 text-muted-foreground" />
<div className="min-w-0 flex-1">
<p className="font-semibold">{t('images.title')}</p>
<p className="mt-1 text-sm text-soft-foreground">{t('images.description', { stored: images.stored, total: images.total })}</p>
<Progress value={(images.stored * 100) / images.total} size="sm" className="mt-3" aria-label={t('images.title')} />
</div>
</div>
</Card>
);
}
5 changes: 4 additions & 1 deletion web/src/app/(app)/(profile)/_components/profile-hero.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import type { ReactNode } from 'react';
import { Avatar, AvatarFallback } from '@/components/ui/avatar';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';

export function ProfileHero({
name,
initial,
avatarUrl,
summary,
summaryShort,
heroUrl,
aside,
}: {
name: string;
initial: string;
avatarUrl: string | null;
summary: string;
summaryShort: string;
heroUrl: string | null;
Expand All @@ -26,6 +28,7 @@ export function ProfileHero({
<div className="relative mx-auto flex max-w-page flex-wrap items-end justify-between gap-8 px-4 pt-28 pb-4 sm:px-6 md:pt-14 md:pb-10 lg:px-12">
<div className="flex min-w-0 items-center gap-3.5 md:gap-6">
<Avatar className="size-avatar-lg md:size-avatar-xl md:shadow-avatar">
{avatarUrl && <AvatarImage src={avatarUrl} alt="" referrerPolicy="no-referrer" />}
<AvatarFallback className="text-(length:--text-heading) font-extrabold md:text-(length:--text-display)">
{initial}
</AvatarFallback>
Expand Down
9 changes: 8 additions & 1 deletion web/src/app/(app)/(profile)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useUser } from '@clerk/react';
import { formatDuration } from '@openpsapp/core';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -6,10 +7,12 @@ import { PageLoader } from '@/components/page-loader';
import { useDevices } from '@/hooks/use-devices';
import { useEarnedTrophies } from '@/hooks/use-earned-trophies';
import { useGames } from '@/hooks/use-games';
import { useImageSync } from '@/hooks/use-image-sync';
import { useProfile } from '@/hooks/use-profile';
import { useTrophySets } from '@/hooks/use-trophy-sets';
import { paths } from '@/lib/links';
import { describeSync } from '../_lib/sync-status';
import { avatarUrl, describeSync, pendingImages } from '../_lib/sync-status';
import { ImageSyncBanner } from './_components/image-sync-banner';
import { LatestTrophies } from './_components/latest-trophies';
import { MonthRecap } from './_components/month-recap';
import { PlatinumCard } from './_components/platinum-card';
Expand All @@ -29,6 +32,8 @@ export default function ProfilePage() {
const sets = useTrophySets();
const earned = useEarnedTrophies();
const devices = useDevices();
const images = pendingImages(useImageSync());
const { user: account } = useUser();
const [expanded, setExpanded] = useState(false);
const recap = useMonthRecap(earned.data ?? NO_ITEMS, games.data ?? NO_ITEMS, sets.data ?? NO_ITEMS);

Expand Down Expand Up @@ -64,12 +69,14 @@ export default function ProfilePage() {
<ProfileHero
name={name}
initial={name.slice(0, 1).toUpperCase()}
avatarUrl={avatarUrl(account)}
summary={t('profile.summary', { games: gamesLabel, playtime })}
summaryShort={t('profile.summaryShort', { games: gamesLabel, playtime })}
heroUrl={heroImage(list)}
aside={<TrophySummary totals={totals.trophies} className="max-md:hidden" />}
/>
<div className="mx-auto flex max-w-page flex-wrap items-start gap-5 px-4 pb-16 sm:px-6 md:gap-10 md:pt-2 lg:px-12">
{images && <ImageSyncBanner images={images} className="w-full" />}
<TrophySummaryCompact totals={totals.trophies} className="w-full md:hidden" />
<div className="flex min-w-0 grow-999 basis-main flex-col gap-5 md:gap-10">
<RecentGames
Expand Down
7 changes: 5 additions & 2 deletions web/src/app/(app)/_components/account-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { UserAvatar } from './user-avatar';

export function AccountMenu({
initial,
avatarUrl,
name,
email,
whatIsSentUrl,
onAccount,
onSignOut,
}: {
initial: string;
avatarUrl: string | null;
name: string | null;
email: string | null;
whatIsSentUrl: string;
Expand All @@ -29,9 +32,9 @@ export function AccountMenu({
<DropdownMenu>
<DropdownMenuTrigger
aria-label={t('header.accountMenu')}
className="flex size-(--control-md) items-center justify-center rounded-full bg-primary font-semibold text-primary-foreground outline-none focus-visible:ring-3 focus-visible:ring-ring/30 data-popup-open:ring-3 data-popup-open:ring-ring/30"
className="flex size-(--control-md) items-center justify-center rounded-full outline-none focus-visible:ring-3 focus-visible:ring-ring/30 data-popup-open:ring-3 data-popup-open:ring-ring/30"
>
{initial}
<UserAvatar initial={initial} imageUrl={avatarUrl} />
</DropdownMenuTrigger>
<DropdownMenuContent align="end" sideOffset={8} className="w-60">
<DropdownMenuGroup>
Expand Down
7 changes: 5 additions & 2 deletions web/src/app/(app)/_components/mobile-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ import { useTranslation } from 'react-i18next';
import { Link } from 'react-router';
import { LogoMark } from '@/components/brand/logo';
import { Button } from '@/components/ui/button';
import { UserAvatar } from './user-avatar';

export function MobileHeader({
homeTo,
accountTo,
initial,
avatarUrl,
status,
onSearch,
}: {
homeTo: string;
accountTo: string;
initial: string;
avatarUrl: string | null;
status: ReactNode;
onSearch: () => void;
}) {
Expand All @@ -31,9 +34,9 @@ export function MobileHeader({
<Link
to={accountTo}
aria-label={t('nav.account')}
className="flex size-(--control-md) shrink-0 items-center justify-center rounded-full bg-primary font-bold text-primary-foreground"
className="flex size-(--control-md) shrink-0 items-center justify-center rounded-full"
>
{initial}
<UserAvatar initial={initial} imageUrl={avatarUrl} fallbackClassName="font-bold" />
</Link>
</header>
);
Expand Down
30 changes: 26 additions & 4 deletions web/src/app/(app)/_components/sync-badge.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import type { ImageSync } from '@openpsapp/contract/api';
import { formatTimeAgo } from '@openpsapp/core';
import { cn } from 'cn';
import { useTranslation } from 'react-i18next';
import { Badge } from '@/components/ui/badge';
import type { SyncState } from '../_types/sync';

export function SyncBadge({ sync, now }: { sync: SyncState; now: Date }) {
export function SyncBadge({ sync, images, now }: { sync: SyncState; images: ImageSync | null; now: Date }) {
const { t, i18n } = useTranslation();
if (sync.kind === 'none') return null;
if (sync.kind === 'synced' && images) {
return (
<Badge variant="outline" className="px-2.5 py-1">
<span aria-hidden="true" className="size-1.5 animate-pulse rounded-full bg-warning" />
{t('images.badge', { stored: images.stored, total: images.total })}
</Badge>
);
}
if (sync.kind === 'waiting') {
return (
<Badge variant="outline" className="px-2.5 py-1">
Expand All @@ -22,15 +31,28 @@ export function SyncBadge({ sync, now }: { sync: SyncState; now: Date }) {
);
}

export function SyncPill({ sync, now, className }: { sync: SyncState; now: Date; className?: string }) {
export function SyncPill({ sync, images, now, className }: { sync: SyncState; images: ImageSync | null; now: Date; className?: string }) {
const { t, i18n } = useTranslation();
if (sync.kind === 'none') return null;
const text = sync.kind === 'waiting' ? t('sync.waiting') : t('sync.short', { ago: formatTimeAgo(sync.at, now, i18n.language) });
const sending = sync.kind === 'synced' && images;
const text =
sync.kind === 'waiting'
? t('sync.waiting')
: sending
? t('images.badge', { stored: images.stored, total: images.total })
: t('sync.short', { ago: formatTimeAgo(sync.at, now, i18n.language) });
return (
<span
className={cn('flex min-w-0 items-center gap-2 rounded-full bg-muted/70 px-3 py-1.5 text-caption text-soft-foreground', className)}
>
<span aria-hidden="true" className={cn('size-2 shrink-0 rounded-full', sync.kind === 'synced' ? 'bg-success' : 'bg-warning')} />
<span
aria-hidden="true"
className={cn(
'size-2 shrink-0 rounded-full',
sync.kind === 'synced' && !sending ? 'bg-success' : 'bg-warning',
sending && 'animate-pulse',
)}
/>
<span className="truncate">{text}</span>
</span>
);
Expand Down
20 changes: 20 additions & 0 deletions web/src/app/(app)/_components/user-avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';

export function UserAvatar({
initial,
imageUrl,
className,
fallbackClassName,
}: {
initial: string;
imageUrl: string | null;
className?: string;
fallbackClassName?: string;
}) {
return (
<Avatar className={className}>
{imageUrl && <AvatarImage src={imageUrl} alt="" referrerPolicy="no-referrer" />}
<AvatarFallback className={fallbackClassName}>{initial}</AvatarFallback>
</Avatar>
);
}
6 changes: 5 additions & 1 deletion web/src/app/(app)/_hooks/use-shell.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { useClerk, useUser } from '@clerk/react';
import { useLocation, useMatches } from 'react-router';
import { useDevices } from '@/hooks/use-devices';
import { useImageSync } from '@/hooks/use-image-sync';
import { useNow } from '@/hooks/use-now';
import { useProfile } from '@/hooks/use-profile';
import { isFocusedRoute, sectionFor } from '../_lib/navigation';
import { describeSync } from '../_lib/sync-status';
import { avatarUrl, describeSync, pendingImages } from '../_lib/sync-status';

export function useShell() {
const location = useLocation();
const matches = useMatches();
const profile = useProfile();
const devices = useDevices();
const images = useImageSync();
const { user } = useUser();
const clerk = useClerk();
const now = useNow();
Expand All @@ -22,6 +24,8 @@ export function useShell() {
name,
email,
initial: (name ?? '?').slice(0, 1).toUpperCase(),
avatarUrl: avatarUrl(user),
images: pendingImages(images),
sync: describeSync(devices.data),
now,
signOut: () => void clerk.signOut(),
Expand Down
19 changes: 18 additions & 1 deletion web/src/app/(app)/_lib/sync-status.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DeviceInfo } from '@openpsapp/contract/pairing';
import { describe, expect, it } from 'vitest';
import { currentDevice, describeSync } from './sync-status';
import { avatarUrl, currentDevice, describeSync, pendingImages } from './sync-status';

const device = (id: string, createdAt: string, lastSyncAt: string | null): DeviceInfo => ({
id,
Expand Down Expand Up @@ -28,3 +28,20 @@ describe('describeSync', () => {
expect(describeSync(devices)).toEqual({ kind: 'synced', deviceId: '2', name: 'P2', at: '2026-11-14T16:37:00Z' });
});
});

describe('pendingImages', () => {
it('reports images only while some are still on their way', () => {
expect(pendingImages({ total: 83, stored: 16 })).toEqual({ total: 83, stored: 16 });
expect(pendingImages({ total: 83, stored: 83 })).toBeNull();
expect(pendingImages({ total: 0, stored: 0 })).toBeNull();
expect(pendingImages(undefined)).toBeNull();
});
});

describe('avatarUrl', () => {
it('uses the sign-in picture only when the account has one', () => {
expect(avatarUrl({ hasImage: true, imageUrl: 'https://img.clerk.com/a' })).toBe('https://img.clerk.com/a');
expect(avatarUrl({ hasImage: false, imageUrl: 'https://img.clerk.com/default' })).toBeNull();
expect(avatarUrl(null)).toBeNull();
});
});
9 changes: 9 additions & 0 deletions web/src/app/(app)/_lib/sync-status.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ImageSync } from '@openpsapp/contract/api';
import type { DeviceInfo } from '@openpsapp/contract/pairing';
import type { SyncState } from '../_types/sync';

Expand All @@ -12,3 +13,11 @@ export function describeSync(devices: DeviceInfo[] | undefined): SyncState {
if (!device.lastSyncAt) return { kind: 'waiting', deviceId: device.id, name: device.profileName };
return { kind: 'synced', deviceId: device.id, name: device.profileName, at: device.lastSyncAt };
}

export function pendingImages(images: ImageSync | null | undefined): ImageSync | null {
return images && images.stored < images.total ? images : null;
}

export function avatarUrl(user: { hasImage: boolean; imageUrl: string } | null | undefined): string | null {
return user?.hasImage ? user.imageUrl : null;
}
6 changes: 4 additions & 2 deletions web/src/app/(app)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ export default function AppLayout() {
section={shell.section}
homeTo={paths.profile}
onSearch={() => search.setOpen(true)}
status={<SyncBadge sync={shell.sync} now={shell.now} />}
status={<SyncBadge sync={shell.sync} images={shell.images} now={shell.now} />}
menu={
<AccountMenu
initial={shell.initial}
avatarUrl={shell.avatarUrl}
name={shell.name}
email={shell.email}
whatIsSentUrl={SYNC_DOC_URL}
Expand All @@ -45,7 +46,8 @@ export default function AppLayout() {
homeTo={paths.profile}
accountTo={paths.account}
initial={shell.initial}
status={<SyncPill sync={shell.sync} now={shell.now} />}
avatarUrl={shell.avatarUrl}
status={<SyncPill sync={shell.sync} images={shell.images} now={shell.now} />}
onSearch={() => search.setOpen(true)}
/>
)}
Expand Down
25 changes: 25 additions & 0 deletions web/src/hooks/use-image-sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { ImageSync } from '@openpsapp/contract/api';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useEffect, useRef } from 'react';
import { api } from '@/lib/api';
import { queryKeys } from '@/lib/query-keys';

export const IMAGE_SYNC_POLL_MS = 3000;

export function useImageSync() {
const queryClient = useQueryClient();
const query = useQuery({
queryKey: queryKeys.images,
queryFn: () => api<ImageSync>('/images'),
refetchInterval: (q) => (q.state.data && q.state.data.stored < q.state.data.total ? IMAGE_SYNC_POLL_MS : false),
});
const stored = query.data?.stored;
const seen = useRef(stored);
useEffect(() => {
if (stored === undefined || stored === seen.current) return;
const first = seen.current === undefined;
seen.current = stored;
if (!first) void queryClient.invalidateQueries({ queryKey: queryKeys.library });
}, [stored, queryClient]);
return query.data ?? null;
}
5 changes: 5 additions & 0 deletions web/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
"waiting": "Waiting for the first sync",
"none": "No PS5 connected"
},
"images": {
"title": "Images on their way",
"description": "Your PS5 is sending game and trophy images: {{stored}} of {{total}}. They show up here as they arrive.",
"badge": "Sending images {{stored}}/{{total}}"
},
"footer": {
"data": "Data from {{name}}'s PS5 · last sync {{date}}",
"dataNever": "Data from {{name}}'s PS5 · not synced yet",
Expand Down
Loading
Loading