All files / src/views/profile PublicProfilePage.tsx

100% Statements 61/61
83.33% Branches 5/6
100% Functions 2/2
100% Lines 61/61

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 771x 1x 1x 1x 1x           1x   3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x   3x 1x 1x 1x 1x 1x 1x 1x   1x   3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x   1x 1x 1x   1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x 1x   1x  
import '@/styles/profile.css';
import { useParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { useAuth } from '@/contexts/AuthContext';
import {
  ProfileEquipmentSection,
  ProfilePublicEarnedBadgesSection,
  ProfilePublicHero,
  ProfileShowcaseSection,
} from './ProfilePublicSections';
import { usePublicProfileViewModel } from '../../viewmodels/profile/usePublicProfileViewModel';
 
export default function PublicProfilePage() {
  const { t } = useTranslation();
  const { token } = useAuth();
  const { userId } = useParams<{ userId: string }>();
  const {
    profile,
    isLoading,
    error,
    retry,
    earnedBadges,
    earnedBadgesLoading,
    earnedBadgesError,
    refreshEarnedBadges,
  } = usePublicProfileViewModel(userId, token);
 
  if (isLoading) {
    return (
      <div className="profile-container profile-container-wide">
        <div className="profile-public-state">
          <h1>{t('public_profile.title')}</h1>
          <p>{t('public_profile.loading')}</p>
        </div>
      </div>
    );
  }
 
  if (!profile) {
    return (
      <div className="profile-container profile-container-wide">
        <div className="profile-public-state">
          <h1>{t('public_profile.title')}</h1>
          <p>{error ?? t('public_profile.load_failed')}</p>
          <button type="button" className="save-btn profile-public-retry" onClick={() => void retry()}>
            {t('common.retry')}
          </button>
        </div>
      </div>
    );
  }
 
  return (
    <div className="profile-container profile-container-wide">
      <ProfilePublicHero profile={profile} eyebrow={t('public_profile.eyebrow')} />
 
      <ProfilePublicEarnedBadgesSection
        badges={earnedBadges}
        loading={earnedBadgesLoading}
        error={earnedBadgesError}
        onRetry={refreshEarnedBadges}
        viewerHasSession={Boolean(token)}
      />
 
      <ProfileEquipmentSection
        items={profile.equipment}
        emptyMessage={t('public_profile.equipment_empty_member')}
      />
 
      <ProfileShowcaseSection
        items={profile.showcase_images}
        emptyMessage={t('public_profile.showcase_empty_member')}
      />
    </div>
  );
}