detail-panel.svelte 10 KB

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