All files / src/components IgShareCard.vue

100% Statements 110/110
90.47% Branches 19/21
100% Functions 6/6
100% Lines 110/110

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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 1341x 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 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 1x 219x 219x 219x 219x 219x   219x 223x 219x 219x 219x 219x 219x 10x 10x 10x 219x   219x 219x 219x   219x 229x 219x 219x 14x 219x 219x 1x 1x    
<template>
  <!--
    SB-32 share-card dispatcher. Renders the chosen template at exact
    1080×1080. Exposes a `root` ref that points at the inner template's
    root <div> so html2canvas can capture pixel-perfect output.
  -->
  <component
    :is="currentTemplate"
    ref="inner"
    :match="match"
    :photo-src="photoSrc"
    :photo-is-cross-origin="photoIsCrossOrigin"
    :events="events"
    :mode="mode"
    :accent-preference="accentPreference"
    :blurb="blurb"
    :week-number="weekNumber"
    :matchup="template === 'fest' ? matchup : null"
    :schedule="isSchedule ? schedule : null"
    :format="isSchedule ? scheduleFormat : null"
  />
</template>
 
<script>
import { computed, ref, watch } from 'vue';
import IgOverlay from './ig/IgOverlay.vue';
import IgSplit from './ig/IgSplit.vue';
import IgTournamentRound from './ig/IgTournamentRound.vue';
import IgStadium from './ig/IgStadium.vue';
import IgMotw from './ig/IgMotw.vue';
import IgFest from './ig/IgFest.vue';
import IgFestPhoto from './ig/IgFestPhoto.vue';
import IgFestPost from './ig/IgFestPost.vue';
import IgFestSchedule from './ig/IgFestSchedule.vue';
 
const TEMPLATE_COMPONENTS = {
  overlay: IgOverlay,
  split: IgSplit,
  'tournament-round': IgTournamentRound,
  stadium: IgStadium,
  // SB-1010. Listed last so it is the rightmost option in the picker, and
  // only auto-selected when the share was launched from the MOTW strip.
  motw: IgMotw,
  // SB-1883. 1080×1920 Story, offered only for MLS NEXT Fest matches.
  fest: IgFest,
  // SB-1893. The rest of the Fest family: a photo Story and a square post.
  'fest-photo': IgFestPhoto,
  'fest-post': IgFestPost,
  'fest-schedule': IgFestSchedule,
  'fest-schedule-story': IgFestSchedule,
};
 
export const SHARE_CARD_TEMPLATES = Object.keys(TEMPLATE_COMPONENTS);
 
export default {
  name: 'IgShareCard',
  components: {
    IgOverlay,
    IgSplit,
    IgTournamentRound,
    IgStadium,
    IgMotw,
    IgFest,
    IgFestPhoto,
    IgFestPost,
    IgFestSchedule,
  },
  props: {
    match: { type: Object, required: true },
    photoSrc: { type: String, default: null },
    photoIsCrossOrigin: { type: Boolean, default: false },
    events: { type: Array, default: () => [] },
    mode: {
      type: String,
      required: true,
      validator: v => ['preview', 'result'].includes(v),
    },
    template: {
      type: String,
      default: 'overlay',
      validator: v => SHARE_CARD_TEMPLATES.includes(v),
    },
    // SB-659: which team's colors drive the accent. 'auto' keeps the
    // home-then-away-then-MT resolution.
    accentPreference: {
      type: String,
      default: 'auto',
      validator: v => ['auto', 'home', 'away', 'mt'].includes(v),
    },
    // The MOTW editorial line. Only the motw template renders it; the others
    // ignore it, which is why it rides as a prop rather than forcing every
    // template to know about the feature.
    blurb: { type: String, default: null },
    weekNumber: { type: Number, default: null },
    // SB-1883: GET /api/matches/{id}/matchup, for the fest template's stat
    // panels. Null while loading or when it failed.
    matchup: { type: Object, default: null },
    // SB-1917: the Fest Team Schedule data, built by the share modal.
    schedule: { type: Object, default: null },
  },
  setup(props) {
    const inner = ref(null);
    // `root` mirrors the inner template's root <div>. The IgShareModal
    // grabs this for html2canvas. Re-evaluated whenever the template
    // changes (component swap unmounts the old, mounts the new).
    const root = ref(null);
 
    const updateRoot = () => {
      root.value = inner.value?.root || null;
    };
    watch(inner, updateRoot, { flush: 'post' });
    watch(
      () => props.template,
      () => {
        // After Vue swaps the component, the new ref isn't bound yet —
        // wait a tick for the post-flush watcher above to fire.
      }
    );
 
    const currentTemplate = computed(
      () => TEMPLATE_COMPONENTS[props.template] || IgOverlay
    );
 
    const isSchedule = computed(() =>
      props.template.startsWith('fest-schedule')
    );
    const scheduleFormat = computed(() =>
      props.template === 'fest-schedule-story' ? 'story' : 'post'
    );
    return { inner, root, currentTemplate, isSchedule, scheduleFormat };
  },
};
</script>