@playpilot/tpi 8.34.4 → 8.35.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.
@@ -68,6 +68,7 @@ export const TrackingEvent = {
68
68
  RegionRequestFailed: 'ali_region_request_failed',
69
69
  YouTubeAvailabilityRequestFailed: 'ali_youtube_availability_request_failed',
70
70
  CardToExploreCta: 'ali_card_to_explore_cta',
71
+ TitleParticipantsView: 'ali_title_participants_view',
71
72
 
72
73
  // Explore
73
74
  // These deliberately do not use the `ali_` prefix. We might want to separate this from TPI at some point
@@ -1,148 +1,148 @@
1
- <script lang="ts">
2
- import type { ExploreFilter } from '$lib/types/filter'
3
- import genres from '$lib/data/genres.json'
4
- import { fetchProviders } from '$lib/api/providers'
5
- import { t } from '$lib/localization'
6
- import FilterItem from './FilterItem.svelte'
7
- import FilterSorting from './FilterSorting.svelte'
8
- import Button from '../../Button.svelte'
9
- import IconArrow from '../../Icons/IconArrow.svelte'
10
- import IconFilter from '../../Icons/IconFilter.svelte'
11
- import { fly, scale } from 'svelte/transition'
12
- import ActiveFilterItems from './ActiveFilterItems.svelte'
13
- import { isFilterItemActive } from '$lib/filter'
14
- import { cdnBaseUrl } from '$lib/constants'
15
-
16
- interface Props {
17
- filter: ExploreFilter
18
- limit?: boolean
19
- showSorting?: boolean
20
- searchQuery?: string
21
- onchange?: () => void
22
- onempty?: () => void
23
- }
24
-
25
- const {
26
- filter,
27
- limit = true,
28
- showSorting = true,
29
- searchQuery = '',
30
- onchange = () => null,
31
- onempty = () => null,
32
- }: Props = $props()
33
-
34
- const shownItemsLimit = 3
35
- const items = [{
36
- label: t('Services'),
37
- param: 'providers',
38
- fetchData: async () => (await fetchProviders()).map(playlink => ({ label: playlink.name, value: playlink.slug })),
39
- }, {
40
- label: t('Genres'),
41
- param: 'genres',
42
- data: genres.filter(genre => parseInt(genre.slug) < 900).map(genre => ({ label: t(genre.name), value: genre.slug })),
43
- }, {
44
- label: t('IMDb'),
45
- param: 'imdb_score',
46
- range: [0, 10] as [number, number],
47
- }, {
48
- label: t('Year'),
49
- param: 'year',
50
- range: [1900, new Date().getFullYear()] as [number, number],
51
- }, {
52
- label: t('Runtime'),
53
- param: 'length',
54
- range: [0, 180] as [number, number],
55
- valueAppend: t('Minutes'),
56
- }, {
57
- label: t('Countries'),
58
- param: 'country_codes',
59
- fetchData: async () => import.meta.env.DEV ?
60
- (await import('$lib/data/countries.json')).default :
61
- (await fetch(`${cdnBaseUrl}/src/lib/data/countries.json`)).json(),
62
- }, {
63
- label: t('Category'),
64
- param: 'category',
65
- data: [{ label: t('Movies'), value: 'movie' }, { label: t('Shows'), value: 'series' }, { label: t('Kids'), value: 'kids' }, { label: t('Documentary'), value: 'documentary' }],
66
- }]
67
-
68
- let limited = $state(limit)
69
- let wasPreviouslyActive = false
70
-
71
- $effect(() => {
72
- const hasAnyActiveFilter = Object.keys(filter).some((param) => {
73
- const { range } = items.find((i: any) => param === i.param) || {}
74
-
75
- return isFilterItemActive(filter[param], range)
76
- })
77
-
78
- if (hasAnyActiveFilter || searchQuery) {
79
- wasPreviouslyActive = true
80
- } else if (wasPreviouslyActive) {
81
- wasPreviouslyActive = false
82
- onempty()
83
- }
84
- })
85
- </script>
86
-
87
- <div class="filter" role="navigation" class:limit>
88
- <div class="items">
89
- {#each limited ? items.slice(0, shownItemsLimit) : items as item}
90
- <div transition:scale={{ start: 0.75, duration: 100 }}>
91
- <FilterItem {filter} {onchange} {...item} />
92
- </div>
93
- {/each}
94
- </div>
95
-
96
- <div class="actions">
97
- {#if limit}
98
- <Button variant="link" onclick={() => limited = !limited}>
99
- <IconFilter />
100
- {t('All Filters')}
101
- <IconArrow direction={limited ? 'down' : 'up'} />
102
- </Button>
103
- {/if}
104
-
105
- {#if showSorting}
106
- <div class="sorting" transition:fly={{ x: 5, duration: 100 }}>
107
- <FilterSorting {filter} {onchange} />
108
- </div>
109
- {/if}
110
- </div>
111
- </div>
112
-
113
- <ActiveFilterItems {filter} {items} />
114
-
115
- <style lang="scss">
116
- .filter {
117
- position: relative;
118
- }
119
-
120
- .items {
121
- display: flex;
122
- flex-wrap: wrap;
123
- gap: margin(0.5);
124
- padding-right: margin(7);
125
-
126
- .limit & {
127
- padding-right: 0;
128
- }
129
- }
130
-
131
- .actions {
132
- position: absolute;
133
- top: margin(0.25);
134
- right: 0;
135
-
136
- .limit & {
137
- position: initial;
138
- top: auto;
139
- display: flex;
140
- justify-content: space-between;
141
- margin-top: margin(0.5);
142
- }
143
- }
144
-
145
- .sorting {
146
- margin-top: margin(0.1);
147
- }
148
- </style>
1
+ <script lang="ts">
2
+ import type { ExploreFilter } from '$lib/types/filter'
3
+ import genres from '$lib/data/genres.json'
4
+ import { fetchProviders } from '$lib/api/providers'
5
+ import { t } from '$lib/localization'
6
+ import FilterItem from './FilterItem.svelte'
7
+ import FilterSorting from './FilterSorting.svelte'
8
+ import Button from '../../Button.svelte'
9
+ import IconArrow from '../../Icons/IconArrow.svelte'
10
+ import IconFilter from '../../Icons/IconFilter.svelte'
11
+ import { fly, scale } from 'svelte/transition'
12
+ import ActiveFilterItems from './ActiveFilterItems.svelte'
13
+ import { isFilterItemActive } from '$lib/filter'
14
+ import { cdnBaseUrl } from '$lib/constants'
15
+
16
+ interface Props {
17
+ filter: ExploreFilter
18
+ limit?: boolean
19
+ showSorting?: boolean
20
+ searchQuery?: string
21
+ onchange?: () => void
22
+ onempty?: () => void
23
+ }
24
+
25
+ const {
26
+ filter,
27
+ limit = true,
28
+ showSorting = true,
29
+ searchQuery = '',
30
+ onchange = () => null,
31
+ onempty = () => null,
32
+ }: Props = $props()
33
+
34
+ const shownItemsLimit = 3
35
+ const items = [{
36
+ label: t('Services'),
37
+ param: 'providers',
38
+ fetchData: async () => (await fetchProviders()).map(playlink => ({ label: playlink.name, value: playlink.slug })),
39
+ }, {
40
+ label: t('Genres'),
41
+ param: 'genres',
42
+ data: genres.filter(genre => parseInt(genre.slug) < 900).map(genre => ({ label: t(genre.name), value: genre.slug })),
43
+ }, {
44
+ label: t('IMDb'),
45
+ param: 'imdb_score',
46
+ range: [0, 10] as [number, number],
47
+ }, {
48
+ label: t('Year'),
49
+ param: 'year',
50
+ range: [1900, new Date().getFullYear()] as [number, number],
51
+ }, {
52
+ label: t('Runtime'),
53
+ param: 'length',
54
+ range: [0, 180] as [number, number],
55
+ valueAppend: t('Minutes'),
56
+ }, {
57
+ label: t('Countries'),
58
+ param: 'country_codes',
59
+ fetchData: async () => import.meta.env.DEV ?
60
+ (await import('$lib/data/countries.json')).default :
61
+ (await fetch(`${cdnBaseUrl}/src/lib/data/countries.json`)).json(),
62
+ }, {
63
+ label: t('Category'),
64
+ param: 'category',
65
+ data: [{ label: t('Movies'), value: 'movie' }, { label: t('Shows'), value: 'series' }, { label: t('Kids'), value: 'kids' }, { label: t('Documentary'), value: 'documentary' }],
66
+ }]
67
+
68
+ let limited = $state(limit)
69
+ let wasPreviouslyActive = false
70
+
71
+ $effect(() => {
72
+ const hasAnyActiveFilter = Object.keys(filter).some((param) => {
73
+ const { range } = items.find((i: any) => param === i.param) || {}
74
+
75
+ return isFilterItemActive(filter[param], range)
76
+ })
77
+
78
+ if (hasAnyActiveFilter || searchQuery) {
79
+ wasPreviouslyActive = true
80
+ } else if (wasPreviouslyActive) {
81
+ wasPreviouslyActive = false
82
+ onempty()
83
+ }
84
+ })
85
+ </script>
86
+
87
+ <div class="filter" role="navigation" class:limit>
88
+ <div class="items">
89
+ {#each limited ? items.slice(0, shownItemsLimit) : items as item}
90
+ <div transition:scale={{ start: 0.75, duration: 100 }}>
91
+ <FilterItem {filter} {onchange} {...item} />
92
+ </div>
93
+ {/each}
94
+ </div>
95
+
96
+ <div class="actions">
97
+ {#if limit}
98
+ <Button variant="link" onclick={() => limited = !limited}>
99
+ <IconFilter />
100
+ {t('All Filters')}
101
+ <IconArrow direction={limited ? 'down' : 'up'} />
102
+ </Button>
103
+ {/if}
104
+
105
+ {#if showSorting}
106
+ <div class="sorting" transition:fly={{ x: 5, duration: 100 }}>
107
+ <FilterSorting {filter} {onchange} />
108
+ </div>
109
+ {/if}
110
+ </div>
111
+ </div>
112
+
113
+ <ActiveFilterItems {filter} {items} />
114
+
115
+ <style lang="scss">
116
+ .filter {
117
+ position: relative;
118
+ }
119
+
120
+ .items {
121
+ display: flex;
122
+ flex-wrap: wrap;
123
+ gap: margin(0.5);
124
+ padding-right: margin(7);
125
+
126
+ .limit & {
127
+ padding-right: 0;
128
+ }
129
+ }
130
+
131
+ .actions {
132
+ position: absolute;
133
+ top: margin(0.25);
134
+ right: 0;
135
+
136
+ .limit & {
137
+ position: initial;
138
+ top: auto;
139
+ display: flex;
140
+ justify-content: space-between;
141
+ margin-top: margin(0.5);
142
+ }
143
+ }
144
+
145
+ .sorting {
146
+ margin-top: margin(0.1);
147
+ }
148
+ </style>
@@ -20,9 +20,10 @@
20
20
  interface Props {
21
21
  searchQuery?: string,
22
22
  filter?: ExploreFilter
23
+ forceGrid?: boolean
23
24
  }
24
25
 
25
- const { searchQuery = '', filter = {} }: Props = $props()
26
+ const { searchQuery = '', filter = {}, forceGrid = false }: Props = $props()
26
27
 
27
28
  // svelte-ignore non_reactive_update
28
29
  let page = 1
@@ -33,12 +34,13 @@
33
34
  let promise = $state(getTitlesForFilter())
34
35
  let width = $state(0)
35
36
 
36
- const grid = $derived(width > 500)
37
+ const grid = $derived(forceGrid || width > 500)
37
38
  const gridColumns = $derived.by(() => {
38
39
  if (width > 1400) return 8
39
40
  if (width > 900) return 6
40
- else if (width > 600) return 4
41
- return 3
41
+ if (width > 600) return 4
42
+ if (width > 400) return 3
43
+ return 2
42
44
  })
43
45
  const TitleComponent = $derived(grid ? GridTitle : ListTitle)
44
46
  const SkeletonComponent = $derived(grid ? GridTitleSkeleton : ListTitleSkeleton)
@@ -28,7 +28,7 @@
28
28
 
29
29
  {#snippet back(offset = false)}
30
30
  <div class="back" class:offset>
31
- <Button variant="link" onclick={() => { navigate('home') }}>
31
+ <Button variant="link" onclick={() => navigate('home')}>
32
32
  <IconArrow direction="left" />
33
33
  {t('Home')}
34
34
  </Button>
@@ -215,6 +215,10 @@
215
215
  &.background-blur {
216
216
  backdrop-filter: blur(1.5rem);
217
217
  }
218
+
219
+ :global(*) {
220
+ box-sizing: border-box;
221
+ }
218
222
  }
219
223
 
220
224
  .dialog,
@@ -52,9 +52,17 @@
52
52
 
53
53
  window.location.href = exploreModalUrl(participant.sid)
54
54
  }
55
+
56
+ async function getParticipants(): Promise<ParticipantData[]> {
57
+ const participants = await fetchParticipantsForTitle(title)
58
+
59
+ if (participants?.length) track(TrackingEvent.TitleParticipantsView, title, { participants: participants.map(p => p.name).slice(0, 20) })
60
+
61
+ return participants
62
+ }
55
63
  </script>
56
64
 
57
- {#await fetchParticipantsForTitle(title)}
65
+ {#await getParticipants()}
58
66
  <Rail {heading}>
59
67
  {#each { length: 5 }}
60
68
  <div class="participant">
@@ -119,4 +119,14 @@ describe('ParticipantsRail.svelte', () => {
119
119
 
120
120
  expect(track).toHaveBeenCalledWith(TrackingEvent.ParticipantClick, null, { title_source: title.original_title, participant: participants[0].name })
121
121
  })
122
+
123
+ it('Should fire track event after participants are fetched', async () => {
124
+ vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
125
+
126
+ render(ParticipantsRail, { title })
127
+
128
+ await waitFor(async () => {
129
+ expect(track).toHaveBeenCalledWith(TrackingEvent.TitleParticipantsView, title, { participants: participants.map(p => p.name) })
130
+ })
131
+ })
122
132
  })