Skip to content

Commit

Permalink
Fetch Cítov items from rhinventory API
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanqui committed Jan 6, 2025
1 parent 0563bc3 commit d832785
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
8 changes: 5 additions & 3 deletions src/lib/AssetBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
</div>
<p>{@html data.description}</p>
</div>
<div class="asset-photo">
<img src="{ data.picture.url }" class="asset-img" alt="">
</div>
{#if data.picture.url}
<div class="asset-photo">
<img src="{ data.picture.url }" class="asset-img" alt="">
</div>
{/if}
</div>
</Box>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/InterviewBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
interface Props {
data: InterviewData;
compact: boolean;
compact?: boolean;
}
let { data, compact=false }: Props = $props();
Expand Down
32 changes: 32 additions & 0 deletions src/lib/rhinventory_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { AssetData } from "$src/types";

type RHInventoryAPIAsset = {
id: number;
name: string;
note: string;
primary_image_path: string;
primary_document_path: string;
primary_dump_path: string;
}

type RHInventoryAssetsResponse = {
assets: RHInventoryAPIAsset[];
}

export async function loadRHInventoryAssetData(params: {tagId: number, page: number}): Promise<AssetData[]> {
// TODO handle page
const url = `https://api.inventory.herniarchiv.cz/asset/list-by-tag?tag_id=${params.tagId}`;
const response = await fetch(url);
const APIAssets = (await response.json()) as RHInventoryAssetsResponse;

console.log(APIAssets);

return APIAssets.assets.map(APIAsset => {
return {
name: APIAsset.name,
picture: {url: APIAsset.primary_image_path},
description: APIAsset.note,
inventory_url: `https://inventory.herniarchiv.cz/asset/${APIAsset.id}` /* TODO use slug */
}
});
}
2 changes: 0 additions & 2 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script lang="ts">
export const prerender = true;
import { lang } from '../stores.js';
import Meta from '$lib/Meta.svelte';
import Header from '$lib/Header.svelte';
Expand Down
29 changes: 20 additions & 9 deletions src/routes/projects/atari-klub-citov/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<script lang="ts">
import type { PageData } from './$types';
import Meta from "$lib/Meta.svelte";
import type { AssetData, InterviewData } from "$src/types";
import InterviewBox from "$lib/InterviewBox.svelte";
import { data as havelka_data } from '$src/routes/interviews/josef-havelka/interview';
import { data as asset07859_data } from '$src/routes/assets/asset_07859';
import { data as asset07860_data } from '$src/routes/assets/asset_07860';
import { data as asset08107_data } from '$src/routes/assets/asset_08107';
import { data as asset08077_data } from '$src/routes/assets/asset_08077';
import AssetBox from "$src/lib/AssetBox.svelte";
import { loadRHInventoryAssetData } from '$src/lib/rhinventory_api';
let { pageData }: { pageData: PageData } = $props();
let interviews: InterviewData[] = [havelka_data];
let assets: AssetData[] = [asset07859_data, asset07860_data, asset08077_data, asset08107_data];
let assetPage = $state(0);
const assetTagId = 16;
let assetsPromise: Promise<AssetData[]> = $derived(loadRHInventoryAssetData({tagId: assetTagId, page: assetPage}))
</script>

<Meta title="Atari klub Cítov" />
Expand Down Expand Up @@ -41,13 +45,20 @@

<h3>Rozhovory</h3>
{#each interviews as data}
<InterviewBox {data} />
<InterviewBox {data}/>
{/each}

<h3 id="Predmety">Předměty</h3>
<!-- {#each assets as data}
<AssetBox {data} />
{/each} -->

{#await assetsPromise }
<p><em>Načítá se...</em></p>
{:then assets}
{#each assets as asset }
<AssetBox data={asset} />
{/each}
{:catch error}
<p><em>Chyba při načítání předmětů: {error.message}</em></p>
{/await}

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

0 comments on commit d832785

Please sign in to comment.