Skip to content

Commit

Permalink
use svelte5, update to code review
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Drage <[email protected]>
  • Loading branch information
cdrage committed Oct 23, 2024
1 parent ab95e69 commit ec715a7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/frontend/src/Examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ test('Test examples correctly marks examples either Pull image or Build image de

// Wait until example1 says Build image as it updates reactively
// same for example 2 but Pull image
waitFor(() => {
await waitFor(() => {
const buildImage1 = example1.querySelector('[aria-label="Build image"]');
expect(buildImage1).toBeInTheDocument();
});

waitFor(() => {
await waitFor(() => {
const pullImage2 = example2.querySelector('[aria-label="Pull image"]');
expect(pullImage2).toBeInTheDocument();
});
Expand Down
10 changes: 6 additions & 4 deletions packages/frontend/src/lib/Card.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<script lang="ts">
export let title: string | undefined = undefined;
export let description: string | undefined = undefined;
export let href: string | undefined = undefined;
interface Props {
title: string;
description?: string;
href?: string;
}
let { title, description, href }: Props = $props();
</script>

<a class="no-underline" href={href}>
Expand Down
17 changes: 7 additions & 10 deletions packages/frontend/src/lib/ExampleCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import { Button } from '@podman-desktop/ui-svelte';
import { router } from 'tinro';
import DiskImageIcon from './DiskImageIcon.svelte';
export let example: Example;
interface Props {
example: Example;
}
let { example }: Props = $props();
let pullInProgress = false;
let pullInProgress = $state(false);
async function openURL(): Promise<void> {
await bootcClient.openLink(example.repository);
Expand All @@ -35,11 +39,6 @@ function formatStringSize(size: number): string {
}
return `${size} MB`;
}
// Make sure if example.pulled is updated, we force a re-render
$: {
example.state;
}
</script>

<div class="no-underline">
Expand Down Expand Up @@ -99,12 +98,10 @@ $: {
icon={faArrowDown}
aria-label="Pull image"
title="Pull image"
class="w-28"
inProgress={pullInProgress}>Pull image</Button>
{:else}
<!-- Show a spinner / in progress for querying button instead if we are still loading information-->
<Button icon={faArrowDown} aria-label="Querying" title="Querying" class="w-28" inProgress={true}
>Querying</Button>
<Button icon={faArrowDown} aria-label="Querying" title="Querying" inProgress={true}>Querying</Button>
{/if}
</div>
</div>
Expand Down
19 changes: 11 additions & 8 deletions packages/frontend/src/lib/ExamplesCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import { bootcClient, rpcBrowser } from '../api/client';
import type { ImageInfo } from '@podman-desktop/api';
import { Messages } from '/@shared/src/messages/Messages';
export let category: Category;
export let examples: Example[];
let bootcAvailableImages: ImageInfo[] = [];
interface Props {
category: Category;
examples: Example[];
}
let { category, examples = $bindable() }: Props = $props();
let bootcAvailableImages = $state<ImageInfo[]>([]);
onMount(async () => {
bootcAvailableImages = await bootcClient.listBootcImages();
Expand All @@ -32,6 +36,7 @@ onMount(async () => {
// Function to update examples based on available images
function updateExamplesWithPulledImages() {
if (bootcAvailableImages) {
console.log('updateExamplesWithPulledImages');
// Set each state to 'unpulled' by default before updating, as this prevents 'flickering'
// and unsure states when images are being updated
for (const example of examples) {
Expand All @@ -54,16 +59,14 @@ function updateExamplesWithPulledImages() {
}
// Reactive statement to call the function each time bootcAvailableImages updates
$: if (bootcAvailableImages) {
$effect(() => {
updateExamplesWithPulledImages();
}
});
</script>

<Card title={category.name}>
<div slot="content" class="w-full">
{#if examples.length === 0}
<div class="text-gray-400 mt-2">There is no example in this category.</div>
{/if}
<div class="text-gray-400 mt-2">There is no example in this category.</div>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 mt-4">
{#each examples as example}
<ExampleCard example={example} />
Expand Down

0 comments on commit ec715a7

Please sign in to comment.