@playpilot/tpi 8.29.0-beta.8 → 8.29.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.29.0-beta.8",
3
+ "version": "8.29.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -28,13 +28,7 @@ export async function fetchParticipantsForTitle(title: TitleData): Promise<Parti
28
28
  }
29
29
 
30
30
  export async function fetchParticipantBySid(sid: string): Promise<ParticipantData> {
31
- await new Promise(res => setTimeout(res, 200))
32
-
33
- return participants[0]
34
-
35
- const data = await api<{ results: ParticipantData[] }>(`/participants/browse?api-token=${getApiToken()}&sids=${sid}`)
36
-
37
- const participant = data.results[0]
31
+ const participant = await api<ParticipantData>(`/participants/${sid}?api-token=${getApiToken()}`)
38
32
 
39
33
  if (!participant) throw new Error('No participant was returned for sid: ' + sid)
40
34
 
@@ -9,6 +9,9 @@
9
9
  import ExploreLayout from './ExploreLayout.svelte'
10
10
  import ExploreTitle from './Routes/ExploreTitle.svelte'
11
11
  import ExploreModal from './Routes/ExploreModal.svelte'
12
+ import { setContext } from 'svelte'
13
+
14
+ setContext('navigate', navigate)
12
15
 
13
16
  const routes: ExploreRoute[] = [
14
17
  {
@@ -1,106 +1,106 @@
1
- <script lang="ts">
2
- import { fetchParticipantBySid } from '$lib/api/participants'
3
- import { fetchSimilarTitles, fetchTitleBySid } from '$lib/api/titles'
4
- import { mobileBreakpoint } from '$lib/constants'
5
- import { SplitTest } from '$lib/enums/SplitTest'
6
- import { t } from '$lib/localization'
7
- import { openModal, type ModalType } from '$lib/modal'
8
- import { getSplitTestVariantName, trackSplitTestView } from '$lib/splitTest'
9
- import type { TitleData } from '$lib/types/title'
10
- import Modal from '../../Modals/Modal.svelte'
11
-
12
- interface Props {
13
- navigate?: (key: string, pushState?: boolean) => void
14
- }
15
-
16
- const { navigate = () => null }: Props = $props()
17
-
18
- async function openModalViaRoute(): Promise<void> {
19
- const currentUrl = new URL(document.location.toString())
20
- const sid = currentUrl.searchParams.get('sid')
21
-
22
- if (!sid) return
23
-
24
- let type: ModalType = sid.startsWith('pr') ? 'participant' : 'title' // Sids with with `pr` for participants, `ti` for titles
25
- let data: any = null
26
-
27
- if (type === 'title') {
28
- const isMobile = window.innerWidth < mobileBreakpoint
29
- const isInReelSplitTest = isMobile && getSplitTestVariantName(SplitTest.Reels) === 'Reel'
30
-
31
- if (isMobile) trackSplitTestView(SplitTest.Reels)
32
-
33
- type = isMobile && isInReelSplitTest ? 'titles-reel' : 'titles-rail'
34
-
35
- const [title, railTitles] = (await Promise.allSettled([fetchTitleBySid(sid), fetchSimilarTitles({ sid } as unknown as TitleData)])).map((promise) => promise.status === 'fulfilled' ? promise.value : null)
36
-
37
- data = [title as TitleData, ...(railTitles as TitleData[])]
38
- } else if (type === 'participant') {
39
- data = await fetchParticipantBySid(sid)
40
- }
41
-
42
- openModal({
43
- type,
44
- data,
45
- props: {
46
- onclose: () => navigate('home'),
47
- pushState: false,
48
- },
49
- })
50
- }
51
- </script>
52
-
53
- {#await openModalViaRoute()}
54
- <Modal blur pushState={false}>
55
- {#snippet dialog()}
56
- <div class="loading">
57
- <div class="bar"></div>
58
- <div class="bar"></div>
59
- <div class="bar"></div>
60
- </div>
61
- {/snippet}
62
- </Modal>
63
- {:catch}
64
- <Modal blur onclose={() => navigate('home')} pushState={false}>
65
- <div class="error">
66
- {t('An Error Occurred')}
67
- </div>
68
- </Modal>
69
- {/await}
70
-
71
- <style lang="scss">
72
- .loading {
73
- display: flex;
74
- align-items: center;
75
- justify-content: center;
76
- height: 100%;
77
- gap: margin(0.5);
78
- }
79
-
80
- @keyframes animate-bar {
81
- to {
82
- height: margin(3);
83
- opacity: 0.5;
84
- }
85
- }
86
-
87
- .bar {
88
- height: margin(4);
89
- width: margin(1);
90
- border-radius: margin(0.25);
91
- background: white;
92
- animation: animate-bar 750ms infinite;
93
-
94
- @for $i from 0 through 2 {
95
- &:nth-child(#{$i}) {
96
- animation-delay: $i * 250ms;
97
- }
98
- }
99
- }
100
-
101
- .error {
102
- padding: margin(2);
103
- font-size: 1.25em;
104
- color: theme(text-color);
105
- }
106
- </style>
1
+ <script lang="ts">
2
+ import { fetchParticipantBySid } from '$lib/api/participants'
3
+ import { fetchSimilarTitles, fetchTitleBySid } from '$lib/api/titles'
4
+ import { mobileBreakpoint } from '$lib/constants'
5
+ import { SplitTest } from '$lib/enums/SplitTest'
6
+ import { t } from '$lib/localization'
7
+ import { openModal, type ModalType } from '$lib/modal'
8
+ import { getSplitTestVariantName, trackSplitTestView } from '$lib/splitTest'
9
+ import type { TitleData } from '$lib/types/title'
10
+ import Modal from '../../Modals/Modal.svelte'
11
+
12
+ interface Props {
13
+ navigate?: (key: string, pushState?: boolean) => void
14
+ }
15
+
16
+ const { navigate = () => null }: Props = $props()
17
+
18
+ async function openModalViaRoute(): Promise<void> {
19
+ const currentUrl = new URL(document.location.toString())
20
+ const sid = currentUrl.searchParams.get('sid')
21
+
22
+ if (!sid) return
23
+
24
+ let type: ModalType = sid.startsWith('pr') ? 'participant' : 'title' // Sids with with `pr` for participants, `ti` for titles
25
+ let data: any = null
26
+
27
+ if (type === 'title') {
28
+ const isMobile = window.innerWidth < mobileBreakpoint
29
+ const isInReelSplitTest = isMobile && getSplitTestVariantName(SplitTest.Reels) === 'Reel'
30
+
31
+ if (isMobile) trackSplitTestView(SplitTest.Reels)
32
+
33
+ type = isMobile && isInReelSplitTest ? 'titles-reel' : 'titles-rail'
34
+
35
+ const [title, railTitles] = (await Promise.allSettled([fetchTitleBySid(sid), fetchSimilarTitles({ sid } as unknown as TitleData)])).map((promise) => promise.status === 'fulfilled' ? promise.value : null)
36
+
37
+ data = [title as TitleData, ...(railTitles as TitleData[])]
38
+ } else if (type === 'participant') {
39
+ data = await fetchParticipantBySid(sid)
40
+ }
41
+
42
+ openModal({
43
+ type,
44
+ data,
45
+ props: {
46
+ onclose: () => navigate('home'),
47
+ pushState: false,
48
+ },
49
+ })
50
+ }
51
+ </script>
52
+
53
+ {#await openModalViaRoute()}
54
+ <Modal blur pushState={false}>
55
+ {#snippet dialog()}
56
+ <div class="loading">
57
+ <div class="bar"></div>
58
+ <div class="bar"></div>
59
+ <div class="bar"></div>
60
+ </div>
61
+ {/snippet}
62
+ </Modal>
63
+ {:catch}
64
+ <Modal blur onclose={() => navigate('home')} pushState={false}>
65
+ <div class="error">
66
+ {t('An Error Occurred')}
67
+ </div>
68
+ </Modal>
69
+ {/await}
70
+
71
+ <style lang="scss">
72
+ .loading {
73
+ display: flex;
74
+ align-items: center;
75
+ justify-content: center;
76
+ height: 100%;
77
+ gap: margin(0.5);
78
+ }
79
+
80
+ @keyframes animate-bar {
81
+ to {
82
+ height: margin(3);
83
+ opacity: 0.5;
84
+ }
85
+ }
86
+
87
+ .bar {
88
+ height: margin(4);
89
+ width: margin(1);
90
+ border-radius: margin(0.25);
91
+ background: white;
92
+ animation: animate-bar 750ms infinite;
93
+
94
+ @for $i from 0 through 2 {
95
+ &:nth-child(#{$i}) {
96
+ animation-delay: $i * 250ms;
97
+ }
98
+ }
99
+ }
100
+
101
+ .error {
102
+ padding: margin(2);
103
+ font-size: 1.25em;
104
+ color: theme(text-color);
105
+ }
106
+ </style>
@@ -8,8 +8,10 @@
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 { getContext } from 'svelte'
11
12
  import ParticipantImage from '../Participants/ParticipantImage.svelte'
12
13
  import Rail from './Rail.svelte'
14
+ import { exploreModalUrl } from '$lib/routes'
13
15
 
14
16
  interface Props {
15
17
  title: TitleData
@@ -18,6 +20,8 @@
18
20
 
19
21
  const { title, heading = t('Cast') }: Props = $props()
20
22
 
23
+ const navigate: Function | undefined = getContext('navigate')
24
+
21
25
  /**
22
26
  * Order participants by how often their name appears in an the page text. This only takes into account
23
27
  * their full name. If an actor is mentioned by first name only, which is often the case, they won't get
@@ -42,8 +46,22 @@
42
46
  }
43
47
 
44
48
  function onclick(event: MouseEvent, participant: ParticipantData): void {
45
- openModal({ event, type: 'participant', data: participant })
46
49
  track(TrackingEvent.ParticipantClick, null, { title_source: title.original_title || title.title, participant: participant.name })
50
+
51
+ if (!window.PlayPilotLinkInjections?.config?.open_tpi_links_in_explore) {
52
+ openModal({ event, type: 'participant', data: participant })
53
+ return
54
+ }
55
+
56
+ const url = exploreModalUrl(participant.sid)
57
+
58
+ if (navigate) {
59
+ window.history.pushState({}, '', url)
60
+ navigate('modal')
61
+ return
62
+ }
63
+
64
+ window.location.href = url
47
65
  }
48
66
  </script>
49
67
 
@@ -1,98 +1,122 @@
1
- import { fireEvent, render, waitFor } from '@testing-library/svelte'
2
- import { describe, expect, it, vi, beforeEach } from 'vitest'
3
-
4
- import ParticipantsRail from '../../../../routes/components/Rails/ParticipantsRail.svelte'
5
- import { openModal } from '$lib/modal'
6
- import { participants, title } from '$lib/fakeData'
7
- import { track } from '$lib/tracking'
8
- import { TrackingEvent } from '$lib/enums/TrackingEvent'
9
- import { fetchParticipantsForTitle } from '$lib/api/participants'
10
-
11
- vi.mock('$lib/modal', () => ({
12
- openModal: vi.fn(),
13
- }))
14
-
15
- vi.mock('$lib/tracking', () => ({
16
- track: vi.fn(),
17
- }))
18
-
19
- vi.mock('$lib/api/participants', () => ({
20
- fetchParticipantsForTitle: vi.fn(),
21
- }))
22
-
23
- describe('ParticipantsRail.svelte', () => {
24
- beforeEach(() => {
25
- document.body.innerHTML = ''
26
- })
27
-
28
- it('Should render each given participant', async () => {
29
- vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
30
-
31
- const { getByText } = render(ParticipantsRail, { title })
32
-
33
- await waitFor(() => {
34
- expect(getByText(participants[0].name)).toBeTruthy()
35
- expect(getByText(participants[1].name)).toBeTruthy()
36
- })
37
- })
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
-
52
- it('Should order participants by their number of occurrences on the page', async () => {
53
- document.body.innerHTML = `<main>${participants[1].name}. ${participants[2].name}, ${participants[2].name}</main>`
54
- vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
55
-
56
- const { getAllByTestId } = render(ParticipantsRail, { title })
57
-
58
- await waitFor(() => {
59
- expect(getAllByTestId('participant')[0].innerText).toContain(participants[2].name)
60
- expect(getAllByTestId('participant')[1].innerText).toContain(participants[1].name)
61
- expect(getAllByTestId('participant')[2].innerText).toContain(participants[0].name)
62
- })
63
- })
64
-
65
- it('Should not render when no participants are returned', async () => {
66
- vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce([])
67
-
68
- const { container } = render(ParticipantsRail)
69
-
70
- await waitFor(() => {
71
- expect(container.querySelectorAll('.participant').length).toBe(0)
72
- })
73
- })
74
-
75
- it('Should open modal on click of participant', async () => {
76
- vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
77
-
78
- const { getAllByTestId } = render(ParticipantsRail, { title })
79
-
80
- await waitFor(async () => {
81
- await fireEvent.click(getAllByTestId('participant')[0])
82
- })
83
-
84
- expect(openModal).toHaveBeenCalledWith({ event: expect.any(Object), type: 'participant', data: participants[0] })
85
- })
86
-
87
- it('Should fire track event on click of participant', async () => {
88
- vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
89
-
90
- const { getAllByTestId } = render(ParticipantsRail, { title })
91
-
92
- await waitFor(async () => {
93
- await fireEvent.click(getAllByTestId('participant')[0])
94
- })
95
-
96
- expect(track).toHaveBeenCalledWith(TrackingEvent.ParticipantClick, null, { title_source: title.original_title, participant: participants[0].name })
97
- })
98
- })
1
+ import { fireEvent, render, waitFor } from '@testing-library/svelte'
2
+ import { describe, expect, it, vi, beforeEach } from 'vitest'
3
+
4
+ import ParticipantsRail from '../../../../routes/components/Rails/ParticipantsRail.svelte'
5
+ import { openModal } from '$lib/modal'
6
+ import { participants, title } from '$lib/fakeData'
7
+ import { track } from '$lib/tracking'
8
+ import { TrackingEvent } from '$lib/enums/TrackingEvent'
9
+ import { fetchParticipantsForTitle } from '$lib/api/participants'
10
+
11
+ vi.mock('$lib/modal', () => ({
12
+ openModal: vi.fn(),
13
+ }))
14
+
15
+ vi.mock('$lib/tracking', () => ({
16
+ track: vi.fn(),
17
+ }))
18
+
19
+ vi.mock('$lib/api/participants', () => ({
20
+ fetchParticipantsForTitle: vi.fn(),
21
+ }))
22
+
23
+ describe('ParticipantsRail.svelte', () => {
24
+ beforeEach(() => {
25
+ vi.resetAllMocks()
26
+
27
+ // @ts-ignore
28
+ window.PlayPilotLinkInjections = {}
29
+ document.body.innerHTML = ''
30
+ })
31
+
32
+ it('Should render each given participant', async () => {
33
+ vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
34
+
35
+ const { getByText } = render(ParticipantsRail, { title })
36
+
37
+ await waitFor(() => {
38
+ expect(getByText(participants[0].name)).toBeTruthy()
39
+ expect(getByText(participants[1].name)).toBeTruthy()
40
+ })
41
+ })
42
+
43
+ it('Should render image only for participants with image', async () => {
44
+ const participantsWithImage = [...participants]
45
+ participantsWithImage[0].image = 'some-image.jpg'
46
+
47
+ vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participantsWithImage)
48
+
49
+ const { getAllByRole } = render(ParticipantsRail, { title })
50
+
51
+ await waitFor(() => {
52
+ expect(getAllByRole('presentation')).toHaveLength(1)
53
+ })
54
+ })
55
+
56
+ it('Should order participants by their number of occurrences on the page', async () => {
57
+ document.body.innerHTML = `<main>${participants[1].name}. ${participants[2].name}, ${participants[2].name}</main>`
58
+ vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
59
+
60
+ const { getAllByTestId } = render(ParticipantsRail, { title })
61
+
62
+ await waitFor(() => {
63
+ expect(getAllByTestId('participant')[0].innerText).toContain(participants[2].name)
64
+ expect(getAllByTestId('participant')[1].innerText).toContain(participants[1].name)
65
+ expect(getAllByTestId('participant')[2].innerText).toContain(participants[0].name)
66
+ })
67
+ })
68
+
69
+ it('Should not render when no participants are returned', async () => {
70
+ vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce([])
71
+
72
+ const { container } = render(ParticipantsRail)
73
+
74
+ await waitFor(() => {
75
+ expect(container.querySelectorAll('.participant').length).toBe(0)
76
+ })
77
+ })
78
+
79
+ it('Should open modal on click of participant', async () => {
80
+ vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
81
+
82
+ const { getAllByTestId } = render(ParticipantsRail, { title })
83
+
84
+ await waitFor(async () => {
85
+ await fireEvent.click(getAllByTestId('participant')[0])
86
+ })
87
+
88
+ expect(openModal).toHaveBeenCalledWith({ event: expect.any(Object), type: 'participant', data: participants[0] })
89
+ })
90
+
91
+ it('Should not open modal on click if if open_tpi_links_in_explore is true and instead set url', async () => {
92
+ // @ts-ignore
93
+ window.PlayPilotLinkInjections = {
94
+ config: {
95
+ open_tpi_links_in_explore: true,
96
+ },
97
+ }
98
+
99
+ vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
100
+
101
+ const { getAllByTestId } = render(ParticipantsRail, { title })
102
+
103
+ await waitFor(async () => {
104
+ await fireEvent.click(getAllByTestId('participant')[0])
105
+ })
106
+
107
+ expect(openModal).not.toHaveBeenCalled()
108
+ expect(window.location.href).toContain(participants[0].sid)
109
+ })
110
+
111
+ it('Should fire track event on click of participant', async () => {
112
+ vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
113
+
114
+ const { getAllByTestId } = render(ParticipantsRail, { title })
115
+
116
+ await waitFor(async () => {
117
+ await fireEvent.click(getAllByTestId('participant')[0])
118
+ })
119
+
120
+ expect(track).toHaveBeenCalledWith(TrackingEvent.ParticipantClick, null, { title_source: title.original_title, participant: participants[0].name })
121
+ })
122
+ })