@playpilot/tpi 8.24.0 → 8.25.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playpilot/tpi",
3
- "version": "8.24.0",
3
+ "version": "8.25.0-beta.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -10,7 +10,7 @@
10
10
  import { trackViaPixel } from '@playpilot/retargeting-tracking'
11
11
  import Popover from './Popover.svelte'
12
12
  import Title from './Title.svelte'
13
- import Participant from './Participant.svelte'
13
+ import Participant from './Participants/Participant.svelte'
14
14
  import TopScroll from './Ads/TopScroll.svelte'
15
15
  import Display from './Ads/Display.svelte'
16
16
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  <script lang="ts">
3
3
  import Modal from './Modal.svelte'
4
- import Participant from '../Participant.svelte'
4
+ import Participant from '../Participants/Participant.svelte'
5
5
  import type { ParticipantData } from '$lib/types/participant'
6
6
  import { TrackingEvent } from '$lib/enums/TrackingEvent'
7
7
  import { track } from '$lib/tracking'
@@ -5,11 +5,12 @@
5
5
  import { openModal } from '$lib/modal'
6
6
  import type { ParticipantData } from '$lib/types/participant'
7
7
  import type { TitleData } from '$lib/types/title'
8
- import ListTitle from './ListTitle.svelte'
9
8
  import { t } from '$lib/localization'
10
9
  import { hasConsentedTo } from '$lib/consent'
11
10
  import { trackViaPixel } from '@playpilot/retargeting-tracking'
12
11
  import { MetaEvent } from '$lib/enums/TrackingEvent'
12
+ import ParticipantImage from './ParticipantImage.svelte'
13
+ import ListTitle from '../ListTitle.svelte'
13
14
 
14
15
  interface Props {
15
16
  participant: ParticipantData
@@ -54,13 +55,17 @@
54
55
  </script>
55
56
 
56
57
  <div class="header" class:small>
57
- <div class="heading" use:heading={2} id="heading">{name}</div>
58
+ <ParticipantImage {participant} />
58
59
 
59
- {#if birth_date}
60
- <p class="dates">
61
- {t('Born On')} <strong>{formatDate(birth_date)}</strong>{#if death_date}, {t('Died On')} <strong>{formatDate(death_date)}</strong>{/if}
62
- </p>
63
- {/if}
60
+ <div>
61
+ <div class="heading" use:heading={2} id="heading">{name}</div>
62
+
63
+ {#if birth_date}
64
+ <p class="dates">
65
+ {t('Born On')} <strong>{formatDate(birth_date)}</strong>{#if death_date}, {t('Died On')} <strong>{formatDate(death_date)}</strong>{/if}
66
+ </p>
67
+ {/if}
68
+ </div>
64
69
  </div>
65
70
 
66
71
  <div class="content">
@@ -85,13 +90,22 @@
85
90
 
86
91
  <style lang="scss">
87
92
  .header {
88
- padding: margin(4) margin(1) margin(2);
93
+ --participant-image-size: #{margin(6)};
94
+ display: grid;
95
+ grid-template-columns: calc(var(--participant-image-size)) auto;
96
+ align-items: center;
97
+ gap: margin(1);
98
+ padding: margin(3) margin(1) margin(2);
89
99
  font-family: theme(detail-font-family, font-family);
90
100
  font-weight: theme(detail-font-weight, normal);
91
101
  font-size: theme(detail-font-size, font-size-base);
92
102
  line-height: theme(participant-description-line-height, normal);
93
103
  color: theme(detail-text-color, text-color);
94
104
 
105
+ @include desktop {
106
+ --participant-image-size: #{margin(8)};
107
+ }
108
+
95
109
  &.small {
96
110
  padding: margin(1);
97
111
  }
@@ -101,7 +115,7 @@
101
115
  margin: 0;
102
116
  font-family: theme(detail-title-font-family, font-family);
103
117
  font-weight: theme(detail-title-font-weight, lighter);
104
- font-size: theme(detail-title-font-size, margin(1.5));
118
+ font-size: clamp(1.25em, 5vw, 1.5em);
105
119
  line-height: normal;
106
120
  font-style: theme(detail-title-font-style, normal);
107
121
 
@@ -109,6 +123,10 @@
109
123
  margin: 0 0 margin(0.5);
110
124
  font-size: theme(detail-title-small-font-size, margin(1.25));
111
125
  }
126
+
127
+ .small & {
128
+ font-size: 1em;
129
+ }
112
130
  }
113
131
 
114
132
  .dates {
@@ -0,0 +1,56 @@
1
+ <script lang="ts">
2
+ import type { ParticipantData } from '$lib/types/participant'
3
+
4
+ interface Props {
5
+ participant?: ParticipantData | null
6
+ }
7
+
8
+ const { participant = null }: Props = $props()
9
+ </script>
10
+
11
+ <div class="image">
12
+ {#if participant?.image}
13
+ <img loading="lazy" src={participant.image} alt="" />
14
+ {/if}
15
+ </div>
16
+
17
+ <style lang="scss">
18
+ $item-width: #{var(--participant-image-size, margin(6))};
19
+
20
+ .image {
21
+ position: relative;
22
+ display: block;
23
+ width: $item-width;
24
+ height: $item-width;
25
+ border-radius: 50%;
26
+ overflow: hidden;
27
+ background: theme(cast-background, lighter);
28
+
29
+ &::before,
30
+ &::after {
31
+ content: "";
32
+ display: block;
33
+ position: absolute;
34
+ width: 50%;
35
+ height: 50%;
36
+ top: 50%;
37
+ left: 50%;
38
+ border-radius: 50%;
39
+ transform: translateX(-50%) translateY(-50%);
40
+ background: currentColor;
41
+ opacity: 0.1;
42
+ }
43
+
44
+ &::after {
45
+ top: 100%;
46
+ width: 75%;
47
+ }
48
+
49
+ img {
50
+ z-index: 1;
51
+ position: relative;
52
+ width: 100%;
53
+ height: auto;
54
+ }
55
+ }
56
+ </style>
@@ -8,6 +8,7 @@
8
8
  import { track } from '$lib/tracking'
9
9
  import type { ParticipantData } from '$lib/types/participant'
10
10
  import type { TitleData } from '$lib/types/title'
11
+ import ParticipantImage from '../Participants/ParticipantImage.svelte'
11
12
  import Rail from './Rail.svelte'
12
13
 
13
14
  interface Props {
@@ -35,8 +36,6 @@
35
36
  participantsByOccurrence[participant.sid] = { participant, count }
36
37
  }
37
38
 
38
- // Sort all participants by their occurrences. If a participant did not occur their positioned will be retained
39
- // relative to where it was before
40
39
  const participantsSortedByCount = Object.values(participantsByOccurrence).sort((a, b) => b.count - a.count)
41
40
 
42
41
  return participantsSortedByCount.map(({ participant }) => participant)
@@ -51,7 +50,10 @@
51
50
  {#await fetchParticipantsForTitle(title)}
52
51
  <Rail {heading}>
53
52
  {#each { length: 5 }}
54
- <div class="participant"></div>
53
+ <div class="participant">
54
+ <ParticipantImage />
55
+ <div class="name"></div>
56
+ </div>
55
57
  {/each}
56
58
  </Rail>
57
59
  {:then participants}
@@ -59,11 +61,9 @@
59
61
  <Rail {heading}>
60
62
  {#each orderParticipantsByPageTextOccurrence(participants).slice(0, 15) as participant}
61
63
  <button class="participant" data-testid="participant" onclick={event => onclick(event, participant)}>
62
- <span class="truncate">{participant.name}</span>
64
+ <ParticipantImage {participant} />
63
65
 
64
- {#if participant.character}
65
- <div class="character truncate">{participant.character}</div>
66
- {/if}
66
+ <div class="name">{participant.name}</div>
67
67
  </button>
68
68
  {/each}
69
69
  </Rail>
@@ -71,22 +71,25 @@
71
71
  {/await}
72
72
 
73
73
  <style lang="scss">
74
+ $item-width: #{theme(rail-size-default, margin(6))};
75
+
74
76
  .participant {
77
+ --participant-image-size: #{$item-width};
75
78
  display: flex;
76
79
  flex-direction: column;
77
- flex: 0 0 10rem;
78
- width: 10rem;
79
- min-height: margin(3.375); // Matches 54 pixels, the height of a card with both name and character
80
- padding: margin(0.5);
81
- border: theme(cast-border, 0);
80
+ flex: 0 0 $item-width;
81
+ gap: margin(0.5);
82
+ width: $item-width;
83
+ padding: 0;
82
84
  border-radius: theme(cast-border-radius, border-radius);
83
- background: theme(cast-background, lighter);
85
+ border: 0;
86
+ background: transparent;
84
87
  cursor: pointer;
85
- font-family: inherit;
86
- text-align: left;
87
88
  color: inherit;
89
+ font-family: inherit;
88
90
  font-size: theme(cast-font-size, font-size-small);
89
91
  line-height: normal;
92
+ text-align: center;
90
93
  white-space: nowrap;
91
94
 
92
95
  &:is(button):hover,
@@ -96,12 +99,7 @@
96
99
  }
97
100
  }
98
101
 
99
- .character {
100
- color: theme(cast-character-text-color, text-color-alt);
101
- font-style: italic;
102
- }
103
-
104
- .truncate {
102
+ .name {
105
103
  overflow: hidden;
106
104
  text-overflow: ellipsis;
107
105
  white-space: nowrap;
@@ -20,6 +20,7 @@
20
20
  import Tooltip from '../components/Tooltip.svelte'
21
21
  import ExploreRouter from '../components/Explore/ExploreRouter.svelte'
22
22
  import TitlesRail from '../components/Rails/TitlesRail.svelte'
23
+ import ParticipantsRail from '../components/Rails/ParticipantsRail.svelte'
23
24
 
24
25
  if (browser) {
25
26
  // @ts-ignore
@@ -125,6 +126,15 @@
125
126
  </div>
126
127
  </div>
127
128
 
129
+ <h2>Participants</h2>
130
+
131
+ <div class="group">
132
+ <div>
133
+ <h3>Participants.svelte</h3>
134
+ <div class="item"><ParticipantsRail {title} /></div>
135
+ </div>
136
+ </div>
137
+
128
138
  <h2>After article</h2>
129
139
 
130
140
  <div class="group">
@@ -1,7 +1,7 @@
1
1
  import { fireEvent, render, waitFor } from '@testing-library/svelte'
2
2
  import { describe, expect, it, vi, beforeEach } from 'vitest'
3
3
 
4
- import Participant from '../../../routes/components/Participant.svelte'
4
+ import Participant from '../../../../routes/components/Participants/Participant.svelte'
5
5
  import { participants, title } from '$lib/fakeData'
6
6
  import { fetchTitlesForParticipant } from '$lib/api/participants'
7
7
 
@@ -80,4 +80,23 @@ describe('Participant.svelte', () => {
80
80
  expect(queryByText('Credits')).not.toBeTruthy()
81
81
  expect(container.querySelector('.small')).toBeTruthy()
82
82
  })
83
+
84
+ it('Should render image if given', async () => {
85
+ const participantWithImage = { ...participants[0], image: 'some-image.jpg' }
86
+
87
+ const { getByRole } = render(Participant, { participant: participantWithImage })
88
+
89
+ await waitFor(() => {
90
+ expect(getByRole('presentation')).toBeTruthy()
91
+ })
92
+ })
93
+
94
+ it('Should not render image if not given', async () => {
95
+
96
+ const { queryByRole } = render(Participant, { participant: participants[0] })
97
+
98
+ await waitFor(() => {
99
+ expect(queryByRole('presentation')).not.toBeTruthy()
100
+ })
101
+ })
83
102
  })
@@ -36,6 +36,19 @@ describe('ParticipantsRail.svelte', () => {
36
36
  })
37
37
  })
38
38
 
39
+ it('Should render image only for participants with image', async () => {
40
+ const participantsWithImage = [...participants]
41
+ participantsWithImage[0].image = 'some-image.jpg'
42
+
43
+ vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participantsWithImage)
44
+
45
+ const { getAllByRole } = render(ParticipantsRail, { title })
46
+
47
+ await waitFor(() => {
48
+ expect(getAllByRole('presentation')).toHaveLength(1)
49
+ })
50
+ })
51
+
39
52
  it('Should order participants by their number of occurrences on the page', async () => {
40
53
  document.body.innerHTML = `<main>${participants[1].name}. ${participants[2].name}, ${participants[2].name}</main>`
41
54
  vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)