detail-panel.svelte 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <script lang="ts">
  2. import { page } from '$app/stores';
  3. import { locale } from '$lib/stores/preferences.store';
  4. import type { LatLngTuple } from 'leaflet';
  5. import { DateTime } from 'luxon';
  6. import Calendar from 'svelte-material-icons/Calendar.svelte';
  7. import CameraIris from 'svelte-material-icons/CameraIris.svelte';
  8. import Close from 'svelte-material-icons/Close.svelte';
  9. import ImageOutline from 'svelte-material-icons/ImageOutline.svelte';
  10. import MapMarkerOutline from 'svelte-material-icons/MapMarkerOutline.svelte';
  11. import { createEventDispatcher } from 'svelte';
  12. import { AssetResponseDto, AlbumResponseDto, api, ThumbnailFormat } from '@api';
  13. import { asByteUnitString } from '../../utils/byte-units';
  14. import ImageThumbnail from '../assets/thumbnail/image-thumbnail.svelte';
  15. import { getAssetFilename } from '$lib/utils/asset-utils';
  16. export let asset: AssetResponseDto;
  17. export let albums: AlbumResponseDto[] = [];
  18. let textarea: HTMLTextAreaElement;
  19. let description: string;
  20. $: {
  21. // Get latest description from server
  22. if (asset.id && !api.isSharedLink) {
  23. api.assetApi.getAssetById({ id: asset.id }).then((res) => {
  24. people = res.data?.people || [];
  25. textarea.value = res.data?.exifInfo?.description || '';
  26. });
  27. }
  28. }
  29. $: latlng = (() => {
  30. const lat = asset.exifInfo?.latitude;
  31. const lng = asset.exifInfo?.longitude;
  32. if (lat && lng) {
  33. return [lat, lng] as LatLngTuple;
  34. }
  35. })();
  36. $: people = asset.people || [];
  37. const dispatch = createEventDispatcher();
  38. const getMegapixel = (width: number, height: number): number | undefined => {
  39. const megapixel = Math.round((height * width) / 1_000_000);
  40. if (megapixel) {
  41. return megapixel;
  42. }
  43. return undefined;
  44. };
  45. const autoGrowHeight = (e: Event) => {
  46. const target = e.target as HTMLTextAreaElement;
  47. target.style.height = 'auto';
  48. target.style.height = `${target.scrollHeight}px`;
  49. };
  50. const handleFocusIn = () => {
  51. dispatch('description-focus-in');
  52. };
  53. const handleFocusOut = async () => {
  54. dispatch('description-focus-out');
  55. try {
  56. await api.assetApi.updateAsset({
  57. id: asset.id,
  58. updateAssetDto: {
  59. description: description,
  60. },
  61. });
  62. } catch (error) {
  63. console.error(error);
  64. }
  65. };
  66. </script>
  67. <section class="p-2 dark:bg-immich-dark-bg dark:text-immich-dark-fg">
  68. <div class="flex place-items-center gap-2">
  69. <button
  70. class="flex place-content-center place-items-center rounded-full p-3 transition-colors hover:bg-gray-200 dark:text-immich-dark-fg dark:hover:bg-gray-900"
  71. on:click={() => dispatch('close')}
  72. >
  73. <Close size="24" />
  74. </button>
  75. <p class="text-lg text-immich-fg dark:text-immich-dark-fg">Info</p>
  76. </div>
  77. <section
  78. class="mx-4 mt-10"
  79. style:display={$page?.data?.user?.id !== asset.ownerId && textarea?.value == '' ? 'none' : 'block'}
  80. >
  81. <textarea
  82. bind:this={textarea}
  83. class="max-h-[500px]
  84. w-full resize-none overflow-hidden border-b border-gray-500 bg-transparent text-base text-black outline-none transition-all focus:border-b-2 focus:border-immich-primary disabled:border-none dark:text-white dark:focus:border-immich-dark-primary"
  85. placeholder={$page?.data?.user?.id !== asset.ownerId ? '' : 'Add a description'}
  86. on:focusin={handleFocusIn}
  87. on:focusout={handleFocusOut}
  88. on:input={autoGrowHeight}
  89. bind:value={description}
  90. disabled={$page?.data?.user?.id !== asset.ownerId}
  91. />
  92. </section>
  93. {#if !api.isSharedLink && people.length > 0}
  94. <section class="px-4 py-4 text-sm">
  95. <h2>PEOPLE</h2>
  96. <div class="mt-4 flex flex-wrap gap-2">
  97. {#each people as person (person.id)}
  98. <a href="/people/{person.id}" class="w-[90px]" on:click={() => dispatch('close-viewer')}>
  99. <ImageThumbnail
  100. curve
  101. shadow
  102. url={api.getPeopleThumbnailUrl(person.id)}
  103. altText={person.name}
  104. widthStyle="90px"
  105. heightStyle="90px"
  106. thumbhash={null}
  107. />
  108. <p class="mt-1 truncate font-medium">{person.name}</p>
  109. <p class="font-light">
  110. {#if person.birthDate}
  111. Age {Math.floor(
  112. DateTime.fromISO(asset.fileCreatedAt).diff(DateTime.fromISO(person.birthDate), 'years').years,
  113. )}
  114. {/if}
  115. </p>
  116. </a>
  117. {/each}
  118. </div>
  119. </section>
  120. {/if}
  121. <div class="px-4 py-4">
  122. {#if !asset.exifInfo}
  123. <p class="text-sm">NO EXIF INFO AVAILABLE</p>
  124. {:else}
  125. <p class="text-sm">DETAILS</p>
  126. {/if}
  127. {#if asset.exifInfo?.dateTimeOriginal}
  128. {@const assetDateTimeOriginal = DateTime.fromISO(asset.exifInfo.dateTimeOriginal, {
  129. zone: asset.exifInfo.timeZone ?? undefined,
  130. })}
  131. <div class="flex gap-4 py-4">
  132. <div>
  133. <Calendar size="24" />
  134. </div>
  135. <div>
  136. <p>
  137. {assetDateTimeOriginal.toLocaleString(
  138. {
  139. month: 'short',
  140. day: 'numeric',
  141. year: 'numeric',
  142. },
  143. { locale: $locale },
  144. )}
  145. </p>
  146. <div class="flex gap-2 text-sm">
  147. <p>
  148. {assetDateTimeOriginal.toLocaleString(
  149. {
  150. weekday: 'short',
  151. hour: 'numeric',
  152. minute: '2-digit',
  153. timeZoneName: 'longOffset',
  154. },
  155. { locale: $locale },
  156. )}
  157. </p>
  158. </div>
  159. </div>
  160. </div>{/if}
  161. {#if asset.exifInfo?.fileSizeInByte}
  162. <div class="flex gap-4 py-4">
  163. <div><ImageOutline size="24" /></div>
  164. <div>
  165. <p class="break-all">
  166. {getAssetFilename(asset)}
  167. </p>
  168. <div class="flex gap-2 text-sm">
  169. {#if asset.exifInfo.exifImageHeight && asset.exifInfo.exifImageWidth}
  170. {#if getMegapixel(asset.exifInfo.exifImageHeight, asset.exifInfo.exifImageWidth)}
  171. <p>
  172. {getMegapixel(asset.exifInfo.exifImageHeight, asset.exifInfo.exifImageWidth)} MP
  173. </p>
  174. {/if}
  175. <p>{asset.exifInfo.exifImageHeight} x {asset.exifInfo.exifImageWidth}</p>
  176. {/if}
  177. <p>{asByteUnitString(asset.exifInfo.fileSizeInByte, $locale)}</p>
  178. </div>
  179. </div>
  180. </div>
  181. {/if}
  182. {#if asset.exifInfo?.fNumber}
  183. <div class="flex gap-4 py-4">
  184. <div><CameraIris size="24" /></div>
  185. <div>
  186. <p>{asset.exifInfo.make || ''} {asset.exifInfo.model || ''}</p>
  187. <div class="flex gap-2 text-sm">
  188. <p>{`ƒ/${asset.exifInfo.fNumber.toLocaleString($locale)}` || ''}</p>
  189. {#if asset.exifInfo.exposureTime}
  190. <p>{`${asset.exifInfo.exposureTime}`}</p>
  191. {/if}
  192. {#if asset.exifInfo.focalLength}
  193. <p>{`${asset.exifInfo.focalLength.toLocaleString($locale)} mm`}</p>
  194. {/if}
  195. {#if asset.exifInfo.iso}
  196. <p>
  197. {`ISO${asset.exifInfo.iso}`}
  198. </p>
  199. {/if}
  200. </div>
  201. </div>
  202. </div>
  203. {/if}
  204. {#if asset.exifInfo?.city}
  205. <div class="flex gap-4 py-4">
  206. <div><MapMarkerOutline size="24" /></div>
  207. <div>
  208. <p>{asset.exifInfo.city}</p>
  209. <div class="flex gap-2 text-sm">
  210. <p>{asset.exifInfo.state}</p>
  211. </div>
  212. <div class="flex gap-2 text-sm">
  213. <p>{asset.exifInfo.country}</p>
  214. </div>
  215. </div>
  216. </div>
  217. {/if}
  218. </div>
  219. </section>
  220. {#if latlng}
  221. <div class="h-[360px]">
  222. {#await import('../shared-components/leaflet') then { Map, TileLayer, Marker }}
  223. <Map center={latlng} zoom={14}>
  224. <TileLayer
  225. urlTemplate={'https://tile.openstreetmap.org/{z}/{x}/{y}.png'}
  226. options={{
  227. attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
  228. }}
  229. />
  230. <Marker {latlng} popupContent="{latlng[0].toFixed(7)},{latlng[1].toFixed(7)}" />
  231. </Map>
  232. {/await}
  233. </div>
  234. {/if}
  235. <section class="p-2 dark:text-immich-dark-fg">
  236. <div class="px-4 py-4">
  237. {#if albums.length > 0}
  238. <p class="pb-4 text-sm">APPEARS IN</p>
  239. {/if}
  240. {#each albums as album}
  241. <a data-sveltekit-preload-data="hover" href={`/albums/${album.id}`}>
  242. <!-- svelte-ignore a11y-no-static-element-interactions -->
  243. <div
  244. class="flex gap-4 py-2 hover:cursor-pointer"
  245. on:click={() => dispatch('click', album)}
  246. on:keydown={() => dispatch('click', album)}
  247. >
  248. <div>
  249. <img
  250. alt={album.albumName}
  251. class="h-[50px] w-[50px] rounded object-cover"
  252. src={album.albumThumbnailAssetId &&
  253. api.getAssetThumbnailUrl(album.albumThumbnailAssetId, ThumbnailFormat.Jpeg)}
  254. draggable="false"
  255. />
  256. </div>
  257. <div class="mb-auto mt-auto">
  258. <p class="dark:text-immich-dark-primary">{album.albumName}</p>
  259. <div class="flex gap-2 text-sm">
  260. <p>{album.assetCount} items</p>
  261. {#if album.shared}
  262. <p>· Shared</p>
  263. {/if}
  264. </div>
  265. </div>
  266. </div>
  267. </a>
  268. {/each}
  269. </div>
  270. </section>