All files / src/components/ranking RankingView.vue

96.2% Statements 76/79
100% Branches 7/7
66.66% Functions 2/3
96.2% Lines 76/79

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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 1051x 1x       1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x             1x 1x 2x 2x 2x 2x 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 1x 1x 1x 1x   1x 1x 1x 1x   1x 5x 5x 5x 1x 1x 1x 1x 1x 1x 5x 1x 1x   1x 1x       1x    
<template>
  <!--
    The Ranking tab (SB-1785). Leaderboards first, then the Power Rating
    (SB-1809) for whoever canSeePowerRating allows. The sub-nav stays hidden
    while there is one entry.
  -->
  <div data-testid="ranking-view">
    <nav
      v-if="subTabs.length > 1"
      class="flex flex-wrap gap-2 mb-4"
      aria-label="Ranking views"
      data-testid="ranking-subnav"
    >
      <button
        v-for="tab in subTabs"
        :key="tab.id"
        type="button"
        @click="activeSubTab = tab.id"
        :class="[
          'px-4 py-2 text-sm rounded-lg font-medium transition-colors',
          activeSubTab === tab.id
            ? 'bg-brand-500 text-white shadow-sm'
            : 'bg-surface-alt text-fg-muted hover:bg-line',
        ]"
      >
        {{ tab.name }}
        <span
          v-if="tab.preview"
          class="ml-1 inline-block rounded px-1.5 py-0.5 align-[1px] text-[10px] font-semibold uppercase tracking-wide bg-accent-100 text-accent-800 dark:bg-accent-900/40 dark:text-accent-200"
          data-testid="power-rating-preview-chip"
          >Preview</span
        >
      </button>
    </nav>
    <!-- SB-1803: announce the Power Rating (SB-1784) before it ships. Wording
         promises only what the approved design commits to. It stays until
         the Power Rating is public; the preview sub-tab does not need it. -->
    <aside
      v-if="activeSubTab !== 'power-rating'"
      class="mb-4 rounded-lg border border-line bg-card px-3 py-2 text-sm text-fg"
      data-testid="power-rating-coming-soon"
    >
      <p>
        <span
          class="mr-1.5 inline-block rounded px-1.5 py-0.5 align-[1px] text-[10px] font-semibold uppercase tracking-wide bg-accent-100 text-accent-800 dark:bg-accent-900/40 dark:text-accent-200"
          >Coming soon</span
        >
        <strong class="font-semibold">Power Rating.</strong>
        One rating for every Homegrown team from U15 to U19, built from results
        and opponent strength. It appears once MLS NEXT Fest results connect the
        conferences.
      </p>
    </aside>
    <LeaderboardsPanel
      v-if="activeSubTab === 'leaderboards'"
      @navigate-to-team="$emit('navigate-to-team', $event)"
    />
    <PowerRatingPanel
      v-else-if="activeSubTab === 'power-rating'"
      @navigate-to-team="$emit('navigate-to-team', $event)"
    />
  </div>
</template>
 
<script setup>
import { computed, ref, watch } from 'vue';
import { useAuthStore } from '@/stores/auth';
import LeaderboardsPanel from './LeaderboardsPanel.vue';
import PowerRatingPanel from './PowerRatingPanel.vue';
 
defineEmits(['navigate-to-team']);
 
// Launch gate (SB-1809): the Power Rating waits for the Fest backtest
// (SB-1806). Until then only admins see it, marked Preview. Launching is
// this one line: set it to true and every viewer of the Ranking tab gets the
// sub-tab, without the chip.
const POWER_RATING_PUBLIC = false;
 
const authStore = useAuthStore();
const canSeePowerRating = computed(
  () => POWER_RATING_PUBLIC || Boolean(authStore.isAdmin?.value)
);
 
const subTabs = computed(() => [
  { id: 'leaderboards', name: 'Leaderboards' },
  ...(canSeePowerRating.value
    ? [
        {
          id: 'power-rating',
          name: 'Power Rating',
          preview: !POWER_RATING_PUBLIC,
        },
      ]
    : []),
]);
const activeSubTab = ref('leaderboards');
 
// Signing out of admin mid-view must not leave a hidden panel on screen.
watch(subTabs, tabs => {
  if (!tabs.some(t => t.id === activeSubTab.value)) {
    activeSubTab.value = tabs[0].id;
  }
});
</script>