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 ProfileSidebarCard from '../components/profile/ProfileSidebarCard'; import ProfileTabs, { type ProfileTab } from '../components/profile/ProfileTabs'; import ActivityTab from '../components/profile/tabs/ActivityTab'; import FollowingTab from '../components/profile/tabs/FollowingTab'; import LikedTab from '../components/profile/tabs/LikedTab'; import { FILLER_ACTIVITY, FILLER_FOLLOWING, FILLER_LIKED, FILLER_PROFILE_META, } from '../utils/filler-user-profile'; import type { Route } from './+types/user-profile'; export const meta = ({}: Route.MetaArgs) => [{ title: 'Profile | The Biergarten App' }]; export const loader = async ({ request, params }: Route.LoaderArgs) => { const [profile, auth] = await Promise.all([ getPublicUserProfile(params.id), getOptionalAuth(request), ]); if (!profile) { throw data('User not found.', { status: 404, statusText: 'Not Found' }); } return { profile, isOwnProfile: auth?.userAccountId === profile.userAccountId, }; }; 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; const [activeTab, setActiveTab] = useState('activity'); const [isFollowingProfile, setIsFollowingProfile] = useState(false); const [following, setFollowing] = useState(() => FILLER_FOLLOWING.map((f) => ({ ...f, isFollowing: true })), ); const handleToggleFollowRow = (id: string) => { setFollowing((prev) => prev.map((f) => (f.id === id ? { ...f, isFollowing: !f.isFollowing } : f)), ); }; const displayName = `${profile.firstName} ${profile.lastName}`.trim() || profile.username; const stats = [ { label: 'Following', value: FILLER_PROFILE_META.following }, { label: 'Followers', value: FILLER_PROFILE_META.followers }, { label: 'Breweries visited', value: FILLER_PROFILE_META.breweriesVisited }, { label: 'Ratings given', value: FILLER_PROFILE_META.ratingsGiven }, ]; return (
{displayName.slice(0, 2).toUpperCase()}
setIsFollowingProfile((prev) => !prev)} />
{activeTab === 'activity' && } {activeTab === 'following' && ( )} {activeTab === 'liked' && }
); }; export default UserProfile; export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => ( );