Skip to content

Commit b69ca1a

Browse files
committed
Create AssetList component which isolates dynamic content
1 parent 7cc2590 commit b69ca1a

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/lib/AssetList.svelte

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script lang="ts">
2+
import { type AssetData } from "$src/types";
3+
import AssetBox from "$src/lib/AssetBox.svelte";
4+
import { loadRHInventoryAssetData } from '$src/lib/rhinventory_api';
5+
6+
let props: { assetTagId: number } = $props();
7+
8+
let assetPage = $state(0);
9+
let assetsPromise: Promise<AssetData[]> = $derived(loadRHInventoryAssetData({tagId: props.assetTagId, page: assetPage}))
10+
</script>
11+
12+
{#await assetsPromise }
13+
<p><em>Načítá se...</em></p>
14+
{:then assets}
15+
{#each assets as asset }
16+
<AssetBox data={asset} />
17+
{/each}
18+
{:catch error}
19+
<p><em>Chyba při načítání předmětů: {error.message}</em></p>
20+
{/await}

src/routes/projects/atari-klub-citov/+page.svelte

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
<script lang="ts">
22
import Meta from "$lib/Meta.svelte";
3-
import type { AssetData, InterviewData } from "$src/types";
3+
import type { InterviewData } from "$src/types";
44
import InterviewBox from "$lib/InterviewBox.svelte";
55
import { data as havelka_data } from '$src/routes/interviews/josef-havelka/interview';
6-
import AssetBox from "$src/lib/AssetBox.svelte";
7-
import { loadRHInventoryAssetData } from '$src/lib/rhinventory_api';
6+
import AssetList from "$src/lib/AssetList.svelte";
87
98
let interviews: InterviewData[] = [havelka_data];
10-
11-
let assetPage = $state(0);
12-
const assetTagId = 16;
13-
let assetsPromise: Promise<AssetData[]> = $derived(loadRHInventoryAssetData({tagId: assetTagId, page: assetPage}))
149
</script>
1510

1611
<Meta title="Atari klub Cítov" />
@@ -45,16 +40,7 @@
4540
{/each}
4641

4742
<h3 id="Predmety">Předměty</h3>
48-
49-
{#await assetsPromise }
50-
<p><em>Načítá se...</em></p>
51-
{:then assets}
52-
{#each assets as asset }
53-
<AssetBox data={asset} />
54-
{/each}
55-
{:catch error}
56-
<p><em>Chyba při načítání předmětů: {error.message}</em></p>
57-
{/await}
43+
<AssetList assetTagId={16} />
5844

5945
<!-- <h3>Články</h3>
6046
<p><em>Sem přijdou případné články.</em> -->

0 commit comments

Comments
 (0)