@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playpilot/tpi",
3
- "version": "8.23.0-beta.1",
3
+ "version": "8.23.0-beta.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -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(apiBaseUrl + path, {
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' | 'dk-DK'
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
- const rails: { heading: string, params: Record<string, any>, properties: Record<string, any> }[] = [{
16
- heading: 'List: Upcoming',
17
- params: { from_playlist_sid: 'li42wf', region: null, no_region_filter: true },
18
- properties: { expandable: true },
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
- {#each rails as { heading, params, properties }}
53
- <div class="rail">
54
- <TitlesRail
55
- heading={t(heading)}
56
- titles={getListTitles(params)}
57
- size={windowWidth >= mobileBreakpoint ? 'flexible' : 'huge'}
58
- minimumLength={7}
59
- {...properties}
60
- bind:expandedTitle
61
- bind:expandedRailKey
62
- onclick={() => track(TrackingEvent.ExploreTitleRailModalView, null, { rail: heading })}
63
- onexpand={(title) => track(TrackingEvent.ExploreTitleRailExpandClick, title, { rail: heading })} />
64
- </div>
65
- {/each}
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: 90dvh;
93
- $item-height: calc(90dvh - margin(7));
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
- --background-mask-image: unset;
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: 10dvh;
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 {
@@ -245,6 +245,7 @@
245
245
  }
246
246
 
247
247
  .title {
248
+ cursor: pointer;
248
249
  width: unset;
249
250
  font-size: theme(rail-font-size, font-size-small);
250
251
  line-height: 1.2;
@@ -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
- expect(fetchTitles).toHaveBeenCalledTimes(5)
29
+ await waitFor(() => {
30
+ expect(api).toHaveBeenCalledOnce()
31
+ expect(fetchTitles).toHaveBeenCalledTimes(5)
32
+ })
22
33
  })
23
34
  })