Skip to content

Commit 1293e47

Browse files
authored
refactor: cast button (#25101)
1 parent 1a24a2d commit 1293e47

7 files changed

Lines changed: 42 additions & 34 deletions

File tree

web/src/lib/cast/cast-button.svelte

Lines changed: 0 additions & 24 deletions
This file was deleted.

web/src/lib/components/album-page/album-viewer.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { shortcut } from '$lib/actions/shortcut';
3-
import CastButton from '$lib/cast/cast-button.svelte';
3+
import ActionButton from '$lib/components/ActionButton.svelte';
44
import AlbumMap from '$lib/components/album-page/album-map.svelte';
55
import DownloadAction from '$lib/components/timeline/actions/DownloadAction.svelte';
66
import SelectAllAssets from '$lib/components/timeline/actions/SelectAllAction.svelte';
@@ -9,6 +9,7 @@
99
import { featureFlagsManager } from '$lib/managers/feature-flags-manager.svelte';
1010
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
1111
import { handleDownloadAlbum } from '$lib/services/album.service';
12+
import { getGlobalActions } from '$lib/services/app.service';
1213
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
1314
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
1415
import { dragAndDropFilesStore } from '$lib/stores/drag-and-drop-files.store';
@@ -58,6 +59,8 @@
5859
handlePromiseError(setAssetId(asset.id).then(() => ($slideshowState = SlideshowState.PlaySlideshow)));
5960
}
6061
};
62+
63+
const { Cast } = $derived(getGlobalActions($t));
6164
</script>
6265

6366
<svelte:document
@@ -116,7 +119,7 @@
116119
{/snippet}
117120

118121
{#snippet trailing()}
119-
<CastButton />
122+
<ActionButton action={Cast} />
120123

121124
{#if sharedLink.allowUpload}
122125
<IconButton

web/src/lib/components/asset-viewer/asset-viewer-nav-bar.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts">
22
import { goto } from '$app/navigation';
33
import { resolve } from '$app/paths';
4-
import CastButton from '$lib/cast/cast-button.svelte';
54
import ActionButton from '$lib/components/ActionButton.svelte';
65
import type { OnAction, PreAction } from '$lib/components/asset-viewer/actions/action';
76
import AddToAlbumAction from '$lib/components/asset-viewer/actions/add-to-album-action.svelte';
@@ -24,6 +23,7 @@
2423
import MenuOption from '$lib/components/shared-components/context-menu/menu-option.svelte';
2524
import { AppRoute } from '$lib/constants';
2625
import { featureFlagsManager } from '$lib/managers/feature-flags-manager.svelte';
26+
import { getGlobalActions } from '$lib/services/app.service';
2727
import { getAssetActions, handleReplaceAsset } from '$lib/services/asset.service';
2828
import { photoViewerImgElement } from '$lib/stores/assets-store.svelte';
2929
import { user } from '$lib/stores/user.store';
@@ -111,6 +111,8 @@
111111
shortcuts: [{ key: 'Escape' }],
112112
};
113113
114+
const { Cast } = $derived(getGlobalActions($t));
115+
114116
const { Share, Offline, PlayMotionPhoto, StopMotionPhoto, Info } = $derived(getAssetActions($t, asset));
115117
116118
// $: showEditorButton =
@@ -137,8 +139,7 @@
137139
</div>
138140

139141
<div class="flex gap-2 overflow-x-auto dark" data-testid="asset-viewer-navbar-actions">
140-
<CastButton />
141-
142+
<ActionButton action={Cast} />
142143
<ActionButton action={Share} />
143144
<ActionButton action={Offline} />
144145
<ActionButton action={PlayMotionPhoto} />

web/src/lib/components/shared-components/navigation-bar/navigation-bar.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
<script lang="ts">
66
import { page } from '$app/state';
77
import { clickOutside } from '$lib/actions/click-outside';
8-
import CastButton from '$lib/cast/cast-button.svelte';
8+
import ActionButton from '$lib/components/ActionButton.svelte';
99
import NotificationPanel from '$lib/components/shared-components/navigation-bar/notification-panel.svelte';
1010
import SearchBar from '$lib/components/shared-components/search-bar/search-bar.svelte';
1111
import { AppRoute } from '$lib/constants';
1212
import SkipLink from '$lib/elements/SkipLink.svelte';
1313
import { authManager } from '$lib/managers/auth-manager.svelte';
1414
import { featureFlagsManager } from '$lib/managers/feature-flags-manager.svelte';
15+
import { getGlobalActions } from '$lib/services/app.service';
1516
import { mobileDevice } from '$lib/stores/mobile-device.svelte';
1617
import { notificationManager } from '$lib/stores/notification-manager.svelte';
1718
import { sidebarStore } from '$lib/stores/sidebar.svelte';
@@ -45,6 +46,8 @@
4546
console.error('Failed to load notifications on mount', error);
4647
}
4748
});
49+
50+
const { Cast } = $derived(getGlobalActions($t));
4851
</script>
4952

5053
<svelte:window bind:innerWidth />
@@ -158,7 +161,7 @@
158161
{/if}
159162
</div>
160163

161-
<CastButton />
164+
<ActionButton action={Cast} />
162165

163166
<div
164167
use:clickOutside={{

web/src/lib/managers/cast-manager.svelte.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { eventManager } from '$lib/managers/event-manager.svelte';
12
import { GCastDestination } from '$lib/utils/cast/gcast-destination.svelte';
23
import { createSession, type SessionCreateResponseDto } from '@immich/sdk';
34
import { DateTime, Duration } from 'luxon';
@@ -57,9 +58,11 @@ class CastManager {
5758
new GCastDestination(),
5859
// Add other cast destinations here (ie FCast)
5960
];
61+
62+
eventManager.on('AppInit', () => void this.initialize());
6063
}
6164

62-
async initialize() {
65+
private async initialize() {
6366
// this goes first to prevent multiple calls to initialize
6467
if (this.initialized) {
6568
return;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { CastDestinationType, castManager } from '$lib/managers/cast-manager.svelte';
2+
import { GCastDestination } from '$lib/utils/cast/gcast-destination.svelte';
3+
import type { ActionItem } from '@immich/ui';
4+
import { mdiCast, mdiCastConnected } from '@mdi/js';
5+
import type { MessageFormatter } from 'svelte-i18n';
6+
7+
export const getGlobalActions = ($t: MessageFormatter) => {
8+
const Cast: ActionItem = {
9+
title: $t('cast'),
10+
icon: castManager.isCasting ? mdiCastConnected : mdiCast,
11+
color: castManager.isCasting ? 'primary' : 'secondary',
12+
$if: () =>
13+
castManager.availableDestinations.length > 0 &&
14+
castManager.availableDestinations[0].type === CastDestinationType.GCAST,
15+
onAction: () => void GCastDestination.showCastDialog(),
16+
};
17+
18+
return { Cast };
19+
};

web/src/routes/(user)/albums/[albumId=id]/[[photos=photos]]/[[assetId=id]]/+page.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import { afterNavigate, goto, onNavigate } from '$app/navigation';
33
import { scrollMemoryClearer } from '$lib/actions/scroll-memory';
4-
import CastButton from '$lib/cast/cast-button.svelte';
4+
import ActionButton from '$lib/components/ActionButton.svelte';
55
import AlbumDescription from '$lib/components/album-page/album-description.svelte';
66
import AlbumMap from '$lib/components/album-page/album-map.svelte';
77
import AlbumSummary from '$lib/components/album-page/album-summary.svelte';
@@ -39,6 +39,7 @@
3939
import AlbumUsersModal from '$lib/modals/AlbumUsersModal.svelte';
4040
import SharedLinkCreateModal from '$lib/modals/SharedLinkCreateModal.svelte';
4141
import { handleDeleteAlbum, handleDownloadAlbum } from '$lib/services/album.service';
42+
import { getGlobalActions } from '$lib/services/app.service';
4243
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
4344
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
4445
import { SlideshowNavigation, SlideshowState, slideshowStore } from '$lib/stores/slideshow.store';
@@ -413,6 +414,8 @@
413414
}
414415
}
415416
};
417+
418+
const { Cast } = $derived(getGlobalActions($t));
416419
</script>
417420

418421
<OnEvents {onSharedLinkCreate} {onAlbumDelete} />
@@ -592,7 +595,7 @@
592595
{#if viewMode === AlbumPageViewMode.VIEW}
593596
<ControlAppBar showBackButton backIcon={mdiArrowLeft} onClose={() => goto(backUrl)}>
594597
{#snippet trailing()}
595-
<CastButton />
598+
<ActionButton action={Cast} />
596599

597600
{#if isEditor}
598601
<IconButton

0 commit comments

Comments
 (0)