Address PR #310 review feedback on the public profile page

This commit is contained in:
Aaron Po
2026-09-13 01:05:01 -04:00
parent 81717eddbf
commit 132f93cc87
12 changed files with 127 additions and 32 deletions

View File

@@ -13,7 +13,7 @@ Covers `/users/:id` (`routes/user-profile.tsx`). Mirrors the format of
| Field | Status | Source | Gap |
| ---------------------------------------- | ------ | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Username, name, joined date | ✅ | `GET /api/user/{id}` (`UserAccount`) | |
| Username, name, joined date | ✅ | `GET /api/user/{id}/profile` (`PublicUserProfileDto`) | |
| `isOwnProfile` | ✅ | Compares the session's `userAccountId` to the route param | |
| Bio | ⚠️ | `FILLER_PROFILE_META.bio` | `Social.UserProfile.Biography` exists (`IUserProfileRepository`, `UpdateBiographyHandler`) but there's no query/controller route to read another user's profile — only a write path for the authenticated user's own. |
| Location | ❌ | `FILLER_PROFILE_META.location` | No location field on `UserAccount` or `UserProfile`. |

View File

@@ -22,13 +22,19 @@ const meta = {
export default meta;
type Story = StoryObj<typeof meta>;
const panels = {
activity: <p>Activity panel</p>,
following: <p>Following panel</p>,
liked: <p>Liked panel</p>,
};
const ControlledTabs = () => {
const [activeTab, setActiveTab] = useState<ProfileTab>('activity');
return <ProfileTabs activeTab={activeTab} onChange={setActiveTab} />;
return <ProfileTabs activeTab={activeTab} onChange={setActiveTab} panels={panels} />;
};
export const Default: Story = {
args: { activeTab: 'activity', onChange: fn() },
args: { activeTab: 'activity', onChange: fn(), panels },
render: () => <ControlledTabs />,
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
@@ -36,5 +42,6 @@ export const Default: Story = {
await expect(followingTab).toHaveAttribute('aria-selected', 'false');
await userEvent.click(followingTab);
await expect(followingTab).toHaveAttribute('aria-selected', 'true');
await expect(canvas.getByText('Following panel')).toBeInTheDocument();
},
};

View File

@@ -1,4 +1,5 @@
import { Tab, TabGroup, TabList } from '@headlessui/react';
import { Tab, TabGroup, TabList, TabPanel, TabPanels } from '@headlessui/react';
import type { ReactNode } from 'react';
export type ProfileTab = 'activity' | 'following' | 'liked';
@@ -11,9 +12,10 @@ const TABS: { id: ProfileTab; label: string }[] = [
interface ProfileTabsProps {
activeTab: ProfileTab;
onChange: (tab: ProfileTab) => void;
panels: Record<ProfileTab, ReactNode>;
}
const ProfileTabs = ({ activeTab, onChange }: ProfileTabsProps) => {
const ProfileTabs = ({ activeTab, onChange, panels }: ProfileTabsProps) => {
const selectedIndex = TABS.findIndex((tab) => tab.id === activeTab);
return (
@@ -28,6 +30,11 @@ const ProfileTabs = ({ activeTab, onChange }: ProfileTabsProps) => {
</Tab>
))}
</TabList>
<TabPanels className="mt-5">
{TABS.map((tab) => (
<TabPanel key={tab.id}>{panels[tab.id]}</TabPanel>
))}
</TabPanels>
</TabGroup>
);
};

View File

@@ -2,7 +2,7 @@ import { useState } from 'react';
import { data } from 'react-router';
import RouteErrorState from '../../../components/ui/error/RouteErrorState';
import { getOptionalAuth } from '../../auth/auth.server';
import { getPublicUserProfile } from '../users.server';
import { getPublicUserProfile, type PublicUserProfile } from '../users.server';
import ProfileSidebarCard from '../components/profile/ProfileSidebarCard';
import ProfileTabs, { type ProfileTab } from '../components/profile/ProfileTabs';
import ActivityTab from '../components/profile/tabs/ActivityTab';
@@ -37,9 +37,17 @@ export const loader = async ({ request, params }: Route.LoaderArgs) => {
const joinedLabel = (isoDate: string) =>
`Joined ${new Intl.DateTimeFormat('en-US', { month: 'long', year: 'numeric' }).format(new Date(isoDate))}`;
const UserProfile = ({ loaderData }: Route.ComponentProps) => {
const { profile, isOwnProfile } = loaderData;
interface ProfileContentProps {
profile: PublicUserProfile;
isOwnProfile: boolean;
}
/**
* Owns the profile-scoped interactive state. Keyed by `profile.userAccountId` in the
* parent so React remounts it (resetting follow/tab state) when the route's `:id` changes,
* since React Router reuses the route component itself across param-only navigations.
*/
const ProfileContent = ({ profile, isOwnProfile }: ProfileContentProps) => {
const [activeTab, setActiveTab] = useState<ProfileTab>('activity');
const [isFollowingProfile, setIsFollowingProfile] = useState(false);
const [following, setFollowing] = useState(() =>
@@ -91,17 +99,21 @@ const UserProfile = ({ loaderData }: Route.ComponentProps) => {
/>
</div>
<div className="flex flex-col gap-5 mt-12">
<ProfileTabs activeTab={activeTab} onChange={setActiveTab} />
{activeTab === 'activity' && <ActivityTab activity={FILLER_ACTIVITY} />}
{activeTab === 'following' && (
<FollowingTab
following={following}
onToggleFollow={handleToggleFollowRow}
/>
)}
{activeTab === 'liked' && <LikedTab liked={FILLER_LIKED} />}
<div className="mt-12">
<ProfileTabs
activeTab={activeTab}
onChange={setActiveTab}
panels={{
activity: <ActivityTab activity={FILLER_ACTIVITY} />,
following: (
<FollowingTab
following={following}
onToggleFollow={handleToggleFollowRow}
/>
),
liked: <LikedTab liked={FILLER_LIKED} />,
}}
/>
</div>
</div>
</div>
@@ -109,6 +121,18 @@ const UserProfile = ({ loaderData }: Route.ComponentProps) => {
);
};
const UserProfile = ({ loaderData }: Route.ComponentProps) => {
const { profile, isOwnProfile } = loaderData;
return (
<ProfileContent
key={profile.userAccountId}
profile={profile}
isOwnProfile={isOwnProfile}
/>
);
};
export default UserProfile;
export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => (

View File

@@ -11,15 +11,17 @@ export interface PublicUserProfile {
}
/**
* Fetches the public-facing slice of a user account. `GET /api/user/{id}` also returns
* `email` and `dateOfBirth`, but those stay out of anything rendered on a public profile.
* Fetches the public-facing slice of a user account from the dedicated public-profile
* endpoint, which never includes `email` or `dateOfBirth`.
*/
export const getPublicUserProfile = async (
userAccountId: string,
): Promise<PublicUserProfile | null> => {
let res: Response;
try {
res = await fetch(`${API_BASE_URL}/api/user/${encodeURIComponent(userAccountId)}`);
res = await fetch(
`${API_BASE_URL}/api/user/${encodeURIComponent(userAccountId)}/profile`,
);
} catch {
throw data('The user service is unreachable right now. Please try again in a moment.', {
status: 503,

View File

@@ -77,11 +77,13 @@ export interface FillerFollowing {
userAccountId?: string;
}
// `userAccountId` is left unset for rows below since no backend account backs them yet;
// FollowingTab only links a row once a real account GUID is available (see USER_PROFILE_HANDOFF.md).
export const FILLER_FOLLOWING: FillerFollowing[] = [
{ id: '1', name: 'Breakside Brewery', meta: 'Portland, OR · Brewery' },
{ id: '2', name: 'Jonah Weckstein', meta: '@jweck · 142 ratings', userAccountId: 'jweck' },
{ id: '2', name: 'Jonah Weckstein', meta: '@jweck · 142 ratings' },
{ id: '3', name: 'Wayfinder Beer', meta: 'Portland, OR · Brewery' },
{ id: '4', name: 'Casey Blume', meta: '@caseyb · 88 ratings', userAccountId: 'caseyb' },
{ id: '4', name: 'Casey Blume', meta: '@caseyb · 88 ratings' },
];
export interface FillerLiked {