Skip to content

Commit 08fd906

Browse files
committed
refactor: stackRouterPage controls to use context everywhere
1 parent 7b8fd35 commit 08fd906

File tree

11 files changed

+23
-66
lines changed

11 files changed

+23
-66
lines changed

backend/src/auth/auth.controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class AuthController {
3838

3939
return {
4040
accessToken: token,
41-
user: this.usersService.getUserDto(user),
41+
user: await this.usersService.getUserDto(user),
4242
};
4343
}
4444
}

src/lib/components/Sidebar/Sidebar.svelte

-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
Manage
3030
}
3131
32-
const tab = useTabs(Tabs.Series);
33-
3432
const { visibleStyle } = getUiVisibilityContext();
3533
3634
let selectedIndex = 0;

src/lib/components/StackRouter/StackRouter.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,15 @@ function useStackRouterControls() {
329329
const topSelectable = useRegistrar();
330330

331331
function handleGoBack() {
332-
const selectable = get(topSelectable);
333-
if (selectable && get(selectable.focusIndex) === 0) {
334-
history.back();
335-
} else {
336-
selectable?.focusChild(0, { cycleTo: true }) || selectable?.focus({ cycleTo: true });
337-
}
332+
history.back();
338333
}
339334

340335
function handleGoToTop() {
341336
const selectable = get(topSelectable);
342-
if (topSelectable) {
343-
selectable?.focusChild(0, { cycleTo: true }) || selectable?.focus({ cycleTo: true });
337+
if (selectable && get(selectable.focusIndex) === 0 && get(selectable.hasFocusWithin)) {
338+
history.back();
339+
} else if (selectable) {
340+
selectable.focusChild(0, { cycleTo: true }) || selectable.focus({ cycleTo: true });
344341
} else handleGoBack();
345342
}
346343

src/lib/pages/CollectionPages/CollectionPage.svelte

+6-17
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import TmdbCard from '$lib/components/Card/TmdbCard.svelte';
33
import CardGrid from '$lib/components/CardGrid.svelte';
44
import Container from '$lib/components/Container.svelte';
5+
import FloatingHeader from '$lib/components/FloatingHeader.svelte';
56
import { createBackgroundPage } from '$lib/components/GlobalBackground/BackgroundStack';
6-
import type { StackRouterPageProps } from '$lib/components/StackRouter/StackRouterPage.type';
7+
import { getStackRouterControls } from '$lib/components/StackRouter/StackRouter';
78
import { scrollIntoView } from '$lib/selectable';
89
import { setScrollContext } from '$lib/stores/scroll.store';
910
import classNames from 'classnames';
@@ -12,18 +13,13 @@
1213
export let title: string;
1314
export let subtitle = '';
1415
export let items: Promise<ComponentProps<TmdbCard>['item'][]>;
15-
export let registrar: StackRouterPageProps['registrar'];
16-
export let handleGoBack: StackRouterPageProps['handleGoBack'];
16+
const { registrar } = getStackRouterControls();
1717
1818
const background = createBackgroundPage();
1919
const { registrar: registerScroll, topVisible } = setScrollContext();
20-
console.log($topVisible);
2120
</script>
2221

23-
<Container
24-
on:back={handleGoBack}
25-
class="py-16 *:px-32 flex flex-col h-screen overflow-y-auto overflow-x-hidden"
26-
>
22+
<Container class="py-16 *:px-32 flex flex-col h-screen overflow-y-auto overflow-x-hidden">
2723
<slot name="header">
2824
<div class="pt-8">
2925
<h2 class="uppercase text-zinc-300 font-semibold tracking-wider">{subtitle}</h2>
@@ -39,14 +35,7 @@
3935
</slot>
4036

4137
<slot name="header-compact">
42-
<div
43-
class={classNames(
44-
'py-6 absolute top-0 inset-x-0 z-10 bg-gradient-to-b from-100% from-secondary-900 to-transparent transition-all',
45-
{
46-
'opacity-0 pointer-events-none -translate-y-4': $topVisible
47-
}
48-
)}
49-
>
38+
<FloatingHeader visible={$topVisible}>
5039
<h2 class="uppercase text-zinc-300 font-semibold tracking-wider">{subtitle}</h2>
5140
<h1
5241
class={classNames('text-left font-semibold tracking-wider text-stone-200 mt-1', {
@@ -56,7 +45,7 @@
5645
>
5746
{title}
5847
</h1>
59-
</div>
48+
</FloatingHeader>
6049
</slot>
6150

6251
<div class="pt-16" use:registerScroll>
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<script lang="ts">
22
import { companies } from '$lib/components/Collection/collections';
3-
import type { StackRouterPageProps } from '$lib/components/StackRouter/StackRouterPage.type';
43
import { tmdbApi } from '$lib/stores/user.store';
54
import { capitalize } from '$lib/utils';
65
import CollectionPage from './CollectionPage.svelte';
76
87
export let company: string;
9-
export let registrar: StackRouterPageProps['registrar'];
10-
export let handleGoBack: StackRouterPageProps['handleGoBack'];
118
129
const tmdbCompanyId = companies[company]?.id;
1310
const companyName = companies[company]?.name ?? capitalize(company);
@@ -21,10 +18,4 @@
2118
: Promise.resolve([]);
2219
</script>
2320

24-
<CollectionPage
25-
{registrar}
26-
{handleGoBack}
27-
{items}
28-
title={companyName}
29-
subtitle="Production Company"
30-
/>
21+
<CollectionPage {items} title={companyName} subtitle="Production Company" />
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<script lang="ts">
22
import { collections } from '$lib/components/Collection/collections';
3-
import type { StackRouterPageProps } from '$lib/components/StackRouter/StackRouterPage.type';
43
import { tmdbApi } from '$lib/stores/user.store';
54
import { capitalize } from '$lib/utils';
65
import CollectionPage from './CollectionPage.svelte';
76
87
export let collection: string;
9-
export let registrar: StackRouterPageProps['registrar'];
10-
export let handleGoBack: StackRouterPageProps['handleGoBack'];
11-
8+
129
const listId = collection.match(/^\d+$/) ? parseInt(collection) : collections[collection]?.id;
1310
const collectionName = collections[collection]?.name ?? capitalize(collection);
1411
@@ -17,4 +14,4 @@
1714
: Promise.resolve([]);
1815
</script>
1916

20-
<CollectionPage {registrar} {handleGoBack} {items} title={collectionName} subtitle="Collection" />
17+
<CollectionPage {items} title={collectionName} subtitle="Collection" />
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<script lang="ts">
22
import { networks } from '$lib/components/Collection/collections';
3-
import type { StackRouterPageProps } from '$lib/components/StackRouter/StackRouterPage.type';
43
import { tmdbApi } from '$lib/stores/user.store';
54
import { capitalize } from '$lib/utils';
65
import CollectionPage from './CollectionPage.svelte';
76
87
export let network: string;
9-
export let registrar: StackRouterPageProps['registrar'];
10-
export let handleGoBack: StackRouterPageProps['handleGoBack'];
118
129
const networkId = networks[network]?.id;
1310
const networkName = networks[network]?.name ?? capitalize(network);
@@ -19,4 +16,4 @@
1916
.then((r) => r.data.results ?? []);
2017
</script>
2118

22-
<CollectionPage {registrar} {handleGoBack} {items} title={networkName} subtitle="Network" />
19+
<CollectionPage {items} title={networkName} subtitle="Network" />

src/lib/pages/PersonPage.svelte

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
<script lang="ts">
2-
import Container from '$components/Container.svelte';
32
import { createBackgroundPage } from '$lib/components/GlobalBackground/BackgroundStack';
4-
import type { StackRouterPageProps } from '$lib/components/StackRouter/StackRouterPage.type';
5-
import { scrollIntoView } from '$lib/selectable.js';
63
import { tmdbApi } from '../apis/tmdb/tmdb-api';
7-
import TmdbCard from '../components/Card/TmdbCard.svelte';
8-
import CardGrid from '../components/CardGrid.svelte';
94
import { TMDB_POSTER_SMALL } from '../constants.js';
105
import CollectionPage from './CollectionPages/CollectionPage.svelte';
116
import HeroTitleInfo from './TitlePages/HeroTitleInfo.svelte';
127
138
createBackgroundPage();
149
1510
export let id: string;
16-
export let registrar: StackRouterPageProps['registrar'];
17-
export let handleGoBack: StackRouterPageProps['handleGoBack'];
11+
1812
1913
$: person = tmdbApi.getPerson(Number(id));
2014
$: titles = person.then((person) => {
@@ -69,8 +63,6 @@
6963
items={titles}
7064
subtitle="Person"
7165
title={person.name ?? 'Unknown'}
72-
{registrar}
73-
{handleGoBack}
7466
>
7567
<div class="flex space-x-8" slot="header">
7668
<div

src/lib/pages/TitlePages/EpisodePage.svelte

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
import { PLATFORM_WEB, TMDB_IMAGES_ORIGINAL } from '../../constants';
1212
import { formatThousands } from '../../utils';
1313
import TitleProperties from './HeroTitleInfo.svelte';
14+
import { getStackRouterControls } from '$lib/components/StackRouter/StackRouter';
1415
1516
export let id: string; // Series tmdbId
1617
export let season: string;
1718
export let episode: string;
1819
19-
export let handleGoBack: StackRouterPageProps['handleGoBack'];
20-
export let registrar: StackRouterPageProps['registrar'];
20+
const { registrar } = getStackRouterControls();
2121
2222
const background = createBackgroundPage({ videoMediaId: id });
2323
const { promise: tmdbEpisode, unsubscribe: unsubscribeTmdbEpisode } =
@@ -90,7 +90,6 @@
9090
direction="horizontal"
9191
class="flex mt-8 space-x-4"
9292
focusOnMount
93-
on:back={handleGoBack}
9493
on:mount={registrar}
9594
>
9695
<Button

src/lib/pages/TitlePages/MoviePage/MoviePage.svelte

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { createBackgroundPage } from '$lib/components/GlobalBackground/BackgroundStack';
88
import HeroCarousel from '$lib/components/HeroShowcase/HeroCarousel.svelte';
99
import TmdbPersonCard from '$lib/components/PersonCard/TmdbPersonCard.svelte';
10-
import type { StackRouterPageProps } from '$lib/components/StackRouter/StackRouterPage.type';
10+
import { getStackRouterControls } from '$lib/components/StackRouter/StackRouter';
1111
import { PLATFORM_WEB, TMDB_IMAGES_ORIGINAL } from '$lib/constants';
1212
import { scrollIntoView } from '$lib/selectable';
1313
import { tmdbMovieDataStore } from '$lib/stores/data.store';
@@ -22,8 +22,7 @@
2222
import HeroTitleInfo from '../HeroTitleInfo.svelte';
2323
2424
export let id: string;
25-
export let handleGoBack: StackRouterPageProps['handleGoBack'];
26-
export let registrar: StackRouterPageProps['registrar'];
25+
const { registrar } = getStackRouterControls();
2726
2827
const tmdbId = Number(id);
2928
const background = createBackgroundPage({ backgroundMediaId: id, videoMediaId: id });
@@ -123,7 +122,6 @@
123122
direction="horizontal"
124123
class="flex mt-8 space-x-4"
125124
focusOnMount
126-
on:back={handleGoBack}
127125
on:mount={registrar}
128126
>
129127
<Button

src/lib/pages/TitlePages/SeriesPage/SeriesPage.svelte

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import type { TitleInfoProperty } from '../HeroTitleInfo';
2121
import TitleProperties from '../HeroTitleInfo.svelte';
2222
import EpisodeGrid from './EpisodeGrid.svelte';
23+
import { getStackRouterControls } from '$lib/components/StackRouter/StackRouter';
2324
2425
export let id: string;
25-
export let registrar: StackRouterPageProps['registrar'];
26-
export let handleGoBack: StackRouterPageProps['handleGoBack'];
26+
const { registrar } = getStackRouterControls();
2727
2828
const background = createBackgroundPage({ backgroundMediaId: id, videoMediaId: id });
2929
const {
@@ -134,7 +134,6 @@
134134
direction="horizontal"
135135
class="flex mt-8 space-x-4"
136136
focusOnMount
137-
on:back={handleGoBack}
138137
on:mount={registrar}
139138
>
140139
<Button

0 commit comments

Comments
 (0)