@playpilot/tpi 8.23.4 → 8.24.0

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/src/lib/url.ts CHANGED
@@ -10,7 +10,7 @@ export function getFullUrlPath(): string {
10
10
  return location.protocol + '//' + location.host + cleanedPathname
11
11
  }
12
12
 
13
- export function getUrlParams(): string {
13
+ export function getUrlParams(): Record<string, any> {
14
14
  try {
15
15
  const url = new URL(location.href)
16
16
  return Object.fromEntries(url.searchParams.entries())
@@ -1,144 +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
-
64
- let limited = $state(limit)
65
- let wasPreviouslyActive = false
66
-
67
- $effect(() => {
68
- const hasAnyActiveFilter = Object.keys(filter).some((param) => {
69
- const { range } = items.find((i: any) => param === i.param) || {}
70
-
71
- return isFilterItemActive(filter[param], range)
72
- })
73
-
74
- if (hasAnyActiveFilter || searchQuery) {
75
- wasPreviouslyActive = true
76
- } else if (wasPreviouslyActive) {
77
- wasPreviouslyActive = false
78
- onempty()
79
- }
80
- })
81
- </script>
82
-
83
- <div class="filter" role="navigation" class:limit>
84
- <div class="items">
85
- {#each limited ? items.slice(0, shownItemsLimit) : items as item}
86
- <div transition:scale={{ start: 0.75, duration: 100 }}>
87
- <FilterItem {filter} {onchange} {...item} />
88
- </div>
89
- {/each}
90
- </div>
91
-
92
- <div class="actions">
93
- {#if limit}
94
- <Button variant="link" onclick={() => limited = !limited}>
95
- <IconFilter />
96
- {t('All Filters')}
97
- <IconArrow direction={limited ? 'down' : 'up'} />
98
- </Button>
99
- {/if}
100
-
101
- {#if showSorting}
102
- <div class="sorting" transition:fly={{ x: 5, duration: 100 }}>
103
- <FilterSorting {filter} {onchange} />
104
- </div>
105
- {/if}
106
- </div>
107
- </div>
108
-
109
- <ActiveFilterItems {filter} {items} />
110
-
111
- <style lang="scss">
112
- .filter {
113
- position: relative;
114
- }
115
-
116
- .items {
117
- display: flex;
118
- flex-wrap: wrap;
119
- gap: margin(0.5);
120
- padding-right: margin(7);
121
-
122
- .limit & {
123
- padding-right: 0;
124
- }
125
- }
126
-
127
- .actions {
128
- position: absolute;
129
- top: margin(0.25);
130
- right: 0;
131
-
132
- .limit & {
133
- position: initial;
134
- top: auto;
135
- display: flex;
136
- justify-content: space-between;
137
- margin-top: margin(0.5);
138
- }
139
- }
140
-
141
- .sorting {
142
- margin-top: margin(0.1);
143
- }
144
- </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>
@@ -15,12 +15,12 @@
15
15
  </script>
16
16
 
17
17
  <img
18
+ loading={lazy ? 'lazy' : null}
18
19
  src={removeImageUrlPrefix(title.standing_poster)}
19
20
  alt="Movie poster for '{title.title}'"
20
21
  {width}
21
22
  {height}
22
23
  onerror={({ target }) => (target as HTMLImageElement).src = imagePlaceholderDataUrl}
23
- loading={lazy ? 'lazy' : null}
24
24
  {onload} />
25
25
 
26
26
  <style lang="scss">
@@ -90,7 +90,6 @@ describe('$lib/splitTest', () => {
90
90
  window.PlayPilotLinkInjections.split_test_identifiers = {}
91
91
  window.PlayPilotLinkInjections.split_test_identifiers[multiple.key] = 0.25
92
92
 
93
-
94
93
  expect(isInSplitTestVariant(multiple, 0)).toBe(true)
95
94
  expect(isInSplitTestVariant(multiple, 1)).toBe(false)
96
95
  expect(isInSplitTestVariant(multiple, 2)).toBe(false)
@@ -27,13 +27,13 @@ describe('Filter.svelte', () => {
27
27
 
28
28
  await fireEvent.click(getByText('All filters'))
29
29
 
30
- expect(getAllByTestId('filter-item')).toHaveLength(6)
30
+ expect(getAllByTestId('filter-item')).toHaveLength(7)
31
31
  })
32
32
 
33
33
  it('Should not limit the number of filter items by default if limit is set to false', () => {
34
34
  const { getAllByTestId, getByRole } = render(Filter, { filter: {}, limit: false })
35
35
 
36
- expect(getAllByTestId('filter-item')).toHaveLength(6)
36
+ expect(getAllByTestId('filter-item')).toHaveLength(7)
37
37
  expect(getByRole('navigation').classList).not.toContain('limit')
38
38
  })
39
39