@playpilot/tpi 8.23.0-beta.1 → 8.23.0-beta.3
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/dist/editorial.mount.js +11 -11
- package/dist/link-injections.js +2 -2
- package/dist/mount.js +8 -8
- package/package.json +1 -1
- package/src/lib/api/api.ts +3 -2
- package/src/lib/types/language.d.ts +1 -1
- package/src/routes/components/Explore/Routes/ExploreHome.svelte +34 -36
- package/src/routes/components/Modals/TitlesReelModal.svelte +4 -6
- package/src/routes/components/Rails/TitlesRail.svelte +1 -0
- package/src/tests/routes/components/Explore/Routes/ExploreHome.test.js +14 -3
package/package.json
CHANGED
package/src/lib/api/api.ts
CHANGED
|
@@ -7,9 +7,10 @@ type Options = {
|
|
|
7
7
|
headers?: Record<string, string>
|
|
8
8
|
method?: 'POST' | 'GET'
|
|
9
9
|
body?: null | Record<string, any>
|
|
10
|
+
baseUrl?: string
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export async function api<T>(path: string, { headers = {}, method = 'GET', body = null }: Options = {}): Promise<T> {
|
|
13
|
+
export async function api<T>(path: string, { headers = {}, method = 'GET', body = null, baseUrl = apiBaseUrl }: Options = {}): Promise<T> {
|
|
13
14
|
// For GET methods we store all results in a cache object. This cache is super simple and has no invalidation at all.
|
|
14
15
|
// Once something is stored it's there forever since the page is only short lived.
|
|
15
16
|
// We never use the cache for editiorial mode since in the editor requests do change.
|
|
@@ -18,7 +19,7 @@ export async function api<T>(path: string, { headers = {}, method = 'GET', body
|
|
|
18
19
|
|
|
19
20
|
const baseHeaders: Record<string, string> = method === 'GET' ? {} : { 'Content-Type': 'application/json' }
|
|
20
21
|
|
|
21
|
-
const response = await fetch(
|
|
22
|
+
const response = await fetch(baseUrl + path, {
|
|
22
23
|
method,
|
|
23
24
|
headers: new Headers({ ...baseHeaders, ...headers }),
|
|
24
25
|
// eslint-disable-next-line no-undef
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type LanguageCode = 'en-US' | 'sv-SE' | '
|
|
1
|
+
export type LanguageCode = 'en-US' | 'sv-SE' | 'da-DK'
|
|
@@ -2,37 +2,23 @@
|
|
|
2
2
|
import type { TitleData } from '$lib/types/title'
|
|
3
3
|
import { fetchTitles } from '$lib/api/titles'
|
|
4
4
|
import { t } from '$lib/localization'
|
|
5
|
-
import { Sorting } from '$lib/enums/Sorting'
|
|
6
5
|
import { track } from '$lib/tracking'
|
|
7
6
|
import { TrackingEvent } from '$lib/enums/TrackingEvent'
|
|
8
7
|
import TitlesRail from '../../Rails/TitlesRail.svelte'
|
|
9
8
|
import { mobileBreakpoint } from '$lib/constants'
|
|
9
|
+
import { getLanguage } from '$lib/language'
|
|
10
|
+
import type { LanguageCode } from '$lib/types/language'
|
|
11
|
+
import { api } from '$lib/api/api'
|
|
10
12
|
|
|
11
13
|
let expandedTitle: TitleData | null = $state(null)
|
|
12
14
|
let expandedRailKey: string | null = $state(null)
|
|
13
15
|
let windowWidth: number = $state(window.innerWidth)
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
heading: 'List: Trending',
|
|
21
|
-
params: { ordering: Sorting.Popular },
|
|
22
|
-
properties: { expandable: true },
|
|
23
|
-
}, {
|
|
24
|
-
heading: 'List: New',
|
|
25
|
-
params: { from_playlist_sid: 'li42WR', include_playable_types: 'SVOD,FREE' },
|
|
26
|
-
properties: { aside: true, size: 'flexible' },
|
|
27
|
-
}, {
|
|
28
|
-
heading: 'List: Cinema',
|
|
29
|
-
params: { from_playlist_sid: 'li42WS', region: null, no_region_filter: true },
|
|
30
|
-
properties: { expandable: true },
|
|
31
|
-
}, {
|
|
32
|
-
heading: 'List: Demand',
|
|
33
|
-
params: { from_playlist_sid: 'licBS' },
|
|
34
|
-
properties: { aside: true, size: 'flexible' },
|
|
35
|
-
}]
|
|
17
|
+
type Rail = { headings: Record<LanguageCode, string>, params: Record<string, any>, properties: Record<string, any> }
|
|
18
|
+
|
|
19
|
+
async function fetchRails(): Promise<Rail[]> {
|
|
20
|
+
return await api<Rail[]>('/streaming-guide/rails', { baseUrl: 'https://partner.playpilot.net/api' })
|
|
21
|
+
}
|
|
36
22
|
|
|
37
23
|
async function getListTitles(params: Record<string, any> = {}): Promise<TitleData[]> {
|
|
38
24
|
try {
|
|
@@ -49,20 +35,32 @@
|
|
|
49
35
|
|
|
50
36
|
<div data-testid="explore-home"></div>
|
|
51
37
|
|
|
52
|
-
{#
|
|
53
|
-
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
{
|
|
38
|
+
{#await fetchRails()}
|
|
39
|
+
{#each { length: 3 }}
|
|
40
|
+
<div class="rail">
|
|
41
|
+
<TitlesRail titles={new Promise((res) => setTimeout(res, 10000))} size={windowWidth >= mobileBreakpoint ? 'flexible' : 'huge'} />
|
|
42
|
+
</div>
|
|
43
|
+
{/each}
|
|
44
|
+
{:then rails}
|
|
45
|
+
{#each rails as { headings, params, properties }}
|
|
46
|
+
{@const heading = headings[getLanguage()]}
|
|
47
|
+
|
|
48
|
+
<div class="rail">
|
|
49
|
+
<TitlesRail
|
|
50
|
+
{heading}
|
|
51
|
+
titles={getListTitles(params)}
|
|
52
|
+
size={windowWidth >= mobileBreakpoint ? (properties.size || 'flexible') : 'huge'}
|
|
53
|
+
minimumLength={7}
|
|
54
|
+
{...properties}
|
|
55
|
+
bind:expandedTitle
|
|
56
|
+
bind:expandedRailKey
|
|
57
|
+
onclick={() => track(TrackingEvent.ExploreTitleRailModalView, null, { rail: headings })}
|
|
58
|
+
onexpand={(title) => track(TrackingEvent.ExploreTitleRailExpandClick, title, { rail: headings })} />
|
|
59
|
+
</div>
|
|
60
|
+
{/each}
|
|
61
|
+
{:catch}
|
|
62
|
+
{t('An Error Occurred')}
|
|
63
|
+
{/await}
|
|
66
64
|
|
|
67
65
|
<style lang="scss">
|
|
68
66
|
.rail {
|
|
@@ -89,14 +89,14 @@
|
|
|
89
89
|
</div>
|
|
90
90
|
|
|
91
91
|
<style lang="scss">
|
|
92
|
-
$modal-height:
|
|
93
|
-
$item-height: calc(
|
|
92
|
+
$modal-height: calc(100dvh - margin(4.5));
|
|
93
|
+
$item-height: calc($modal-height - margin(7));
|
|
94
94
|
|
|
95
95
|
.reel {
|
|
96
96
|
--playpilot-detail-background-height: #{$item-height};
|
|
97
97
|
--playpilot-detail-background-border-radius: 0;
|
|
98
98
|
--playpilot-detail-background-width: 400%;
|
|
99
|
-
--
|
|
99
|
+
--playpilot-detail-backdrop: rgba(0, 0, 0, 0.85);
|
|
100
100
|
|
|
101
101
|
:global(*) {
|
|
102
102
|
box-sizing: border-box;
|
|
@@ -113,11 +113,9 @@
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
.slider {
|
|
116
|
-
margin-top:
|
|
116
|
+
margin-top: calc(100dvh - $modal-height);
|
|
117
117
|
height: $modal-height;
|
|
118
118
|
width: 100%;
|
|
119
|
-
border-radius: theme(border-radius-large) theme(border-radius-large) 0 0;
|
|
120
|
-
overflow: hidden;
|
|
121
119
|
}
|
|
122
120
|
|
|
123
121
|
.item {
|
|
@@ -1,23 +1,34 @@
|
|
|
1
|
-
import { render } from '@testing-library/svelte'
|
|
1
|
+
import { render, waitFor } from '@testing-library/svelte'
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
import ExploreHome from '../../../../../routes/components/Explore/Routes/ExploreHome.svelte'
|
|
5
5
|
import { fetchTitles } from '$lib/api/titles'
|
|
6
|
+
import { api } from '$lib/api/api'
|
|
6
7
|
|
|
7
8
|
vi.mock('$lib/api/titles', () => ({
|
|
8
9
|
fetchTitles: vi.fn(),
|
|
9
10
|
}))
|
|
10
11
|
|
|
12
|
+
vi.mock('$lib/api/api', () => ({
|
|
13
|
+
api: vi.fn(),
|
|
14
|
+
}))
|
|
15
|
+
|
|
11
16
|
describe('ExploreResults.svelte', () => {
|
|
12
17
|
beforeEach(() => {
|
|
13
18
|
vi.resetAllMocks()
|
|
14
19
|
})
|
|
15
20
|
|
|
16
|
-
it('Should fetch titles for each rail', () => {
|
|
21
|
+
it('Should fetch rails endpoint and titles for each rail', async () => {
|
|
22
|
+
const rail = { headings: {}, properties: {}, params: {} }
|
|
23
|
+
|
|
24
|
+
vi.mocked(api).mockResolvedValue([rail, rail, rail, rail, rail])
|
|
17
25
|
vi.mocked(fetchTitles).mockResolvedValue({ next: null, previous: null, results: [] })
|
|
18
26
|
|
|
19
27
|
render(ExploreHome)
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
await waitFor(() => {
|
|
30
|
+
expect(api).toHaveBeenCalledOnce()
|
|
31
|
+
expect(fetchTitles).toHaveBeenCalledTimes(5)
|
|
32
|
+
})
|
|
22
33
|
})
|
|
23
34
|
})
|