|
3 | 3 | import Box from "./Box.svelte"; |
4 | 4 | import SvelteMarkdown from '@humanspeak/svelte-markdown' |
5 | 5 | import Capsule from "./Capsule.svelte"; |
| 6 | + import LucideDownload from "@lucide/svelte/icons/download"; |
6 | 7 |
|
7 | 8 | interface Props { |
8 | | - data: AssetData; |
| 9 | + data: AssetData | Promise<AssetData | undefined>; |
9 | 10 | } |
10 | 11 |
|
11 | 12 | let { data }: Props = $props(); |
| 13 | +
|
| 14 | + function formatFileSize(bytes?: number | null): string { |
| 15 | + if (!bytes) return 'unknown size'; |
| 16 | + const units = ['B', 'KiB', 'MiB', 'GiB']; |
| 17 | + let i = 0; |
| 18 | + while (bytes >= 1024 && i < units.length - 1) { |
| 19 | + bytes /= 1024; |
| 20 | + i++; |
| 21 | + } |
| 22 | + return `${bytes.toFixed(1)} ${units[i]}`; |
| 23 | + } |
12 | 24 | </script> |
13 | 25 |
|
14 | 26 | <Box> |
15 | 27 | <div class="asset"> |
16 | | - <div> |
17 | | - <div class="asset-name"> |
18 | | - <a href="{ data.inventory_url }"> |
19 | | - {#if data.id} |
20 | | - <Capsule> |
21 | | - HH{data.id} |
22 | | - </Capsule> |
| 28 | + {#await data} |
| 29 | + <em>Načítám předmět...</em> |
| 30 | + {:then data} |
| 31 | + {#if data} |
| 32 | + <div> |
| 33 | + <div class="asset-name"> |
| 34 | + <a href="{ data.inventory_url }"> |
| 35 | + {#if data.id} |
| 36 | + <Capsule> |
| 37 | + HH{data.id} |
| 38 | + </Capsule> |
| 39 | + {/if} |
| 40 | + </a> |
| 41 | + <a href="{ data.inventory_url }"> |
| 42 | + { data.name } |
| 43 | + </a> |
| 44 | + </div> |
| 45 | + <p> |
| 46 | + <SvelteMarkdown source={data.description} /> |
| 47 | + </p> |
| 48 | + {#if data.primary_dump_path} |
| 49 | + <a href="https://inventory.herniarchiv.cz/files/{data.primary_dump_path}" class="download"> |
| 50 | + <LucideDownload style="vertical-align: top;" /> |
| 51 | + Stáhnout dump |
| 52 | + {#if data.primary_dump_size} |
| 53 | + ({formatFileSize(data.primary_dump_size)}) |
| 54 | + {/if} |
| 55 | + </a> |
23 | 56 | {/if} |
24 | | - </a> |
25 | | - <a href="{ data.inventory_url }"> |
26 | | - { data.name } |
27 | | - </a> |
| 57 | + </div> |
| 58 | + {#if data.picture.url} |
| 59 | + <a href="{ data.inventory_url }" class="asset-photo"> |
| 60 | + <img src="{ data.picture.url }" class="asset-img" alt=""> |
| 61 | + </a> |
| 62 | + {/if} |
| 63 | + {:else} |
| 64 | + <em>Chyba: předmět nebyl dodán.</em> |
| 65 | + {/if} |
| 66 | + {:catch error} |
| 67 | + <div> |
| 68 | + <em>Chyba při načítání předmětu.</em> |
| 69 | + <div style="color: #888;">{error}</div> |
28 | 70 | </div> |
29 | | - <p> |
30 | | - <SvelteMarkdown source={data.description} /> |
31 | | - </p> |
32 | | - </div> |
33 | | - {#if data.picture.url} |
34 | | - <a href="{ data.inventory_url }" class="asset-photo"> |
35 | | - <img src="{ data.picture.url }" class="asset-img" alt=""> |
36 | | - </a> |
37 | | - {/if} |
| 71 | + {/await} |
38 | 72 | </div> |
39 | 73 | </Box> |
40 | 74 |
|
|
65 | 99 | object-fit: cover; |
66 | 100 | } |
67 | 101 |
|
| 102 | + .download { |
| 103 | + text-decoration: none; |
| 104 | + } |
| 105 | +
|
| 106 | + .download:hover { |
| 107 | + text-decoration: underline; |
| 108 | + } |
| 109 | +
|
68 | 110 |
|
69 | 111 | @media only screen and (max-width: 600px) { |
70 | 112 | .asset { |
|
0 commit comments