asset-viewer.svelte 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. <script lang="ts">
  2. import { goto } from '$app/navigation';
  3. import {
  4. ActivityResponseDto,
  5. AlbumResponseDto,
  6. api,
  7. AssetJobName,
  8. AssetResponseDto,
  9. AssetTypeEnum,
  10. ReactionType,
  11. SharedLinkResponseDto,
  12. UserResponseDto,
  13. } from '@api';
  14. import { createEventDispatcher, onDestroy, onMount } from 'svelte';
  15. import { fly } from 'svelte/transition';
  16. import AlbumSelectionModal from '../shared-components/album-selection-modal.svelte';
  17. import { notificationController, NotificationType } from '../shared-components/notification/notification';
  18. import AssetViewerNavBar from './asset-viewer-nav-bar.svelte';
  19. import DetailPanel from './detail-panel.svelte';
  20. import PhotoViewer from './photo-viewer.svelte';
  21. import VideoViewer from './video-viewer.svelte';
  22. import PanoramaViewer from './panorama-viewer.svelte';
  23. import { ProjectionType } from '$lib/constants';
  24. import ConfirmDialogue from '$lib/components/shared-components/confirm-dialogue.svelte';
  25. import ProfileImageCropper from '../shared-components/profile-image-cropper.svelte';
  26. import { isShowDetail } from '$lib/stores/preferences.store';
  27. import { addAssetsToAlbum, downloadFile, getAssetType } from '$lib/utils/asset-utils';
  28. import NavigationArea from './navigation-area.svelte';
  29. import { browser } from '$app/environment';
  30. import { handleError } from '$lib/utils/handle-error';
  31. import type { AssetStore } from '$lib/stores/assets.store';
  32. import { shouldIgnoreShortcut } from '$lib/utils/shortcut';
  33. import { assetViewingStore } from '$lib/stores/asset-viewing.store';
  34. import { SlideshowHistory } from '$lib/utils/slideshow-history';
  35. import { featureFlags } from '$lib/stores/server-config.store';
  36. import { mdiChevronLeft, mdiChevronRight, mdiImageBrokenVariant } from '@mdi/js';
  37. import Icon from '$lib/components/elements/icon.svelte';
  38. import Thumbnail from '../assets/thumbnail/thumbnail.svelte';
  39. import { stackAssetsStore } from '$lib/stores/stacked-asset.store';
  40. import ActivityViewer from './activity-viewer.svelte';
  41. import ActivityStatus from './activity-status.svelte';
  42. import { updateNumberOfComments } from '$lib/stores/activity.store';
  43. import { SlideshowState, slideshowStore } from '$lib/stores/slideshow.store';
  44. import SlideshowBar from './slideshow-bar.svelte';
  45. export let assetStore: AssetStore | null = null;
  46. export let asset: AssetResponseDto;
  47. export let showNavigation = true;
  48. export let sharedLink: SharedLinkResponseDto | undefined = undefined;
  49. $: isTrashEnabled = $featureFlags.trash;
  50. export let force = false;
  51. export let withStacked = false;
  52. export let isShared = false;
  53. export let user: UserResponseDto | null = null;
  54. export let album: AlbumResponseDto | null = null;
  55. let reactions: ActivityResponseDto[] = [];
  56. const { setAssetId } = assetViewingStore;
  57. const {
  58. restartProgress: restartSlideshowProgress,
  59. stopProgress: stopSlideshowProgress,
  60. slideshowShuffle,
  61. slideshowState,
  62. } = slideshowStore;
  63. const dispatch = createEventDispatcher<{
  64. archived: AssetResponseDto;
  65. unarchived: AssetResponseDto;
  66. favorite: AssetResponseDto;
  67. unfavorite: AssetResponseDto;
  68. close: void;
  69. next: void;
  70. previous: void;
  71. unstack: void;
  72. }>();
  73. let appearsInAlbums: AlbumResponseDto[] = [];
  74. let isShowAlbumPicker = false;
  75. let isShowDeleteConfirmation = false;
  76. let addToSharedAlbum = true;
  77. let shouldPlayMotionPhoto = false;
  78. let isShowProfileImageCrop = false;
  79. let shouldShowDownloadButton = sharedLink ? sharedLink.allowDownload : !asset.isOffline;
  80. let shouldShowDetailButton = asset.hasMetadata;
  81. let canCopyImagesToClipboard: boolean;
  82. let slideshowStateUnsubscribe: () => void;
  83. let shuffleSlideshowUnsubscribe: () => void;
  84. let previewStackedAsset: AssetResponseDto | undefined;
  85. let isShowActivity = false;
  86. let isLiked: ActivityResponseDto | null = null;
  87. let numberOfComments: number;
  88. $: {
  89. if (asset.stackCount && asset.stack) {
  90. $stackAssetsStore = asset.stack;
  91. $stackAssetsStore = [...$stackAssetsStore, asset].sort(
  92. (a, b) => new Date(b.fileCreatedAt).getTime() - new Date(a.fileCreatedAt).getTime(),
  93. );
  94. }
  95. if (!$stackAssetsStore.map((a) => a.id).includes(asset.id)) {
  96. $stackAssetsStore = [];
  97. }
  98. }
  99. const handleAddComment = () => {
  100. numberOfComments++;
  101. updateNumberOfComments(1);
  102. };
  103. const handleRemoveComment = () => {
  104. numberOfComments--;
  105. updateNumberOfComments(-1);
  106. };
  107. const handleFavorite = async () => {
  108. if (album) {
  109. try {
  110. if (isLiked) {
  111. const activityId = isLiked.id;
  112. await api.activityApi.deleteActivity({ id: activityId });
  113. reactions = reactions.filter((reaction) => reaction.id !== activityId);
  114. isLiked = null;
  115. } else {
  116. const { data } = await api.activityApi.createActivity({
  117. activityCreateDto: { albumId: album.id, assetId: asset.id, type: ReactionType.Like },
  118. });
  119. isLiked = data;
  120. reactions = [...reactions, isLiked];
  121. }
  122. } catch (error) {
  123. handleError(error, "Can't change favorite for asset");
  124. }
  125. }
  126. };
  127. const getFavorite = async () => {
  128. if (album && user) {
  129. try {
  130. const { data } = await api.activityApi.getActivities({
  131. userId: user.id,
  132. assetId: asset.id,
  133. albumId: album.id,
  134. type: ReactionType.Like,
  135. });
  136. if (data.length > 0) {
  137. isLiked = data[0];
  138. } else {
  139. isLiked = null;
  140. }
  141. } catch (error) {
  142. handleError(error, "Can't get Favorite");
  143. }
  144. }
  145. };
  146. const getNumberOfComments = async () => {
  147. if (album) {
  148. try {
  149. const { data } = await api.activityApi.getActivityStatistics({ assetId: asset.id, albumId: album.id });
  150. numberOfComments = data.comments;
  151. } catch (error) {
  152. handleError(error, "Can't get number of comments");
  153. }
  154. }
  155. };
  156. $: {
  157. if (isShared && asset.id) {
  158. getFavorite();
  159. getNumberOfComments();
  160. }
  161. }
  162. const onKeyboardPress = (keyInfo: KeyboardEvent) => handleKeyboardPress(keyInfo);
  163. onMount(async () => {
  164. document.addEventListener('keydown', onKeyboardPress);
  165. slideshowStateUnsubscribe = slideshowState.subscribe((value) => {
  166. if (value === SlideshowState.PlaySlideshow) {
  167. slideshowHistory.reset();
  168. slideshowHistory.queue(asset.id);
  169. handlePlaySlideshow();
  170. } else if (value === SlideshowState.StopSlideshow) {
  171. handleStopSlideshow();
  172. }
  173. });
  174. shuffleSlideshowUnsubscribe = slideshowShuffle.subscribe((value) => {
  175. if (value) {
  176. slideshowHistory.reset();
  177. slideshowHistory.queue(asset.id);
  178. }
  179. });
  180. if (!sharedLink) {
  181. await getAllAlbums();
  182. }
  183. // Import hack :( see https://github.com/vadimkorr/svelte-carousel/issues/27#issuecomment-851022295
  184. // TODO: Move to regular import once the package correctly supports ESM.
  185. const module = await import('copy-image-clipboard');
  186. canCopyImagesToClipboard = module.canCopyImagesToClipboard();
  187. if (asset.stackCount && asset.stack) {
  188. $stackAssetsStore = asset.stack;
  189. $stackAssetsStore = [...$stackAssetsStore, asset].sort(
  190. (a, b) => new Date(a.fileCreatedAt).getTime() - new Date(b.fileCreatedAt).getTime(),
  191. );
  192. } else {
  193. $stackAssetsStore = [];
  194. }
  195. });
  196. onDestroy(() => {
  197. if (browser) {
  198. document.removeEventListener('keydown', onKeyboardPress);
  199. }
  200. if (slideshowStateUnsubscribe) {
  201. slideshowStateUnsubscribe();
  202. }
  203. if (shuffleSlideshowUnsubscribe) {
  204. shuffleSlideshowUnsubscribe();
  205. }
  206. });
  207. $: asset.id && !sharedLink && getAllAlbums(); // Update the album information when the asset ID changes
  208. const getAllAlbums = async () => {
  209. if (api.isSharedLink) {
  210. return;
  211. }
  212. try {
  213. const { data } = await api.albumApi.getAllAlbums({ assetId: asset.id });
  214. appearsInAlbums = data;
  215. } catch (e) {
  216. console.error('Error getting album that asset belong to', e);
  217. }
  218. };
  219. const handleOpenActivity = () => {
  220. if ($isShowDetail) {
  221. $isShowDetail = false;
  222. }
  223. isShowActivity = !isShowActivity;
  224. };
  225. const handleKeyboardPress = (event: KeyboardEvent) => {
  226. if (shouldIgnoreShortcut(event)) {
  227. return;
  228. }
  229. const key = event.key;
  230. const shiftKey = event.shiftKey;
  231. switch (key) {
  232. case 'a':
  233. case 'A':
  234. if (shiftKey) {
  235. toggleArchive();
  236. }
  237. return;
  238. case 'ArrowLeft':
  239. navigateAssetBackward();
  240. return;
  241. case 'ArrowRight':
  242. navigateAssetForward();
  243. return;
  244. case 'd':
  245. case 'D':
  246. if (shiftKey) {
  247. downloadFile(asset);
  248. }
  249. return;
  250. case 'Delete':
  251. trashOrDelete();
  252. return;
  253. case 'Escape':
  254. if (isShowDeleteConfirmation) {
  255. isShowDeleteConfirmation = false;
  256. return;
  257. }
  258. closeViewer();
  259. return;
  260. case 'f':
  261. toggleFavorite();
  262. return;
  263. case 'i':
  264. isShowActivity = false;
  265. $isShowDetail = !$isShowDetail;
  266. return;
  267. }
  268. };
  269. const handleCloseViewer = () => {
  270. $isShowDetail = false;
  271. closeViewer();
  272. };
  273. const closeViewer = () => dispatch('close');
  274. const navigateAssetRandom = async () => {
  275. if (!assetStore) {
  276. return;
  277. }
  278. const asset = await assetStore.getRandomAsset();
  279. if (!asset) {
  280. return;
  281. }
  282. slideshowHistory.queue(asset.id);
  283. setAssetId(asset.id);
  284. $restartSlideshowProgress = true;
  285. };
  286. const navigateAssetForward = async (e?: Event) => {
  287. if ($slideshowState === SlideshowState.PlaySlideshow && $slideshowShuffle) {
  288. return slideshowHistory.next() || navigateAssetRandom();
  289. }
  290. if ($slideshowState === SlideshowState.PlaySlideshow && assetStore) {
  291. const hasNext = await assetStore.getNextAssetId(asset.id);
  292. if (hasNext) {
  293. $restartSlideshowProgress = true;
  294. } else {
  295. await handleStopSlideshow();
  296. }
  297. }
  298. e?.stopPropagation();
  299. dispatch('next');
  300. };
  301. const navigateAssetBackward = (e?: Event) => {
  302. if ($slideshowState === SlideshowState.PlaySlideshow && $slideshowShuffle) {
  303. slideshowHistory.previous();
  304. return;
  305. }
  306. if ($slideshowState === SlideshowState.PlaySlideshow) {
  307. $restartSlideshowProgress = true;
  308. }
  309. e?.stopPropagation();
  310. dispatch('previous');
  311. };
  312. const showDetailInfoHandler = () => {
  313. if (isShowActivity) {
  314. isShowActivity = false;
  315. }
  316. $isShowDetail = !$isShowDetail;
  317. };
  318. $: trashOrDelete = !(force || !isTrashEnabled)
  319. ? trashAsset
  320. : () => {
  321. isShowDeleteConfirmation = true;
  322. };
  323. const trashAsset = async () => {
  324. try {
  325. await api.assetApi.deleteAssets({ assetBulkDeleteDto: { ids: [asset.id] } });
  326. await navigateAssetForward();
  327. assetStore?.removeAsset(asset.id);
  328. notificationController.show({
  329. message: 'Moved to trash',
  330. type: NotificationType.Info,
  331. });
  332. } catch (e) {
  333. handleError(e, 'Unable to trash asset');
  334. }
  335. };
  336. const deleteAsset = async () => {
  337. try {
  338. await api.assetApi.deleteAssets({ assetBulkDeleteDto: { ids: [asset.id], force: true } });
  339. await navigateAssetForward();
  340. assetStore?.removeAsset(asset.id);
  341. notificationController.show({
  342. message: 'Permanently deleted asset',
  343. type: NotificationType.Info,
  344. });
  345. } catch (e) {
  346. handleError(e, 'Unable to delete asset');
  347. } finally {
  348. isShowDeleteConfirmation = false;
  349. }
  350. };
  351. const toggleFavorite = async () => {
  352. try {
  353. const { data } = await api.assetApi.updateAsset({
  354. id: asset.id,
  355. updateAssetDto: {
  356. isFavorite: !asset.isFavorite,
  357. },
  358. });
  359. asset.isFavorite = data.isFavorite;
  360. assetStore?.updateAsset(data);
  361. dispatch(data.isFavorite ? 'favorite' : 'unfavorite', data);
  362. notificationController.show({
  363. type: NotificationType.Info,
  364. message: asset.isFavorite ? `Added to favorites` : `Removed from favorites`,
  365. });
  366. } catch (error) {
  367. await handleError(error, `Unable to ${asset.isFavorite ? `add asset to` : `remove asset from`} favorites`);
  368. }
  369. };
  370. const openAlbumPicker = (shared: boolean) => {
  371. isShowAlbumPicker = true;
  372. addToSharedAlbum = shared;
  373. };
  374. const handleAddToNewAlbum = (event: CustomEvent) => {
  375. isShowAlbumPicker = false;
  376. const { albumName }: { albumName: string } = event.detail;
  377. api.albumApi.createAlbum({ createAlbumDto: { albumName, assetIds: [asset.id] } }).then((response) => {
  378. const album = response.data;
  379. goto('/albums/' + album.id);
  380. });
  381. };
  382. const handleAddToAlbum = async (event: CustomEvent<{ album: AlbumResponseDto }>) => {
  383. isShowAlbumPicker = false;
  384. const album = event.detail.album;
  385. await addAssetsToAlbum(album.id, [asset.id]);
  386. await getAllAlbums();
  387. };
  388. const disableKeyDownEvent = () => {
  389. if (browser) {
  390. document.removeEventListener('keydown', onKeyboardPress);
  391. }
  392. };
  393. const enableKeyDownEvent = () => {
  394. if (browser) {
  395. document.addEventListener('keydown', onKeyboardPress);
  396. }
  397. };
  398. const toggleArchive = async () => {
  399. try {
  400. const { data } = await api.assetApi.updateAsset({
  401. id: asset.id,
  402. updateAssetDto: {
  403. isArchived: !asset.isArchived,
  404. },
  405. });
  406. asset.isArchived = data.isArchived;
  407. assetStore?.updateAsset(data);
  408. dispatch(data.isArchived ? 'archived' : 'unarchived', data);
  409. notificationController.show({
  410. type: NotificationType.Info,
  411. message: asset.isArchived ? `Added to archive` : `Removed from archive`,
  412. });
  413. } catch (error) {
  414. await handleError(error, `Unable to ${asset.isArchived ? `add asset to` : `remove asset from`} archive`);
  415. }
  416. };
  417. const handleRunJob = async (name: AssetJobName) => {
  418. try {
  419. await api.assetApi.runAssetJobs({ assetJobsDto: { assetIds: [asset.id], name } });
  420. notificationController.show({ type: NotificationType.Info, message: api.getAssetJobMessage(name) });
  421. } catch (error) {
  422. await handleError(error, `Unable to submit job`);
  423. }
  424. };
  425. /**
  426. * Slide show mode
  427. */
  428. let assetViewerHtmlElement: HTMLElement;
  429. const slideshowHistory = new SlideshowHistory((assetId: string) => {
  430. setAssetId(assetId);
  431. $restartSlideshowProgress = true;
  432. });
  433. const handleVideoStarted = () => {
  434. if ($slideshowState === SlideshowState.PlaySlideshow) {
  435. $stopSlideshowProgress = true;
  436. }
  437. };
  438. const handleVideoEnded = async () => {
  439. if ($slideshowState === SlideshowState.PlaySlideshow) {
  440. await navigateAssetForward();
  441. }
  442. };
  443. const handlePlaySlideshow = async () => {
  444. try {
  445. await assetViewerHtmlElement.requestFullscreen();
  446. } catch (error) {
  447. console.error('Error entering fullscreen', error);
  448. $slideshowState = SlideshowState.StopSlideshow;
  449. }
  450. };
  451. const handleStopSlideshow = async () => {
  452. try {
  453. if (document.fullscreenElement) {
  454. await document.exitFullscreen();
  455. }
  456. } catch (error) {
  457. console.error('Error exiting fullscreen', error);
  458. } finally {
  459. $stopSlideshowProgress = true;
  460. $slideshowState = SlideshowState.None;
  461. }
  462. };
  463. const handleStackedAssetMouseEvent = (e: CustomEvent<{ isMouseOver: boolean }>, asset: AssetResponseDto) => {
  464. const { isMouseOver } = e.detail;
  465. if (isMouseOver) {
  466. previewStackedAsset = asset;
  467. } else {
  468. previewStackedAsset = undefined;
  469. }
  470. };
  471. const handleUnstack = async () => {
  472. try {
  473. const ids = $stackAssetsStore.map(({ id }) => id);
  474. await api.assetApi.updateAssets({ assetBulkUpdateDto: { ids, removeParent: true } });
  475. for (const child of $stackAssetsStore) {
  476. child.stackParentId = null;
  477. child.stackCount = 0;
  478. child.stack = [];
  479. assetStore?.addAsset(child);
  480. }
  481. dispatch('unstack');
  482. notificationController.show({ type: NotificationType.Info, message: 'Un-stacked', timeout: 1500 });
  483. } catch (error) {
  484. await handleError(error, `Unable to unstack`);
  485. }
  486. };
  487. </script>
  488. <section
  489. id="immich-asset-viewer"
  490. class="fixed left-0 top-0 z-[1001] grid h-screen w-screen grid-cols-4 grid-rows-[64px_1fr] overflow-y-hidden bg-black"
  491. >
  492. <!-- Top navigation bar -->
  493. {#if $slideshowState === SlideshowState.None}
  494. <div class="z-[1002] col-span-4 col-start-1 row-span-1 row-start-1 transition-transform">
  495. <AssetViewerNavBar
  496. {asset}
  497. isMotionPhotoPlaying={shouldPlayMotionPhoto}
  498. showCopyButton={canCopyImagesToClipboard && asset.type === AssetTypeEnum.Image}
  499. showZoomButton={asset.type === AssetTypeEnum.Image}
  500. showMotionPlayButton={!!asset.livePhotoVideoId}
  501. showDownloadButton={shouldShowDownloadButton}
  502. showDetailButton={shouldShowDetailButton}
  503. showSlideshow={!!assetStore}
  504. hasStackChildren={$stackAssetsStore.length > 0}
  505. on:goBack={closeViewer}
  506. on:showDetail={showDetailInfoHandler}
  507. on:download={() => downloadFile(asset)}
  508. on:delete={trashOrDelete}
  509. on:favorite={toggleFavorite}
  510. on:addToAlbum={() => openAlbumPicker(false)}
  511. on:addToSharedAlbum={() => openAlbumPicker(true)}
  512. on:playMotionPhoto={() => (shouldPlayMotionPhoto = true)}
  513. on:stopMotionPhoto={() => (shouldPlayMotionPhoto = false)}
  514. on:toggleArchive={toggleArchive}
  515. on:asProfileImage={() => (isShowProfileImageCrop = true)}
  516. on:runJob={({ detail: job }) => handleRunJob(job)}
  517. on:playSlideShow={() => ($slideshowState = SlideshowState.PlaySlideshow)}
  518. on:unstack={handleUnstack}
  519. />
  520. </div>
  521. {/if}
  522. {#if $slideshowState === SlideshowState.None && showNavigation}
  523. <div class="z-[1001] column-span-1 col-start-1 row-span-1 row-start-2 mb-[60px] justify-self-start">
  524. <NavigationArea on:click={navigateAssetBackward}><Icon path={mdiChevronLeft} size="36" /></NavigationArea>
  525. </div>
  526. {/if}
  527. <!-- Asset Viewer -->
  528. <div class="z-[1000] relative col-start-1 col-span-4 row-start-1 row-span-full" bind:this={assetViewerHtmlElement}>
  529. {#if $slideshowState != SlideshowState.None}
  530. <div class="z-[1000] absolute w-full flex">
  531. <SlideshowBar
  532. on:prev={navigateAssetBackward}
  533. on:next={navigateAssetForward}
  534. on:close={() => ($slideshowState = SlideshowState.StopSlideshow)}
  535. />
  536. </div>
  537. {/if}
  538. {#if previewStackedAsset}
  539. {#key previewStackedAsset.id}
  540. {#if previewStackedAsset.type === AssetTypeEnum.Image}
  541. <PhotoViewer asset={previewStackedAsset} on:close={closeViewer} haveFadeTransition={false} />
  542. {:else}
  543. <VideoViewer
  544. assetId={previewStackedAsset.id}
  545. on:close={closeViewer}
  546. on:onVideoEnded={handleVideoEnded}
  547. on:onVideoStarted={handleVideoStarted}
  548. />
  549. {/if}
  550. {/key}
  551. {:else}
  552. {#key asset.id}
  553. {#if !asset.resized}
  554. <div class="flex h-full w-full justify-center">
  555. <div
  556. class="px-auto flex aspect-square h-full items-center justify-center bg-gray-100 dark:bg-immich-dark-gray"
  557. >
  558. <Icon path={mdiImageBrokenVariant} size="25%" />
  559. </div>
  560. </div>
  561. {:else if asset.type === AssetTypeEnum.Image}
  562. {#if shouldPlayMotionPhoto && asset.livePhotoVideoId}
  563. <VideoViewer
  564. assetId={asset.livePhotoVideoId}
  565. on:close={closeViewer}
  566. on:onVideoEnded={() => (shouldPlayMotionPhoto = false)}
  567. />
  568. {:else if asset.exifInfo?.projectionType === ProjectionType.EQUIRECTANGULAR || (asset.originalPath && asset.originalPath
  569. .toLowerCase()
  570. .endsWith('.insp'))}
  571. <PanoramaViewer {asset} />
  572. {:else}
  573. <PhotoViewer {asset} on:close={closeViewer} />
  574. {/if}
  575. {:else}
  576. <VideoViewer
  577. assetId={asset.id}
  578. on:close={closeViewer}
  579. on:onVideoEnded={handleVideoEnded}
  580. on:onVideoStarted={handleVideoStarted}
  581. />
  582. {/if}
  583. {#if $slideshowState === SlideshowState.None && isShared}
  584. <div class="z-[9999] absolute bottom-0 right-0 mb-6 mr-6 justify-self-end">
  585. <ActivityStatus
  586. {isLiked}
  587. {numberOfComments}
  588. {isShowActivity}
  589. on:favorite={handleFavorite}
  590. on:openActivityTab={handleOpenActivity}
  591. />
  592. </div>
  593. {/if}
  594. {/key}
  595. {/if}
  596. {#if $stackAssetsStore.length > 0 && withStacked}
  597. <div
  598. id="stack-slideshow"
  599. class="z-[1005] flex place-item-center place-content-center absolute bottom-0 w-full col-span-4 col-start-1 mb-1 overflow-x-auto horizontal-scrollbar"
  600. >
  601. <div class="relative whitespace-nowrap transition-all">
  602. {#each $stackAssetsStore as stackedAsset (stackedAsset.id)}
  603. <div
  604. class="{stackedAsset.id == asset.id
  605. ? '-translate-y-[1px]'
  606. : '-translate-y-0'} inline-block px-1 transition-transform"
  607. >
  608. <Thumbnail
  609. class="{stackedAsset.id == asset.id
  610. ? 'bg-transparent border-2 border-white'
  611. : 'bg-gray-700/40'} inline-block hover:bg-transparent"
  612. asset={stackedAsset}
  613. on:click={() => (asset = stackedAsset)}
  614. on:mouse-event={(e) => handleStackedAssetMouseEvent(e, stackedAsset)}
  615. readonly
  616. thumbnailSize={stackedAsset.id == asset.id ? 65 : 60}
  617. showStackedIcon={false}
  618. />
  619. {#if stackedAsset.id == asset.id}
  620. <div class="w-full flex place-items-center place-content-center">
  621. <div class="w-2 h-2 bg-white rounded-full flex mt-[2px]" />
  622. </div>
  623. {/if}
  624. </div>
  625. {/each}
  626. </div>
  627. </div>
  628. {/if}
  629. </div>
  630. {#if $slideshowState === SlideshowState.None && showNavigation}
  631. <div class="z-[1001] col-span-1 col-start-4 row-span-1 row-start-2 mb-[60px] justify-self-end">
  632. <NavigationArea on:click={navigateAssetForward}><Icon path={mdiChevronRight} size="36" /></NavigationArea>
  633. </div>
  634. {/if}
  635. {#if $slideshowState === SlideshowState.None && $isShowDetail}
  636. <div
  637. transition:fly={{ duration: 150 }}
  638. id="detail-panel"
  639. class="z-[1002] row-start-1 row-span-4 w-[360px] overflow-y-auto bg-immich-bg transition-all dark:border-l dark:border-l-immich-dark-gray dark:bg-immich-dark-bg"
  640. translate="yes"
  641. >
  642. <DetailPanel
  643. {asset}
  644. albums={appearsInAlbums}
  645. on:close={() => ($isShowDetail = false)}
  646. on:close-viewer={handleCloseViewer}
  647. on:description-focus-in={disableKeyDownEvent}
  648. on:description-focus-out={enableKeyDownEvent}
  649. />
  650. </div>
  651. {/if}
  652. {#if isShared && album && isShowActivity && user}
  653. <div
  654. transition:fly={{ duration: 150 }}
  655. id="activity-panel"
  656. class="z-[1002] row-start-1 row-span-5 w-[360px] md:w-[460px] overflow-y-auto bg-immich-bg transition-all dark:border-l dark:border-l-immich-dark-gray dark:bg-immich-dark-bg pl-4"
  657. translate="yes"
  658. >
  659. <ActivityViewer
  660. {user}
  661. assetType={asset.type}
  662. albumOwnerId={album.ownerId}
  663. albumId={album.id}
  664. assetId={asset.id}
  665. bind:reactions
  666. on:addComment={handleAddComment}
  667. on:deleteComment={handleRemoveComment}
  668. on:deleteLike={() => (isLiked = null)}
  669. on:close={() => (isShowActivity = false)}
  670. />
  671. </div>
  672. {/if}
  673. {#if isShowAlbumPicker}
  674. <AlbumSelectionModal
  675. shared={addToSharedAlbum}
  676. on:newAlbum={handleAddToNewAlbum}
  677. on:newSharedAlbum={handleAddToNewAlbum}
  678. on:album={handleAddToAlbum}
  679. on:close={() => (isShowAlbumPicker = false)}
  680. />
  681. {/if}
  682. {#if isShowDeleteConfirmation}
  683. <ConfirmDialogue
  684. title="Delete {getAssetType(asset.type)}"
  685. confirmText="Delete"
  686. on:confirm={deleteAsset}
  687. on:cancel={() => (isShowDeleteConfirmation = false)}
  688. >
  689. <svelte:fragment slot="prompt">
  690. <p>
  691. Are you sure you want to delete this {getAssetType(asset.type).toLowerCase()}? This will also remove it from
  692. its album(s).
  693. </p>
  694. <p><b>You cannot undo this action!</b></p>
  695. </svelte:fragment>
  696. </ConfirmDialogue>
  697. {/if}
  698. {#if isShowProfileImageCrop}
  699. <ProfileImageCropper
  700. {asset}
  701. on:close={() => (isShowProfileImageCrop = false)}
  702. on:close-viewer={handleCloseViewer}
  703. />
  704. {/if}
  705. </section>
  706. <style>
  707. #immich-asset-viewer {
  708. contain: layout;
  709. }
  710. .horizontal-scrollbar::-webkit-scrollbar {
  711. width: 8px;
  712. height: 10px;
  713. }
  714. /* Track */
  715. .horizontal-scrollbar::-webkit-scrollbar-track {
  716. background: #000000;
  717. border-radius: 16px;
  718. }
  719. /* Handle */
  720. .horizontal-scrollbar::-webkit-scrollbar-thumb {
  721. background: rgba(159, 159, 159, 0.408);
  722. border-radius: 16px;
  723. }
  724. /* Handle on hover */
  725. .horizontal-scrollbar::-webkit-scrollbar-thumb:hover {
  726. background: #adcbfa;
  727. border-radius: 16px;
  728. }
  729. </style>